Reputation: 1182
I need to change some python code to call into a c api that looks like this:
int start_our_service(WCHAR* extra, int numargs, WCHAR** args);
I have this:
dll = ctypes.WinDLL(__DLL_PATH)
dll.restype = ctypes.c_int32
dll.argtypes = [ctypes.c_char_p, ctypes.c_int, POINTER(POINTER(ctypes.c_char_p))]
data = (ctypes.c_char_p)("-t:9".encode())
ptr = POINTER(ctypes.c_char_p)(data)
dll.start_service("TEST", 2, ctypes.byref(ptr))
All the args get through ok except the last, the WCHAR**. I'm obviously missing something but can't see it, any ideas?
python 3/windows
TIA
Upvotes: 3
Views: 533
Reputation: 1930
I think you are overcomplicating things by trying to declare the function arguments (which, by the way, you are assigning to the dll instead of the function). The simplest amount of code I can come up with that does what you seem to intend to do is:
argvector = ctypes.c_char_p * 2
args = argvector(b"-t=9", b"--verbose")
dll = ctypes.WinDLL(__DLL_PATH)
dll.start_service("TEST", 2, args)
I.e. Create an array of pointers type, instantiate it and pass it.
I am also passing two arguments where you seem to be passing only one.
Upvotes: 1