[英]error when passing function pointer as a argument in python
Note: dll written in C++ and accessing in python 注意:使用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 is a callback function or function pointer plateDetectedCallback是回调函数或函数指针
Now I want to call callback function as per documentation like plateDetectedCallback(LPRENGINE hEngine, LPRPLATE hPlate)
现在我想按照plateDetectedCallback(LPRENGINE hEngine, LPRPLATE hPlate)
类的文档调用回调函数
I tried in different ways to call the callback function but failed. 我尝试以不同的方式调用回调函数,但失败了。 please, Can any one help in this. 请,任何人都可以帮忙。 Thankyou 谢谢
I am getting the exception like: 我得到像这样的异常:
NameError: name 'plateDetectedCallback' is not defined
I solved the Issue Using @CFUNCTYPE decorator 我使用@CFUNCTYPE装饰器解决了问题
@c.CFUNCTYPE(None, c_void_p, c_void_p) def plateDetectedCallback(hEngine, hPlate): ..... .....
None is the return type of dll(ie void), c_void_p is a void pointer dll的返回类型为None(即void),c_void_p为void指针
make sure to import the ctypes 确保导入ctypes
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.