help with debugging a ctypes problem

gap pajerpunctuationinamedotcom
Sat Sep 23 10:41:10 EDT 2006


I'm no c programmer, and I'm a ctypes newbie.  I'll frame my problem as 
simply as I can.  Sorry if it's too much or not enough info.  I don't 
expect an explicit answer (but maybe), just help figuring out how to debug.

WinXP, python 2.4.2

I'm using ctypes to access functions in a commercial dll.  A certain 
function takes five arguments, foo(a, b, c, d, e).  The last argument, 
e, is an integer that serves as a bit coded options flag.  Zero means no 
option, 1+2+4 means the first three options combined, etc.

I can call foo() successfully if e=c_int(0).  However, if e=3, the 
function does not work.  Execution of the python program continues after 
the call, no errors are raised, but foo() has not done its thing.

If I now call bar(x, y, z) after foo(),  two things happen.
1.  The dll raises an error reporting that argument x is invalid
2.  Python reports that too many bytes (4) have been passed to bar()

I've checked the types of all the variables a million times, and they 
are correct according to the docs.  The vendor sent me a c program that 
they claim works.  It looks like a translation of mine.  I can't run 
theirs, because I can't figure out how to compile it (I'm don't do c; I 
do have MinGW; the code was designed for MSVC; I'm lost).

I'm suspecting that foo() screws up a stack somewhere.  That might 
explain why bar() chokes on the *first* parameter, while it thinks that 
the number of arguments is wrong when it gets to the *last*.

How can I debug this?  Can I view the appropriate stack?  What/where 
would I find it?  Any other ideas or advice?  etc?

thanks,
-gary



More information about the Python-list mailing list