2
我正在嘗試使用ctypes爲Python中的.dll
庫註冊回調函數。但它需要結構/字段中的回調函數。因爲它不起作用(沒有錯誤,但回調函數什麼都不做),我想我錯了。請有人幫助我嗎?Python ctypes中的字段中的回調函數
有一個代碼,希望解釋什麼,我試圖做的:
import ctypes
firsttype = CFUNCTYPE(c_void_p, c_int)
secondtype = CFUNCTYPE(c_void_p, c_int)
@firsttype
def OnFirst(i):
print "OnFirst"
@secondtype
def OnSecond(i):
print "OnSecond"
class tHandlerStructure(Structure):
`_fields_` = [
("firstCallback",firsttype),
("secondCallback",secondtype)
]
stHandlerStructure = tHandlerStructure()
ctypes.cdll.myDll.Initialize.argtypes = [POINTER(tHandlerStructure)]
ctypes.cdll.myDll.Initialize.restype = c_void_p
ctypes.cdll.myDll.Initialize(stHandleStructure)
太好了,謝謝你,現在它的作品。 – 2011-01-16 15:06:32