Call a function in DLL with string arguments? 
Author Message
 Call a function in DLL with string arguments?

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?

Thanks for your reading.

Juping



Sun, 28 Apr 2002 03:00:00 GMT  
 Call a function in DLL with string arguments?

Quote:
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



Sun, 28 Apr 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Calling dll functions which need pointers to be passed as an argument

2. Help - String Argument w/DLL (example)

3. lvdaq.dll argument question for function DIO_Port_WriteInterface().

4. VC++ calling fortran function and fortran function calling a c++ function

5. String-Variable as Function-Argument doesn't work

6. Rest of arguments in a function call

7. calling function as argument

8. function has been called with too many arguments

9. Calling a python function with a list as the input argument from C

10. problem calling functions with default arguments

11. Calling function with arguments

12. Calling a function, arguments in a dict ??

 

 
Powered by phpBB® Forum Software