【发布时间】:2014-08-28 15:19:30
【问题描述】:
我尝试在 Python 中从外部 DLL 调用函数。
函数原型为:
void Myfunction(int32_t *ArraySize, uint64_t XmemData[])
此函数创建一个包含“ArraySize”元素的 uint64 表。这个dll是labview生成的。
以下是调用此函数的 Python 代码:
import ctypes
# Load the library
dllhandle = ctypes.CDLL("SharedLib.dll")
#specify the parameter and return types
dllhandle.Myfunction.argtypes = [ctypes.c_int,ctypes.POINTER(ctypes.c_uint64)]
# Next, set the return types...
dllhandle.Myfunction.restype = None
#convert our Python data into C data
Array_Size = ctypes.c_int(10)
Array = (ctypes.c_uint64 * Array_Size.value)()
# Call function
dllhandle.Myfunction(Array_Size,Array)
for index, value in enumerate(Array):
print Array[index]
执行此操作时出现错误代码:
dllhandle.ReadXmemBlock(Array_Size,Array)
WindowsError: exception: access violation reading 0x0000000A
我猜我没有正确地将参数传递给函数,但我无法弄清楚。
我尝试像 uint64 一样对来自 labview dll 的简单数据进行排序,效果很好;但是一旦我尝试传递 uint64 数组,我就卡住了。
任何帮助将不胜感激。
【问题讨论】:
标签: arrays dll parameters ctypes