472,328 Members | 1,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

Working with ctypes and char** data type

I'm a bit of a python newbie and I need to wrap a C library.

I can initialise the library using CDLL('mcclient.so')

and I can call functions correctly inside the library but I need to
invoke one function which has this function definition:

char ** CAPAPI McSearch(HMCLINK Handle,
short nSearchType,
short nNoSelect,
char **pSelect,
short nNoWhere,
char **pWhere,
char **pData,
int iTimeout);

For **pSelect I want to pass in an array of char points, which in C
would be declared as

char *pData[] = { "ADDR", "POSTCODE" };

Can someone tell me how use pointers + char pointers together in
python with ctypes please?

Thank you

Phill
Jul 24 '08 #1
2 6590
Philluminati schrieb:
I'm a bit of a python newbie and I need to wrap a C library.

I can initialise the library using CDLL('mcclient.so')

and I can call functions correctly inside the library but I need to
invoke one function which has this function definition:

char ** CAPAPI McSearch(HMCLINK Handle,
short nSearchType,
short nNoSelect,
char **pSelect,
short nNoWhere,
char **pWhere,
char **pData,
int iTimeout);

For **pSelect I want to pass in an array of char points, which in C
would be declared as

char *pData[] = { "ADDR", "POSTCODE" };

Can someone tell me how use pointers + char pointers together in
python with ctypes please?
# create an array that holds two pointers to 'char *', and fill it with data:
pData = (c_char_p * 2)()
pData[0] = "ADDR"
pData[1] = "POSTCODE"

# Another way:
pData = (c_char_p * 2)("ADDR", "POSTCODE")

Thomas
Jul 24 '08 #2
On Jul 24, 4:03*pm, Thomas Heller <thel...@python.netwrote:
Philluminati schrieb:
I'm a bit of a python newbie and I need to wrap a C library.
I can initialise the library using CDLL('mcclient.so')
and I can call functions correctly inside the library but I need to
invoke one function which has this function definition:
char ** CAPAPI McSearch(HMCLINK Handle,
* * * * * * * * * * * * short nSearchType,
* * * * * * * * * * * * short nNoSelect,
* * * * * * * * * * * * char **pSelect,
* * * * * * * * * * * * short nNoWhere,
* * * * * * * * * * * * char **pWhere,
* * * * * * * * * * * * char **pData,
* * * * * * * * * * * * int iTimeout);
For **pSelect I want to pass in an array of char points, which in C
would be declared as
char *pData[] = { "ADDR", "POSTCODE" };
Can someone tell me how use pointers + char pointers together in
python with ctypes please?

# create an array that holds two pointers to 'char *', and fill it with data:
pData = (c_char_p * 2)()
pData[0] = "ADDR"
pData[1] = "POSTCODE"

# Another way:
pData = (c_char_p * 2)("ADDR", "POSTCODE")

Thomas
Thank you Thomas for your reply. I also got it working in a slightly
less sophisticated manor like this:

SelectType = c_char_p * 2
select = SelectType("ADDR", "POSTCODE")
ptr = pointer(select)

Anyway, thanks for taking the time to reply!

Phill
Jul 25 '08 #3

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

Similar topics

1
by: Thomas Heller | last post by:
ctypes 0.9.1 released - Sept 14, 2004 ===================================== Overview ctypes is a ffi (Foreign Function Interface) package for...
3
by: Martin P. Hellwig | last post by:
Hey all, I'd like to wrap libpam so that I can use that for authentication and password management. I build ctypes (0.9.9.6) on my platform via...
12
by: p.lavarre | last post by:
Q: The C idea of (pv != NULL) is said most directly in Python ctypes how? A: We are of course supposed to write something like: def...
0
by: Oliver Andrich | last post by:
Hi everybody, I am currently playing around with ctypes and a C library (libWand from ImageMagick), and as I want to easily deploy it on Mac,...
7
by: p.lavarre | last post by:
How do I vary the byte offset of a field of a ctypes.Structure? How do I "use the dynamic nature of Python, and (re-)define the data type after...
6
by: Jack | last post by:
I'm not able to build IP2Location's Python interface so I'm trying to use ctypes to call its C interface. The functions return a pointer to the...
5
by: castironpi | last post by:
Hi all, I have a mmap and a data structure in it. I know the structure's location in the mmap and what structure it is. It has a ctypes...
2
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. ...
3
by: patelss23 | last post by:
Hello All, I am dealing with this weird bug. I have a function in C and I have written python bindings for it using ctypes. I can call this...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

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.