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 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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Thomas Heller |
last post by:
ctypes 0.9.1 released - Sept 14, 2004
=====================================
Overview
ctypes is a ffi (Foreign Function Interface) package for...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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. ...
|
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...
|
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....
|
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...
|
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...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
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...
|
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...
|
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...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
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...
| |