470,849 Members | 1,314 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

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

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)


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.

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"
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

Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
Mar 30 '06 #1
1 2141
First guess is that you are passing a Python function to something that
expects a C function. Try looking at gencb.py in DynWin.

Want to play tabletop RPGs over the internet?
Check out Koboldsoft RPZen: http://www.koboldsoft.com

Mar 30 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Toufik | last post: by
3 posts views Thread by Scott McDermott | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.