ValueError没有足够的参数 - 尝试使用ctypes访问DLL函数时

时间:2014-07-02 11:01:12

标签: ctypes

尝试使用ctypes访问以下API文档时,我获得了ValueErrors:

doSomeThing(int *param1, 
            int **param2, 
            int **param3, 
            char **param4)
**Parameters**
param1
[in] Pointer to an integer. 
param2
[in, out] Pointer to an integer pointer. Will contain a pointer to a list of indexes [0.. param1-1] which can be looped over. 
param3
[in, out] Pointer to an integer pointer. Will contain a pointer to a list of param3 which can be looped over. The param3 are members of the following enumeration:
        enum EXAMPLE_TYPE
        {
            x = 0,
            y = 1,
                z = 2
        };
param4
[in, out] Pointer to a char pointer. Will contain a pointer to a list of strings which can be looped over

**Return value**
Status code value from the enumeration

这是代码:

print exemple_DLL
param1 = ctypes.c_int()
param2 = (ctypes.POINTER(ctypes.c_int)*1)()
param3 = (ctypes.POINTER(ctypes.c_int)*1)()
param4 = (ctypes.POINTER(ctypes.c_char)*50)()

exemple_DLL.doSomeThing(ctypes.byref(param1), ctypes.byref(param2), ctypes.byref(param3), ctypes.byref(param4))

打印输出:

ValueError:调用的过程没有足够的参数(缺少16个字节)或错误的调用约定 第33行出错:' exemple_DLL.doSomeThing(ctypes.byref(param1),ctypes.byref(param2),ctypes.byref(param3),ctypes.byref(param4))'

任何人都知道使用ctypes在我的函数调用中会出现什么问题?

1 个答案:

答案 0 :(得分:0)

我解决了,必须这样做:

param1 = ctypes.c_int32()
param2 = ctypes.c_int32()
param3 = ctypes.c_int32()
param4 = ctypes.c_int32()

exemple_Dll.doSomeThing(ctypes.byref(param1), ctypes.byref(param2), ctypes.byref(param3), ctypes.byref(param4))