【发布时间】:2016-12-08 01:39:53
【问题描述】:
我的Python代码,C有一个回调函数:
global cbGetIMSI
CB_GET_IMSI = CFUNCTYPE(None, c_char_p)
cbGetIMSI = CB_GET_IMSI(py_getIMSI)
def py_getIMSI(imsi):
global tc
tc = import(mod)
imsi = tc.getIMSI()
print '####### imsi = ' + imsi
并调用C函数注册:
lib_inf = cdll.LoadLibrary(self.libinf.get())
lib_inf.inf_regCbGetImsi(cbGetIMSI)
我的 C 代码:
typedef void (*inf_PyCbGetImsi)(char *);
int inf_regCbGetImsi(inf_PyCbGetImsi cbFn)
{
DBG("enter [%s()]", FUNCTION);
if (!cbFn)
{
return -1;
}
g_pyCB.getImsi = cbFn;
return 0;
}
static int GetIMSI()
{
int ret = 0;
int i = 0;
unsigned char aIMSI[15];
DBG("[enter %s()]", __FUNCTION__);
memset(aIMSI, 0, sizeof(aIMSI));
if (g_pyCB.getImsi)
{
g_pyCB.getImsi(aIMSI);
}
DBG("[%s()] aIMSI = [%s]", __FUNCTION__, aIMSI);
return ret;
}
在 Python 中运行日志:
####### imsi = 001010123456789
in C Program:
[GetIMSI()] aIMSI = []
为什么参数的值没有改变,我该如何解决?谢谢!
【问题讨论】:
-
不为NULL,否则无法执行py_getIMSI。谢谢。
-
def getIMSI(): return '001010123456789'