Updated: python ctype question about "access violation readinglocation 0x5a5a5a5a"

Y

Yanping Zhang

Here are more details about my codes, please help!

The function declared in C:
typedef void (WINAPI *PLEARNCALLBACKPROC) (unsigned int progress, unsigned int sigQuality,
unsigned long carrierFreq, void *userData);

UUIRTDRV_API BOOL PASCAL UUIRTLearnIR(HUUHANDLE hHandle, int codeFormat, char *IRCode,
PLEARNCALLBACKPROC progressProc, void *userData, BOOL *pAbort, unsigned int param1, void
*reserved0, void *reserved1);

My python codes:

import ctypes

port = windll.uuirtdrv

myhandle = c_void_p()

myhandle = port.UUIRTOpen()


#+++++++ Call back function ++++++++
LEARNCALLBACKFUNC = CFUNCTYPE(c_void_p, c_uint, c_uint, c_ulong, c_void_p)

def py_learncallback_func(progress,sigQuality, carrierFreq, userdata):

print "progress is: %d %d %d %d" % (progress, sigQuality & 0xff, carrierFreq, userdata)
if progress == 100:
mybool = c_int(1)

return

callback_func = LEARNCALLBACKFUNC(py_learncallback_func)

#++++++++++++++++++++++++++++++++++++++

glearnBuffer = create_string_buffer('\000'*2048)

mybool = c_int(0)
param1 = c_int(0)
reserved0 = c_void_p(0)
reserved1 = c_void_p(0)

mydata = create_string_buffer("0x5a5a5a5a")
#userdata = c_long(0x5a5a5a5a) #failed
#userdata = byref(mydata) #failed
#userdata = pointer(mydata) #failed
userdata = c_void_p(0x5a5a5a5a) #failed


learnformat = c_int(0x0000)

port.UUIRTLearnIR(myhandle, learnformat, glearnBuffer, callback_func, userdata,
mybool,param1,reserved0, reserved1)


I tried to define userdata in different ways and all failed with "access violation
reading(writing) location...". The c routine just passes userdata to call back function and didn't
use it anywhere else.

Thanks!


Hi All,

I need to use this C routine in python and there is a void pointer parameter in it:
(this routine was written by someone else):

myfunc(int a, (void *)userdata, int b)

I saw someone in his C++ wrapper used this routine in this way:
myfunc(a, (void *)0x5a5a5a5a, b)

In my python wrapper, I tried to call it as the following and both failed:
1. myfunc(c_int(a), 0x5a5a5a5a, c_int(b))
got error "access voilation reading from 0x5a5a5a5a"
2.
data = 0x5a5a5a5a
mydata = c_void_p(data)
myfunc(c_int(a), mydata, c_int(b))
same error as in 1

Can anyone know how to fix it? Thanks!



__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com


__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
 
D

Dave Mandelin

First guess is that you are passing a Python function to something that
expects a C function. Try looking at gencb.py in DynWin.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top