Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python中的C枚举typedef ctypes TypeError_Python_C_Ctypes - Fatal编程技术网

Python中的C枚举typedef ctypes TypeError

Python中的C枚举typedef ctypes TypeError,python,c,ctypes,Python,C,Ctypes,我试图用ctypes调用Python中的外部C库。我一直进展顺利,直到我得到了一个特定的函数调用,该函数调用引用了某个枚举,该枚举在头文件中定义如下: typedef enum { a = 0, b } A; 我尝试了各种调用函数的方法,但我一直得到: a = libc.function2(out, 0, outputCallback, c_int(1), 1) ctypes.ArgumentError: argument 3: <

我试图用ctypes调用Python中的外部C库。我一直进展顺利,直到我得到了一个特定的函数调用,该函数调用引用了某个枚举,该枚举在头文件中定义如下:

typedef enum { a = 0,
               b
             } A;
我尝试了各种调用函数的方法,但我一直得到:

a = libc.function2(out, 0, outputCallback, c_int(1), 1)
ctypes.ArgumentError: argument 3: <type 'exceptions.TypeError'>: Don't know how to convert parameter 3

我想我看到了问题所在,也理解你的问题。参数不是从0开始编号,而是从1开始编号。问题在于我的回调函数。
cdll.LoadLibrary("library.so")

libc = CDLL("library.so")


def outputCallback():
    print "Hello"

// This function executes properly
out = libc.function1(0, 0, 0, 0, 0)


// Function that gives error                  #
a = libc.function2(out, 0, outputCallback, c_int(1), 1)