因为 ctypes
是内置模块,可以直接使用:
from ctypes import *
加载dll程序
from ctypes import *
dll = CDLL('./test-sdk.dll')
调用dll方法
直接调用:
from ctypes import *
dll = CDLL('./test-sdk.dll')
dll.test_method()
传递 数字 参数:
from ctypes import *
dll = CDLL('./test-sdk.dll')
dll.test_method(1)
传递 指针 参数:
from ctypes import *
dll = CDLL('./test-sdk.dll')
context_id = c_int(0)
dll.test_method(byref(context_id))
传递 自定义的数据类型 参数:
from ctypes import *
dll = CDLL('./test-sdk.dll')
class Point2f(Structure):
_fields_ = [('x', c_float), ('y', c_float)]
class ROI(Structure):
_fields_ = [('number', c_int), ('points', Point2f)]
dll.test_method(ROI(1, Point2f(0.21, 0.43)))
传递 numpy.ndarray 参数:
import numpy as np
from ctypes import *
dll = CDLL('./test-sdk.dll')
frame = np.array([[1,2,3], [2,3,4]])
frame_data = c_char_p(frame.tobytes())
dll.test_method(frame_data)
网友评论