定义Python中的数组类型,由C函数填充

Define array type in Python to be filled by C function

C header 中,“param1”被声明为 OUT 参数:

long A_API test( 
                        ___OUT_ char param1
                   )

Python 代码中,我尝试使用数组,以便 test 函数具有 space 来填充此 parameter.I 已导入 ctpyes 并且:

test_array = bytearray(b'')
importArray = (ctypes.c_char*40)(*test_array)

def callTest():
    result = lib.test(importArray)
    return result

但是 test 函数没有被执行,它在某处失败了。

不幸的是,我只有 .so 文件,没有源代码,所以我无法调试代码,但我想我这里有类型定义问题。

感谢任何帮助。

Python 根据函数定义,代码应该是这样的:

out_char = ctypes.c_char()
result = lib.test(ctypes.byref(out_char))