1

I am currently planning to access my MFC Dialog based application's .dll file using Python. I am new to Python and have the latest version of Python installed i.e. 3.2. I have installed PythonWin as well, but not really sure if it would be useful or not. I have understood like the basics of using python with the help of ctypes. In my dll file, I have two functions:

double BoxArea(double L, double H, double W);

double BoxVolume(double L, double H, double W);

and I have used the extern dllimport command to access these in my mfc dialog application.

extern "C" __declspec(dllexport)void BoxProperties(double Length, double Height,
                                    double Width, double& Area, double& Volume);

All that works fine when trying to access with another mfc program. Now, I am trying to access those two functions using Python. Could anyone suggest me how should I go about and what commands would directly let me access it?

Many thanks in advance.

Emulator
  • 186
  • 4
  • 20
  • Ummm use PyQt? MFC is pretty much obsolete. What you are trying to do is extremely exotic and might not work or take a very long time to implement (since you don't have proper bindings). – the_drow Sep 08 '11 at 09:58
  • 1
    I was checking online and people were suggesting to use PythonWin. I wonder if that'd be any good. In your opinion, how exactly should I frame my MFC functions if I need to use it along with Python because in the end I need to be able to use this scripting language to talk with my .dll and keep changing only the .dll instead of the whole application. – Emulator Sep 08 '11 at 10:09
  • 1
    I did try http://stackoverflow.com/questions/252417/how-can-i-use-a-dll-from-python, but no luck as such. – Emulator Sep 08 '11 at 10:10
  • Are you able to move to a better GUI toolkit? – the_drow Sep 08 '11 at 10:28
  • Don't you just need to initialise MFC in your DLL start-up? It's probably just assuming it's being loaded into an MFC environment. – Rup Sep 08 '11 at 10:41
  • I don't think so unfortunately. I have been told to programme using MFC and I personally have no experience in working with any other GUI other than Visual C++ MFC at the moment. – Emulator Sep 08 '11 at 10:41
  • @Rup: I have made my application work in this way: http://www.functionx.com/visualc/libraries/staticdll.htm This is just an example and I wanted to know the basics on accessing the .dll functions. I will be using this concept in some other programs to get a detailed idea of working with Python. – Emulator Sep 08 '11 at 10:45

2 Answers2

2

I think this should give you some idea on what you are trying to do. Hope this helps.

Neophile
  • 5,660
  • 14
  • 61
  • 107
1

MFC isn't just a library, it's a platform. It's going to depend on certain assumptions, such as proper initialization being done at program startup and that an MFC message pump will be called periodically among others. Those assumptions will not be met by Python and it will be impractical to make it work properly.

It is possible to program a DLL so that it uses MFC internally but is completely self-contained, but I'm guessing yours is not. See http://msdn.microsoft.com/en-us/library/30c674tx(v=vs.90).aspx

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
  • Could you please suggest me a code for making the above program work? I am trying but it's still not giving any proper result:( – Emulator Sep 09 '11 at 10:28
  • @Emulator, make sure your DLL is following the guidelines I gave in the link. If it doesn't then what you are trying to do will be impossible. – Mark Ransom Sep 09 '11 at 13:34