calling functions returned as pointers from other functions in ctypes

社会主义新天地 提交于 2019-12-06 07:25:58

You are not defining any return type for _foo, try adding:

_foo.restype = c_void_p

ctypes defaults to int returntype, and it looks (from the cast done in you pdb session) like you are on a 64-bit system meaning that you pointer will be truncated when converted to int. On my system the code seems to work - but that is a 32-bit system (and unfortunately I don't have any 64-bit system available to test on right now).

Also you _bar definition doesn't really match what is in the C code, I suggest using something like:

_bar = CFUNCTYPE(c_longlong, c_void_p).in_dll(_lib, "bar")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!