Using CTypes Module

Brandon Philips brandon at sporknet.cjb.net
Mon Feb 3 02:46:47 CET 2003


Hello All,

Really simple question (I think).
I have compiled some code in C++ as a dll.  I tested it with a simple test
program and it does what it is supposed to.  I have played with the Ctypes
module and I can call kernel32 functions and etc like are in the examples
but I cannot call my dll functions... how do I go about doing that? (I am
not a python developer, I am doing this because my group wants my software
to be scriptable.)

I am using ActivePython 2.2, and have gone to the path that contains my dll
and typed python at the command prompt.  I then do the following:


C:\Documents and Settings\brandon\My Documents\My Bob
Documents\CVSROOT\ninebutt
on\Debug>python
ActivePython 2.2.2 Build 224 (ActiveState Corp.) based on
Python 2.2.2 (#37, Nov 26 2002, 10:24:37) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import windll, cdll
>>> cdll.ninebutton.writePacket(1,3)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "C:\Python22\Lib\site-packages\ctypes.py", line 126, in __getattr__
    func = _DynFunction(name, self, FUNCFLAG_CDECL)
ValueError: function 'writePacket' not found
>>>

ninebutton.dll is my dll and writePacket(int, int) is my function.  What did
I do wrong?

Brandon Philips






More information about the Python-list mailing list