【发布时间】:2012-12-11 14:57:13
【问题描述】:
我正在尝试使用 ctypes 调用 dll 函数并出现错误。我如何才能获得有关我的通话有什么问题的更多信息?
dll函数头:
DLL_API BOOL WINAPI DDSSetFrequency(int index, double frequency, int* wavePointNum, int* TNum);
python 代码
from ctypes import *
hantek = cdll.LoadLibrary("E:\Programmer's Guide\DLL\DDS3X25Dll.dll")
print hantek.DDSSearch()
wavePointNum = c_int()
Tnum = c_int()
frequency = c_double(10000000.0)
index = c_int32(1)
hantek.DDSSetFrequency(index,frequency,byref(wavePointNum),byref(Tnum))
1
Traceback (most recent call last):
File "3x25.py", line 17, in <module>
hantek.DDSSetFrequency(index,frequency,byref(wavePointNum),byref(Tnum))
ValueError: Procedure called with not enough arguments (20 bytes missing) or wro
ng calling convention
【问题讨论】:
-
尝试将DLL加载为
windll并定义hantek.DDSSetFrequency函数的argtypes和restype。 docs.python.org/2/library/ctypes.html -
更改为 windll 帮助了一些,没有更多的错误。但我仍然没有得到 wavePointNum 和 Tnum 中的返回值。你能解释一下定义 argtypes 和 restype 的意思吗?
-
a 根据文档进行了更改 hantek = windll.LoadLibrary("E:\Programmer's Guide\DLL\DDS3X25Dll.dll") hantek.DDSSetFrequency.argtypes = [c_int, c_double, POINTER(c_int), POINTER (c_int)] hantek.DDSSetFrequency.restype = c_bool 仍然没有从函数中得到任何东西。那些不需要任何参数的执行得很好。我现在正在尝试来自 VB 的相同 dll,看看它是否在那里工作......