ctypes help

gianluca geonomica at gmail.com
Fri May 23 19:48:27 EDT 2008


On 23 Mag, 12:30, Nick Craig-Wood <n... at craig-wood.com> wrote:
> gianluca <geonom... at gmail.com> wrote:
> >  On 23 Mag, 07:48, Marc 'BlackJack' Rintsch <bj_... at 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.myFUNCT()) I've an
> > > > exception like this:
>
> > > > Traceback (most recent call last):
> > > >   File "<pyshell#18>", line 1, in <module>
> > > >     myDLL.myFUNCT()
> > > >   File "C:\Python25\lib\ctypes\__init__.py", line 353, in __getattr__
> > > >     func = self.__getitem__(name)
> > > >   File "C:\Python25\lib\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\system32 (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... at 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 OurSharedCodeLibrary.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_fakeInitComplete
>         [   1] OSCL_close
>         [   2] OSCL_displayIdent
>         [   3] OSCL_getCurrentDynamicParams
>         [   4] OSCL_getCurrentStaticParams
>         [   5] OSCL_getErrorString
>         [   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.LoadLibrary("OurSharedCodeLibrary")
>         self.dll.OSCL_getErrorString.restype = c_char_p
>
>     def getErrorString(self, status):
>         return self.dll.OSCL_getErrorString(c_int(status))
>
> --
> Nick Craig-Wood <n... at 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.__IsCoverRelA or myLIB.__IsCoverRelA()) I've the same
problem.
Hy
gianluca



More information about the Python-list mailing list