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;
ctypes is a foreign function library for Python. It provides C compatible data types, and allows calling functions in DLLs or shared libraries. It can be used to wrap these libraries in pure Python.
It is a big C++ codebase with a (very) thin python wrapper which uses CDLL to load the C++ and call some C functions that are available to allow primitive python scripting of the code.
Specifies the type of AFP print resources ACIF retrieves from the resource directories or libraries for inclusion in the resource file (specified with the RESOBJDD parameter).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With