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 2 2683
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? 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 functions exposed from dlls/shared libraries
and has extensive facilities to create, access and manipulate
|
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 Simple MAPI module was Ian's completed version of an example
I had posted in an earlier message. In it I had to set some pointer
fields in a C structure to NULL. I was not happy with the solution I
used so I made an inquiry on the ctypes-users...
|
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 the file arapi51.dll to the system32 directory. However
when I tried to access it I see this:
Traceback (most recent call last):
|
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 case
basis"?
\\\
For example, suppose sometimes I receive the value '\x03hi' + \x04bye'
for the struct:
|
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 script below), you're passed in a
pam_response**
pointer. You're supposed to allocate an array of pam_response's and
set
| |
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 have created a debug build of
python but I also use pyodbc
and dateutil libraries in my program and I don't know how to make them
visible to python_d.exe
Am I using the right approach?
thanks in advance for hints,
|
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 all OK but
python don't see the dll function. with dir(myDLL) I've only this:
Could anybody help me
Thanks
|
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
|
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 when I try to print
one of the args I did a pass byref on, no error out, nothing. admittedly I'm a newbie to ctypes and not much of a c programmer
but I could sure use some help. my ctypes test code follows...
from ctypes import *
'''...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |