how to pass char pointer as argument in ctypes python

Please help me in converting below line of c++ code into ctypes python:

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

below are the declarations of each:

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

Upvotes: 7

Views: 13121

Answers (1)

Mark Tolonen
Mark Tolonen

Reputation: 177971

myLibrary.resolve is undefined, but the general code you need (untested) 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')

This assumes you have a DLL named your.dll with a function Open you want to call.

Upvotes: 5

Related Questions