c代码如下:
extern "C"
int DllTestCB(int (*callback)(char *), char* str)
{
if (callback != NULL)
{
int cnt = 1;
while (cnt--)
{
callback(str);
Sleep(1000);
}
}

return 0;
}
python代码如下:
#!/usr/bin/env python
#coding=utf-8

from ctypes import *

def callback(abc):
print 'callback by c++ in python... %s' % abc
return 0
libtest = cdll.dll_py
CMPFUNC = CFUNCTYPE(c_int, c_char_p)
_callback = CMPFUNC(callback)
testcb = libtest.DllTestCB
testcb.restype = None
testcb(_callback, 'a sample++')
运行后,结果如下:
callback by c++ in python... a sample++















python代码如下:















运行后,结果如下:
