OSError:exception:access violation reading 类似这种错误,考虑为内存问题,检查参数类型是否正确,参数格式有无问题。
我的代码中该参数是一个结构体,我对应C库中的结构体定义了一个一样的python结构体
class py_testInfo(Structure):
fields = [
(‘test_ID2’, c_uint32),
(‘test_ID1’, c_uint32),
(‘test_General’, c_uint8)
]
以上结构体就是接口的入参类型,而我在调用的时候就出现了以上问题
test = py_testInfo()
test.test_ID2 = 3
test.test_ID1 = 4
test.test_General = 5
lib.test_api(test )
我看打印的这个0x000000000017跟我这个参数test的地址也是不同,于是将该参数改成byref(test),也就是:lib.test_api(byref(test)),该错误消除
python通过ctypes调用动态库,错误OSError:exception:access violation reading 0x000000000017
最新推荐文章于 2023-11-25 21:24:38 发布