I have a C++ dll, one of the export function is defined as follows:
OPERATEMYSQLSTDCALL_API int __stdcall CheckMac(char * pcMac, OUT LPSTR errorInfo);
I use it in python, use the ctypes library,i read some of the information and call it as follws:
from ctypes import *
lib = WinDLL('OperateMysqlStdcall.dll')
CheckMac = lib.CheckMac
CheckMac.argtypes = [c_char_p, POINTER(c_wchar_p)]
CheckMac.restype = c_int
p1=c_wchar_p()
value = CheckMac('88888888',byref(p1));
print p1.value
but when i execute it,it return None,i'm sure the value "OUT LPSTR errorInfo" in C++ is not NULL,i print it in console and it shows Correctly.could anyone tells me why it can't work in python.Thank U very much!
The type of
LPSTR
ischar*
so you should usec_char_p
for its type as well. As an output parameter, though, you need a writable string buffer. Ideally, the API should indicate the size of the buffer passed so a buffer overrun could be checked.Here's some test DLL code:
And Python:
Output: