473,721 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ctypes help

Hy,
I need help about use dll with ctypes. I've compiled my dll C library
and I copied it in c:\windows\syst em32. When I load it with
"myDLL=cdll.Loa dLibrary(find_l ibrary("myDLL.d ll"))" It seem all OK but
python don't see the dll function. with dir(myDLL) I've only this:
['_FuncPtr', '__class__', '__delattr__', '__dict__', '__doc__',
'__getattr__', '__getattribute __', '__getitem__', '__hash__',
'__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__' ,
'__repr__', '__setattr__', '__str__', '__weakref__', '_handle',
'_name']

Could anybody help me

Thanks

Gianluca
Jun 27 '08 #1
8 4806
On May 23, 12:33 am, gianluca <geonom...@gmai l.comwrote:
Hy,
I need help about use dll with ctypes. I've compiled my dll C library
and I copied it in c:\windows\syst em32. When I load it with
"myDLL=cdll.Loa dLibrary(find_l ibrary("myDLL.d ll"))" It seem all OK but
python don't see the dll function. with dir(myDLL) I've only this:
['_FuncPtr', '__class__', '__delattr__', '__dict__', '__doc__',
'__getattr__', '__getattribute __', '__getitem__', '__hash__',
'__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__' ,
'__repr__', '__setattr__', '__str__', '__weakref__', '_handle',
'_name']
I see nothing wrong here.


Jun 27 '08 #2
gianluca wrote:
Hy,
I need help about use dll with ctypes. I've compiled my dll C library
and I copied it in c:\windows\syst em32. When I load it with
"myDLL=cdll.Loa dLibrary(find_l ibrary("myDLL.d ll"))" It seem all OK but
python don't see the dll function. with dir(myDLL) I've only this:
['_FuncPtr', '__class__', '__delattr__', '__dict__', '__doc__',
'__getattr__', '__getattribute __', '__getitem__', '__hash__',
'__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__' ,
'__repr__', '__setattr__', '__str__', '__weakref__', '_handle',
'_name']

Could anybody help me

Thanks

Gianluca
Since it isn't python, dir can'd do much introspection on the object to produce
the type of output you desire. You have to know the functions (methods) that
you want to call in your dll and call them.

-Larry Bates
Jun 27 '08 #3
On 23 Mag, 01:14, Larry Bates <larry.ba...@we bsafe.com`wrote :
gianluca wrote:
Hy,
I need help about use dll with ctypes. I've compiled my dll C library
and I copied it in c:\windows\syst em32. When I load it with
"myDLL=cdll.Loa dLibrary(find_l ibrary("myDLL.d ll"))" It seem all OK but
python don't see the dll function. with dir(myDLL) I've only this:
['_FuncPtr', '__class__', '__delattr__', '__dict__', '__doc__',
'__getattr__', '__getattribute __', '__getitem__', '__hash__',
'__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__' ,
'__repr__', '__setattr__', '__str__', '__weakref__', '_handle',
'_name']
Could anybody help me
Thanks
Gianluca

Since it isn't python, dir can'd do much introspection on the object to produce
the type of output you desire. You have to know the functions (methods) that
you want to call in your dll and call them.

-Larry Bates

Yes, I know it but when I load a function (a=myDLL.myFUNC T()) I've an
exception like this:

Traceback (most recent call last):
File "<pyshell#1 8>", line 1, in <module>
myDLL.myFUNCT()
File "C:\Python25\li b\ctypes\__init __.py", line 353, in __getattr__
func = self.__getitem_ _(name)
File "C:\Python25\li b\ctypes\__init __.py", line 358, in __getitem__
func = self._FuncPtr(( name_or_ordinal , self))
AttributeError: function 'myFUNCT' not found

Thanks for help
Jun 27 '08 #4
On Thu, 22 May 2008 21:55:41 -0700, gianluca wrote:
Yes, I know it but when I load a function (a=myDLL.myFUNC T()) I've an
exception like this:

Traceback (most recent call last):
File "<pyshell#1 8>", line 1, in <module>
myDLL.myFUNCT()
File "C:\Python25\li b\ctypes\__init __.py", line 353, in __getattr__
func = self.__getitem_ _(name)
File "C:\Python25\li b\ctypes\__init __.py", line 358, in __getitem__
func = self._FuncPtr(( name_or_ordinal , self))
AttributeError: function 'myFUNCT' not found
Then maybe the DLL doesn't contain a function called `myFUNCT`. Any
chance you compiled your C as C++ and name mangling kicked in?

Can you show a minimal C source for a DLL, how you compiled it, what you
did on the Python side to call it, and how it fails?

Ciao,
Marc 'BlackJack' Rintsch
Jun 27 '08 #5
On 23 Mag, 07:48, Marc 'BlackJack' Rintsch <bj_...@gmx.net wrote:
On Thu, 22 May 2008 21:55:41 -0700, gianluca wrote:
Yes, I know it but when I load a function (a=myDLL.myFUNC T()) I've an
exception like this:
Traceback (most recent call last):
File "<pyshell#1 8>", line 1, in <module>
myDLL.myFUNCT()
File "C:\Python25\li b\ctypes\__init __.py", line 353, in __getattr__
func = self.__getitem_ _(name)
File "C:\Python25\li b\ctypes\__init __.py", line 358, in __getitem__
func = self._FuncPtr(( name_or_ordinal , self))
AttributeError: function 'myFUNCT' not found

Then maybe the DLL doesn't contain a function called `myFUNCT`. Any
chance you compiled your C as C++ and name mangling kicked in?

Can you show a minimal C source for a DLL, how you compiled it, what you
did on the Python side to call it, and how it fails?

Ciao,
Marc 'BlackJack' Rintsch
I've located my dll in c:\windows\syst em32 (in linux I aven't any
problem) and I compiled it with dev-c++. The source code is C standard
ANSII and is quite havy. If you like I can send it via mail (you can
realy at ge*******@gmail .com) . I've tryed to build a wrape with swig
olso with same code and I can access at all the function.
thanks
Gianluca
Jun 27 '08 #6
gianluca <ge*******@gmai l.comwrote:
On 23 Mag, 07:48, Marc 'BlackJack' Rintsch <bj_...@gmx.net wrote:
On Thu, 22 May 2008 21:55:41 -0700, gianluca wrote:
Yes, I know it but when I load a function (a=myDLL.myFUNC T()) I've an
exception like this:
Traceback (most recent call last):
File "<pyshell#1 8>", line 1, in <module>
myDLL.myFUNCT()
File "C:\Python25\li b\ctypes\__init __.py", line 353, in __getattr__
func = self.__getitem_ _(name)
File "C:\Python25\li b\ctypes\__init __.py", line 358, in __getitem__
func = self._FuncPtr(( name_or_ordinal , self))
AttributeError: function 'myFUNCT' not found
Then maybe the DLL doesn't contain a function called `myFUNCT`. Any
chance you compiled your C as C++ and name mangling kicked in?

Can you show a minimal C source for a DLL, how you compiled it, what you
did on the Python side to call it, and how it fails?

Ciao,
Marc 'BlackJack' Rintsch

I've located my dll in c:\windows\syst em32 (in linux I aven't any
problem) and I compiled it with dev-c++. The source code is C standard
ANSII and is quite havy. If you like I can send it via mail (you can
realy at ge*******@gmail .com) . I've tryed to build a wrape with swig
olso with same code and I can access at all the function.
You can use objdump from mingw or cygwin to look inside the dll and
see exactly what it is exporting, eg

objdump -x OurSharedCodeLi brary.dll

This prints a great deal of stuff! In the middle you'll see

[snip]
The Export Tables (interpreted .rdata section contents)
[snip]
Ordinal/Name Pointer] Table
[ 0] OSCL_DEBUG_fake InitComplete
[ 1] OSCL_close
[ 2] OSCL_displayIde nt
[ 3] OSCL_getCurrent DynamicParams
[ 4] OSCL_getCurrent StaticParams
[ 5] OSCL_getErrorSt ring
[ 6] OSCL_getIdent
[snip]

This is a dll we used in a project, and those names exactly worked
with ctypes, eg some snips from the ctypes code

self.dll = cdll.LoadLibrar y("OurSharedCod eLibrary")
self.dll.OSCL_g etErrorString.r estype = c_char_p

def getErrorString( self, status):
return self.dll.OSCL_g etErrorString(c _int(status))

--
Nick Craig-Wood <ni**@craig-wood.com-- http://www.craig-wood.com/nick
Jun 27 '08 #7
On 23 Mag, 12:30, Nick Craig-Wood <n...@craig-wood.comwrote:
gianluca <geonom...@gmai l.comwrote:
On 23 Mag, 07:48, Marc 'BlackJack' Rintsch <bj_...@gmx.net wrote:
On Thu, 22 May 2008 21:55:41 -0700, gianluca wrote:
Yes, I know it but when I load a function (a=myDLL.myFUNC T()) I've an
exception like this:
Traceback (most recent call last):
File "<pyshell#1 8>", line 1, in <module>
myDLL.myFUNCT()
File "C:\Python25\li b\ctypes\__init __.py", line 353, in __getattr__
func = self.__getitem_ _(name)
File "C:\Python25\li b\ctypes\__init __.py", line 358, in __getitem__
func = self._FuncPtr(( name_or_ordinal , self))
AttributeError: function 'myFUNCT' not found
Then maybe the DLL doesn't contain a function called `myFUNCT`. Any
chance you compiled your C as C++ and name mangling kicked in?
Can you show a minimal C source for a DLL, how you compiled it, what you
did on the Python side to call it, and how it fails?
Ciao,
Marc 'BlackJack' Rintsch
I've located my dll in c:\windows\syst em32 (in linux I aven't any
problem) and I compiled it with dev-c++. The source code is C standard
ANSII and is quite havy. If you like I can send it via mail (you can
realy at geonom...@gmail .com) . I've tryed to build a wrape with swig
olso with same code and I can access at all the function.

You can use objdump from mingw or cygwin to look inside the dll and
see exactly what it is exporting, eg

objdump -x OurSharedCodeLi brary.dll

This prints a great deal of stuff! In the middle you'll see

[snip]
The Export Tables (interpreted .rdata section contents)
[snip]
Ordinal/Name Pointer] Table
[ 0] OSCL_DEBUG_fake InitComplete
[ 1] OSCL_close
[ 2] OSCL_displayIde nt
[ 3] OSCL_getCurrent DynamicParams
[ 4] OSCL_getCurrent StaticParams
[ 5] OSCL_getErrorSt ring
[ 6] OSCL_getIdent
[snip]

This is a dll we used in a project, and those names exactly worked
with ctypes, eg some snips from the ctypes code

self.dll = cdll.LoadLibrar y("OurSharedCod eLibrary")
self.dll.OSCL_g etErrorString.r estype = c_char_p

def getErrorString( self, status):
return self.dll.OSCL_g etErrorString(c _int(status))

--
Nick Craig-Wood <n...@craig-wood.com--http://www.craig-wood.com/nick
Thank you for help!
I've done all you suggest and I've a objdump output like this:
....
[ 86](sec 1)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00003755 _IsCoverRelD
[ 87](sec 1)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00003657 _IsCoverRelA
[ 88](sec 1)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x000034f5 _IsCoverDX
[ 89](sec 1)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x0000341b _IsCoverA
[ 90](sec 1)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00003072 _CoreRelD
[ 91](sec 1)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00002f5e _CoreRelA
....
my funtions are the __IsCoverRelD, __IsCoverRelA, etc but when I call
it (myLIB.__IsCove rRelA or myLIB.__IsCover RelA()) I've the same
problem.
Hy
gianluca
Jun 27 '08 #8

"gianluca" <ge*******@gmai l.comwrote in message
news:ce******** *************** ***********@e39 g2000hsf.google groups.com...
| Thank you for help!
| I've done all you suggest and I've a objdump output like this:
| ...
| [ 86](sec 1)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00003755 _IsCoverRelD
| [ 87](sec 1)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00003657 _IsCoverRelA
| [ 88](sec 1)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x000034f5 _IsCoverDX
| [ 89](sec 1)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x0000341b _IsCoverA
| [ 90](sec 1)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00003072 _CoreRelD
| [ 91](sec 1)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00002f5e _CoreRelA

The name above have one underscore.
| my funtions are the __IsCoverRelD, __IsCoverRelA, etc but when I call
| it (myLIB.__IsCove rRelA or myLIB.__IsCover RelA()) I've the same
| problem.

These all have two. So if that is what you actually did....

tjr

Jun 27 '08 #9

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

Similar topics

8
4029
by: achrist | last post by:
I'm aving some trouble getting callbacks from a Delphi DLL back to python working through ctypes. The call from python to the DLL works fine. In the Delphi(5) code: type TCallbackFunc = function(x: Integer): Integer; stdcall;
2
3275
by: zapazap | last post by:
Dear Snake Charming Gurus, (Was: http://mail.python.org/pipermail/python-list/2004-January/204454.html) First, a thank you to Tim Golden, Thomas Heller, and Mark Hammond for your earlier help with this problem. I am uncertain about what etiquette calls for, but more on that later. My Objective: I am trying to control the _VMWare Desktop_ application
1
2581
by: Thomas Heller | last post by:
ctypes 0.9.1 released - Sept 14, 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
2
2674
by: gap | last post by:
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. ...
1
4726
by: sjdevnull | last post by:
Hey, I'm trying to wrap GNU readline with ctypes (the Python readline library doesn't support the callback interface), but I can't figure out how to set values to a variable inside the library. This is Python 2.5 on Linux. Here's what I have so far--if you comment out the memmove call (3 lines) it works as expected: # START #!/usr/local/bin/python2.5
0
3209
by: malen | last post by:
Hi all! I'm building mouse movement filter program for Windows and Mac OS X. In Windows I use ctypes.windll.user32.getCursorPos(pointer) and ctypes.windll.user32.setCursorPos(x,y) to get and set the cursor position but I do not know what the library and functions are called in Mac OS X (I'm a complete noob when it comes to Mac :) ) To explain better (I hope) here is the windows code for a test program that forces the mouse to use a...
1
2446
by: moreati | last post by:
Recently I discovered the re module doesn't support POSIX character classes: Python 2.5.2 (r252:60911, Apr 21 2008, 11:12:42) on linux2 Type "help", "copyright", "credits" or "license" for more information. None So I thought I'd try out pcre through ctypes, to recreate pcredemo.c in python. The c code is at:
0
2558
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
3
11259
by: Paddy | last post by:
Hi, I am am falling at the first hurdle when trying to access a library using ctypes. I have a file libucdb.so which the file command says is shared object, but I cannot get it to load: Any help would be appreciated: dmccarthy: file /opt/questasim_6.4/questasim/linux/libucdb.a /opt/
2
1337
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 * '''...
0
8736
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,...
0
9373
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9146
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,...
0
8025
agi2029
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...
1
6677
isladogs
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...
0
4498
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...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2592
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2145
bsmnconsultancy
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...

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.