ctypes callback with char array

O

ohlfsen

Hello.

Hoping that someone can shed some light on a tiny challenge of mine.

Through ctypes I'm calling a c DLL which requires me to implement a callback in Python/ctypes.

The signature of the callback is something like

void foo(int NoOfElements, char Elements[][100])

How do I possible implement/process "char Elements[][100]" in Python/ctypes code?

Thanks a lot in advance.

Best Regards
A. (Python amateur).
 
D

Diez B. Roggisch

ohlfsen said:
Hello.

Hoping that someone can shed some light on a tiny challenge of mine.

Through ctypes I'm calling a c DLL which requires me to implement a callback in Python/ctypes.

The signature of the callback is something like

void foo(int NoOfElements, char Elements[][100])

How do I possible implement/process "char Elements[][100]" in Python/ctypes code?

I'd try it like this:

$ python
Python 2.7 (r27:82500, May 2 2011, 22:50:11)
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
oWelcome to rlcompleter2 0.98
.... pass
....<CFunctionType object at 0x100697940>


No need to know that it's a pointer to char[100] pointers - you can cast
that if you want to.

Diez
 

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,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top