how to pass char pointer as argument in ctypes python

10,159

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.

Share:
10,159
Naveen kumar Katta rathanaiah
Author by

Naveen kumar Katta rathanaiah

Updated on June 09, 2022

Comments

  • Naveen kumar Katta rathanaiah
    Naveen kumar Katta rathanaiah almost 2 years

    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;