passing c_void_p to an library(.so) to c function

O

OJ

Hi
I am trying to implement a python frontend for a c library. I can open
the library successfully and call functions using ctypes. My challenge
now is that this library are using plugins, which is also libraries
(.so on linux).

The library function for adding these plugins expects a viod * to the
plugin. Here is what I have so far:

main = ctypes.cdll.LoadLibrary(libpath) # This is the main library
plugin = ctypes.cdll.LoadLibrary(filename) # This is the plugin
print '%s' % (plugin)
rval = main.CoreAttachPlugin(2, None)

The above example produces:
<CDLL '/usr/local/lib/mupen64plus/mupen64plus-video-rice.so', handle
dad4d0 at 7f567e6e2c50>

In this case I get no error message, but this is with the void * =
NULL, so the plugin is not attached. I have tried different thing to
pass the void *.

Test 1:
rval = main.CoreAttachPlugin(2, plugin)

<CDLL '/usr/local/lib/mupen64plus/mupen64plus-video-rice.so', handle
1a824a0 at 7f2959e3fc50>
Traceback (most recent call last):
File "./m64p.py", line 171, in <module>
rval = m64p.CoreAttachPlugin(i, plugin)
ctypes.ArgumentError: argument 2: <type 'exceptions.TypeError'>: Don't
know how to convert parameter 2


Test 2:
rval = main.CoreAttachPlugin(2, plugin._handle)

<CDLL '/usr/local/lib/mupen64plus/mupen64plus-video-rice.so', handle
dee480 at 7f7e8f44fc50>
Segmentation fault

Test 3:
rval = main.CoreAttachPlugin(2, ctypes.byref(plugin))

<CDLL '/usr/local/lib/mupen64plus/mupen64plus-video-rice.so', handle
24e0430 at 7f7dfe015c50>
Traceback (most recent call last):
File "./m64p.py", line 171, in <module>
rval = m64p.CoreAttachPlugin(i, ctypes.byref(plugin))
TypeError: byref() argument must be a ctypes instance, not 'CDLL'

Does anyone have some tips to how I can do what I want :)?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top