파이썬에서 .dll
라이브러리의 콜백 함수를 ctypes로 등록하려고합니다. 하지만 구조체/필드에 콜백 함수가 필요합니다. 그것은 작동하지 않기 때문에 (오류는 없지만 콜백 함수는 아무 것도하지 않습니다) 제가 틀렸다고 가정합니다. 누구 좀 도와 주시겠습니까?파이썬 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)
대단히 감사합니다. 지금은 작동합니다. –