注意:用C ++编写并以python访问的dll
import ctypes
import os
from ctypes import*
def plateDetectedCallback(hEngine, hPlate):
print "successfully loaded"
pass
lib = cdll.LoadLibrary("some dll path")
hLPRRarams = lib.LPRParams_Create()
hEngine = lib.LPREngine_Create(hLPRRarams, True,plateDetectedCallback) # error in this line
plateDetectedCallback是回调函数或函数指针
现在我想按照plateDetectedCallback(LPRENGINE hEngine, LPRPLATE hPlate)
我尝试了不同的方法来调用回调函数,但是失败了。请,任何人都可以帮忙。谢谢
我遇到了类似的异常:
NameError: name 'plateDetectedCallback' is not defined
答案 0 :(得分:0)
我使用@CFUNCTYPE装饰器解决了该问题
@c.CFUNCTYPE(None, c_void_p, c_void_p) def plateDetectedCallback(hEngine, hPlate): ..... .....
没有一个是dll的返回类型(即void),c_void_p是一个void指针
确保导入ctypes