我正在尝试为WinXP计算机上的相机编写一个非常简单的控制器。而不是编写C代码,我想我只会使用ctypes访问dll。
要启动相机,您必须致电:
BeginHVDevice(int nDevice, HHV *pHandle)
* pHandle是指向摄像机句柄的指针,在.h文件中,它简单地定义为
typedef HANDLE HHV;
我以为以下应该起作用
from ctypes import *
from ctypes.wintypes import *
ailt_lib = cdll.LoadLibrary("HVDAILT")
load_camera = ailt_lib.BeginHVDevice
load_camera.restype = c_int
load_camera.argtypes = [c_int, POINTER(HANDLE)]
def initDev(res=(800,600)):
cam_int = c_int(1)
cam_handle_type = POINTER(HANDLE)
print cam_handle_type
cam_handle = cam_handle_type()
print cam_handle
cam_stat = load_camera(cam_int, cam_handle )
print cam_stat
return cam_handle
但是,当我调用initDev()时,得到了ValueError:所调用的过程没有足够的参数(缺少8个字节)或错误的调用约定。我很确定这意味着我还没有产生兼容的指针来传递,但是我无法弄清楚该函数实际上想要接收什么。
我花了几天时间搜索stackoverflow,查看了ctypes文档并尝试了各种排列,但是我没有找到答案。
似乎该函数正在使用stdcall
而不是cdecl
调用约定,即使用ctypes.WinDLL
代替ctypes.CDLL
。同样,它想要一个指向可以存储该句柄的内存位置的指针,但是您向它传递了一个NULL
指针。而是将其传递给wintypes.HANDLE
。
from ctypes import *
from ctypes.wintypes import *
ailt_lib = WinDLL("HVDAILT")
load_camera = ailt_lib.BeginHVDevice
load_camera.restype = c_int
load_camera.argtypes = [c_int, POINTER(HANDLE)]
def initDev(res=(800,600)):
cam_int = 1
cam_handle = HANDLE()
cam_stat = load_camera(cam_int, byref(cam_handle))
print 'cam_stat:', cam_stat
print 'cam_handle:', cam_handle
return cam_handle
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句