KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
It seems odd that even after setting restype , python returns long rather than c_void_p . For example; # python code from ctypes import * dll = windll.LoadLibrary("my.dll") dll.my_object_create.restype = c_void_p x = dll.my_object_create() print type(x) # prints <type 'long'> //c++ code my_object *my_object_create() { return new my_object(); } void my_object_destroy(my_object *obj) { delete obj; } I recently had to fix a bug where, feeding x back to another ctypes function, the pointer got trampled. This was fixed by changing the initial dll call to x = c_void_p(dll.my_object_create()) ...I'm guessing somewhere along the line ctypes treated x as 4 bytes long not 8 (64 bit architecture). So I am wondering if there is a reason why the existing behaviour leads you into this trap?
Tags (comma-separated)
Save Edits
Cancel