美文网首页
python使用ctypes调用dll

python使用ctypes调用dll

作者: 何小有 | 来源:发表于2022-06-14 19:26 被阅读0次

因为 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)

相关文章

网友评论

      本文标题:python使用ctypes调用dll

      本文链接:https://www.haomeiwen.com/subject/xgnzmrtx.html