I am trying to write python code to call dll functions and stuck at the function below, which I believe is related to the typedef callback function or the function pointer thing.
I have tested the code below, when the callback function is called, python crashes (Window notification-- python.exe has stop responding) with no debug msg.
I am deeply confused, any help will be appreciated :)
Thanks!
C:
#ifdef O_Win32
/** @cond */
#ifdef P_EXPORTS
#define API __declspec(dllexport)
#else
#define API __declspec(dllimport)
#endif // #ifdef P_EXPORTS
/** @endcond */
#endif // #ifdef O_Win32
// Type definition
typedef void (__stdcall *StatusCB)(int nErrorCode, int nSID, void *pArg);
//Function
void GetStatus(StatusCB StatusFn, void *pArg);
Python:
from ctypes import *
def StatusCB(nErrorCode, nSID, pArg):
print 'Hello world'
def start():
lib = cdll.LoadLibrary('API.dll')
CMPFUNC = WINFUNCTYPE(c_int, c_int, c_void_p)
cmp_func = CMPFUNC(StatusCB)
status_func = lib.GetStatus
status_func(cmp_func)