Call a function in DLL with string arguments?

Gordon McMillan gmcm at hypernet.com
Wed Nov 10 17:12:15 CET 1999


Juping  Jin writes:

> I wrote a DLL and want its functions being available from python.
> Its function accept string arguments. From python, I use windll
> to load the module like:
> 
>  handle = windll.module("dllname")
>  handle.fcnname(arguments)
> 
> Python gives following msg:
> 
> TypeError: illegal argument type for built-in operation
> 
> So I did some tests, wrote a small dll and found out that if the
> function accept only numerical values (actually, only integer
> value produces expected results), then python won't give above
> errors. For char or char * argument, it always gave above msg.
> Did I do something wrong?

Well, if you're serious about exposing it to Python, you should 
probably rewrite it, or wrap it, or SWIG it and make a proper 
extension module. If you want to poke at it with windll, then 
you need to realize that Python objects, even if they have a 
natural translation to a C representation, are completely 
incomprehensible to non-Python aware C. As I recall, there's a 
cstring object in the same download as windll which gives you 
a buffer you can use to communicate with a function in the dll. 
In particular, you initialize the cstring with your Python string, 
and it takes care of getting the function a real char *.

Sorry to be vague, but I no longer have windll etc. installed on 
my system.

- Gordon




More information about the Python-list mailing list