我在定義一個DLL文件中的C函數如下:如何通過ctypes將void *數組傳遞給C函數?
myFunction(const int a, long b, void * data, unsigned int * c, unsigned int * d, unsigned long * timestamp)
參數:
[in]: a
[in]: b
[out]: data, which is a pointer to a buffer that is maximum of 8 bytes
[out]: c, points to a buffer that receives data message length
[out]: d, pointer to a buffer which receives a message flag
[out]: timestamp, pointer to a buffer which receives message timestamp
我的Python代碼如下:
import ctypes
dllhandle = ctypes.WinDLL("dllFile.dll")
a = 1
b = 1738
data = ctypes.c_void_p*8
c = 0
d = 0
timestamp = 0
dllhandle.myFunction(a, b, data, c, d, timestamp)
當我跑我的Python代碼,我得到以下錯誤:
ctypes.ArgumentError: argument 3: <type 'exceptions.TypeError'>: Don't know how to convert parameter 3.
我想這與我如何創建我的數據緩衝區指針數組有關。創建數據緩衝區的正確方法是什麼?