How to pass char pointer as parameter in ctypes python


Naveen kumar Katta rathanaiah

Please help me to convert the following line of C++ code to ctypes python:

Ret = openFcn(&Handle, "C:\\Config.xml");

Here are the declarations for each:

typedef uint16_t (* OpenDLLFcnP)(void **, const char *);
OpenDLLFcnP openFcn = NULL;
openFcn = (OpenDLLFcnP) myLibrary.resolve("Open");
void *Handle = NULL;
Mark Tolonen

myLibrary.resolveis undefined, but the generic code you need (not debugged) is:

import ctypes
dll = ctypes.CDLL('your.dll')
Open = dll.Open
Open.argtypes = [ctypes.POINTER(ctypes.c_void_p),ctypes.c_char_p]
Open.restype = ctypes.c_uint16
Handle = ctypes.c_void_p()
result = Open(ctypes.byref(Handle),'c:\\Config.xml')

Suppose you have a DLL named with your.dllthe function Openyou want to call .

Related


Python Ctypes pass data pointer

Hook I am accessing the API and I am not able to get the returned data. Two floating point pointers will point to an array of data. I have to assume the API is functioning properly. Different function calls provide the length of the data I want to retrieve. le

Python Ctypes pass data pointer

Hook I am accessing the API and I am not able to get the returned data. Two floating point pointers will point to an array of data. I have to assume the API is functioning properly. Different function calls provide the length of the data I want to retrieve. le

Python Ctypes pass data pointer

Hook I am accessing the API and I am not able to get the returned data. Two floating point pointers will point to an array of data. I have to assume the API is functioning properly. Different function calls provide the length of the data I want to retrieve. le

Pass char pointer as parameter to function

unlimited This item table prints different permutations of strings. If I declare the string as a char array in main and pass the array name in the printAnagram function it works fine. But if I declare string as char *s="hello" and pass 's' it crashes. Why? #in

Pass char pointer as parameter to function

unlimited This item table prints different permutations of strings. If I declare the string as a char array in main and pass the array name in the printAnagram function it works fine. But if I declare string as char *s="hello" and pass 's' it crashes. Why? #in

Python ctypes parameter with DLL - pointer to array of doubles

lightning I'm a novice programmer using ctypes with Python and trying to use functions from a DLL written in C. I've found a lot of similar questions on SO to solve, but none of the answers to this kind of conundrum. I have the DLL loaded just fine, but one of

Python ctypes parameter with DLL - pointer to array of doubles

lightning I'm a novice programmer using ctypes with Python and trying to use functions from a DLL written in C. I've found a lot of similar questions on SO to solve, but none of the answers to this kind of conundrum. I have the DLL loaded just fine, but one of

Python ctypes parameter with DLL - pointer to array of doubles

lightning I'm a novice programmer using ctypes with Python and trying to use functions from a DLL written in C. I've found a lot of similar questions on SO to solve, but none of the answers to this kind of conundrum. I have the DLL loaded just fine, but one of

python ctypes, pass double pointer by reference

your destiny question I'm trying to use a function from a c library with the following prototype: int glip_get_backends(const char ***name, size_t *count); The parameter here nameis the problem. It is a 2-dimensional char array passed by reference. In C, the u

Python ctypes pass string pointer/buffer

boss I'm trying to get information from a sensor via its DLL using Python. I've never used ctypes or C before, so I'm lacking some knowledge about this, hope someone can help me. Calling the function works so far, but I can't get the function to return the str

python ctypes, pass double pointer by reference

your destiny question I'm trying to use a function from a c library with the following prototype: int glip_get_backends(const char ***name, size_t *count); The parameter here nameis the problem. It is a 2-dimensional char array passed by reference. In C, the u

Pass pointer to char array as parameter to function - C

Macaque In the function declaration below, the first parameter is a String, specifically an array of chars, and the third parameter is a pointer to an integer. Is the second parameter a pointer to an array of characters? In other words, a pointer to a pointer?

Pass pointer to char array as parameter to function - C

Macaque In the function declaration below, the first parameter is a String, specifically an array of chars, and the third parameter is a pointer to an integer. Is the second parameter a pointer to an array of characters? In other words, a pointer to a pointer?

Pass pointer to char array as parameter to function - C

Macaque In the function declaration below, the first parameter is a String, specifically an array of chars, and the third parameter is a pointer to an integer. Is the second parameter a pointer to an array of characters? In other words, a pointer to a pointer?

Pass pointer to char array as parameter to function - C

Macaque In the function declaration below, the first parameter is a String, specifically an array of chars, and the third parameter is a pointer to an integer. Is the second parameter a pointer to an array of characters? In other words, a pointer to a pointer?

How to pass char pointer to C++ API via python?

Anthony I am trying to call the following C++ method from my python code: TESS_API TessResultRenderer* TESS_CALL TessTextRendererCreate(const char* outputbase) { return new TessTextRenderer(outputbase); } I'm having trouble with how to pass pointers to me

How to pass char pointer to C++ API via python?

Anthony I am trying to call the following C++ method from my python code: TESS_API TessResultRenderer* TESS_CALL TessTextRendererCreate(const char* outputbase) { return new TessTextRenderer(outputbase); } I'm having trouble with how to pass pointers to me