473,320 Members | 1,948 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

help with debugging a ctypes problem

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
Sep 23 '06 #1
2 2640
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?

Sep 23 '06 #2
gap
p.*******@ieee.org wrote:
>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?
Uh... windll, I think. I'm really green here.

But there is news: 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
Sep 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Thomas Heller | last post by:
ctypes 0.9.2 released - Oct 28, 2004 ==================================== Overview ctypes is a ffi (Foreign Function Interface) package for Python 2.3 and higher. ctypes allows to call...
3
by: Lenard Lindstrom | last post by:
Posted in a previous thread was some Python code for accessing Window's Simple MAPI api using the ctypes module. http://groups-beta.google.com/group/comp.lang.python/msg/56fa74cdba9b7be9 This...
6
by: Mudcat | last post by:
Hi, I can't figure out why ctypes won't load the DLL I need to use. I've tried everything I can find (and the ctypes website is down at the moment). Here's what I've seen so far. I've added...
7
by: p.lavarre | last post by:
How do I vary the byte offset of a field of a ctypes.Structure? How do I "use the dynamic nature of Python, and (re-)define the data type after the required size is already known, on a case by...
3
by: Chris AtLee | last post by:
Sorry for the repeat post...I'm not sure if my first post (on May 30th) went through or not. I've been trying to write a PAM module using ctypes. In the conversation function (my_conv in the...
2
by: marco_347 | last post by:
hi all, I have a python program that calls a dll through ctypes (py2.5). In some (reproducible) conditions the program crashes with an error in ctypes module. How can I trace down the problem? I...
8
by: gianluca | last post by:
Hy, I need help about use dll with ctypes. I've compiled my dll C library and I copied it in c:\windows\system32. When I load it with "myDLL=cdll.LoadLibrary(find_library("myDLL.dll"))" It seem...
0
by: Egor Zindy | last post by:
Egor Zindy wrote: #!/usr/bin/env python """ A generic chipid library based on ctypes This module handles most of the functions in FTChipID.dll
2
by: Sells, Fred | last post by:
Diez wrote... You're right the ctypes does seem more pythonesque; however I'm still stuck trying return all these parameters that the c api uses. my ctypes code is below. It just quits running...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.