VC++ extension

Courageous jkraska1 at san.rr.com
Tue Aug 8 22:37:31 EDT 2000


Stuart Dallas wrote:
> 
> I am developing an extension for Python in Visual C++ 6. I have created
> a Win32 DLL project and exported the initx function. When I try to
> import the extension into Python it responds with the following message:
> 
> ImportError: dynamic module does not define init function
> 
> I have checked the DLL with QuickView and the init function is being
> exported.
> 
> Help!

One: if you are not actually using classes or other C++ features,
rename your file from .cpp to .c. The designers of Visual C++,
in Their Infinite Wisdom (tm), decided that this would be the
way you'd tell their compiler you want ANSI-C compatability.

Two: If you persist in using C++, a module called "mymodule"
must be defined in a library called "mymodule.dll" and have
its init function named "initmymodule". As far as I know,
there are no ready exceptions to this strict methodology. I
could explain why your init() method must be named like that,
but just trust me. :)

Three: As one other poster indicated, your init method must
be declared 'extern "C" { ... }'. This is because the designers
of C++, in Their Equally Infinite Wisdom (R), ah, well....
nevermind. Trust me, they biffed it. 

All and all, it's really easier to simply do python extensions
in pure ANSI-C unless you have some very specific reason to
use C++.

Good luck.



C//



More information about the Python-list mailing list