On Mon, Jan 22, 2018, at 16:00, Jason Qian via Python-list wrote: > Hello! > > I am using ctypes on Windows to interface with a dll and it works fine > on Linux and windows 32-bit python. But, when using 64-bit python, we got > error "exception: access violation writing 0xFFFFFFFF99222A60".
You are treating the obj type (myPythonAPI *) as c_int, which is only 32 bits. You should be using a pointer type instead (ideally you should be using void * and c_void_p, so Python doesn't need the class definition.) Don't forget to set lib.loadInstance.restype as well. > __declspec(dllexport) myPythonAPI* loadInstance(){ return new > myPythonAPI(); } > __declspec(dllexport) int createService(myPythonAPI* obj, const char* > serviceName) { eturn obj->createService(serviceName); > lib = cdll.LoadLibrary('xxxxxxx.dll') > > lib.createService.argtypes=[c_int,ctypes.c_char_p] > lib.createService.restype=ctypes.c_int > > class myDriver(object): > def init(self): > self.obj = lib.loadInstance() -- https://mail.python.org/mailman/listinfo/python-list