python往c语言传指针_为C语言中的函数指针回调函数编写PythonC类型

我正试图编写python代码来调用dll函数,并停留在下面的函数上,

我认为这与typedef回调函数或函数指针有关。

我已经测试了下面的代码,当调用回调函数时,python崩溃(窗口通知——python.exe停止响应),没有调试消息。

我深感困惑,任何帮助都将不胜感激:)

谢谢!

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值