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

Discussion in 'Python' started by Yanping Zhang, Mar 30, 2006.

  1. 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!



    __________________________________________________
    Do You Yahoo!?
    Tired of spam? Yahoo! Mail has the best spam protection around
    http://mail.yahoo.com
     
    Yanping Zhang, Mar 30, 2006
    #1
    1. Advertisements

  2. First guess is that you are passing a Python function to something that
    expects a C function. Try looking at gencb.py in DynWin.
     
    Dave Mandelin, Mar 30, 2006
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.