Stuck building a Python extension

Dave Brueck dave at pythonapocrypha.com
Wed Sep 24 09:21:44 EDT 2003


On Thursday 25 September 2003 07:07 am, David Hughes wrote:
> I'm nearly there building a Python extension module to access a set of
> functions in a .dll, but I'm getting an unresolved external error for one
> of the function calls (using MS Visual C++ V6).
[snip]

Hi David,

I apologize that this isn't a direct answer to your question, but have you 
tried using ctypes? If you're accessing functions in a Windows DLL then with 
ctypes you can often avoid writing a Python extension altogether. 

For example, if your DLL was named foo.dll and it had an exported C function

int MyFunc(int a, char *b) 

then calling it could be as simple as:

from ctypes import *
val = windll.foo.MyFunc(5, 'hello')

Much more convenient than writing an extension! :)

http://starship.python.net/crew/theller/ctypes/

-Dave





More information about the Python-list mailing list