help with debugging a ctypes problem

G

gap

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
 
P

p.lavarre

help figuring out how to debug ... ctypes ...
a commercial dll. A certain function takes five arguments, foo(a, b, c, d, e).
Can I view the appropriate stack? ... Any other ideas or advice? etc?

Did you call the foo of _cdecl ctypes.cdll or the foo of _stdcall =
ctypes.windll?

What is the sizeof each argument type? Preferably fetched by compiling
some C to printf them?

Would it help to call C in another Dll to return the stack pointer, so
Python could print the stack?
 
G

gap

Did you call the foo of _cdecl ctypes.cdll or the foo of _stdcall =
ctypes.windll?

What is the sizeof each argument type? Preferably fetched by compiling
some C to printf them?

Would it help to call C in another Dll to return the stack pointer, so
Python could print the stack?

Uh... windll, I think. I'm really green here.

But there is If simply leave off the last argument of foo() and
bar(), each works as expected. That is, I call foo() with four instead
of the five that the docs and the c example call for, and I call bar()
with one argument instead of the two that are called for. Everything
works, but you gotta wonder.

Meanwhile, I upgraded from ctypes 0.9.6 to 1.0.0, but I don't think
that that changed anything.

I'll see if I can implement your suggestions, and if I manage it, I'll
report back.

thanks,
-g
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top