Help: 64bit python call c and got OSError: exception: access violation writing 0xFFFFFFFF99222A60
Jason Qian
jqian at tibco.com
Wed Jan 24 16:25:24 EST 2018
Again, thanks for the help. Everything is working fine after the changes.
Here is one more new issue needs some help.
On c side,
The createService function can pass a callback handler as second
parameter.
Without callback handler, it works fine. But if we add the callback
handler, the application will give a exception due to the pointer of
callback handler = NULL;
Not sure, why the callback handler missed up, when the app calling from
python.
Thanks
-- python
lib.createService.argtypes=[ctypes.c_void_p,ctypes.c_char_p]
lib.createService.restype=ctypes.c_int
def create_services(self,servicename):
result=lib.createService(self.obj,servicename)
return result
--c --
__declspec(dllexport) int createService(void* obj, const char* serviceName)
{
return ((myPythonAPI*)obj)->createService(serviceName);
}
int myPythonAPI::createService(const char* serviceName)
{
//case 1 :
//This works fine
createService(methodname);
//case 2
//This will not working,
InvocationCallback serviceCallback;
createService(methodname, &serviceCallback);
}
On Mon, Jan 22, 2018 at 5:58 PM, Jason Qian <jqian at tibco.com> wrote:
> Thanks you very much, fixed the problem :)
>
> On Mon, Jan 22, 2018 at 4:28 PM, Random832 <random832 at fastmail.com> wrote:
>
>> 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
>>
>
>
More information about the Python-list
mailing list