ctypes WindowsError:access violation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • trayres
    New Member
    • Sep 2009
    • 1

    ctypes WindowsError:access violation

    Hi all!
    I'm trying to use ctypes to access a function in a DLL. Here is the function prototype:
    extern "C" void__stdcall__ declspec(dllexp ort) ReturnPulse(dou ble*,double*,do uble*,double*,d ouble*);

    Here is the python code. It is really simple: I initialize each of the variables, then make a pointer to them.

    Python code:
    Code:
    FROGPCGPMonitorDLL = windll.LoadLibrary('C:\Program Files\MesaPhotonics\VideoFROG 7.0\PCGPMonitor.dll')
    
    #Function argument:double* pulse
    sizePULSE = 2 ##Manual is super unclear here
    pulse = c_double * sizePULSE
    ptrpulse = pulse()
    
    #Function argument:double* tdl
    sizeTRACE = FROGPCGPMonitorDLL.GetSize()
    if sizeTRACE == 0 :
        sizeTRACE = 1 #Manually set size to 1 for testing purposes
        print "Size of FROG trace is zero. Probably not right."
    tdl = c_double*sizeTRACE
    ptrtdl = tdl()
    
    
    #Function argument:double* tdP
    sizeTRACE = FROGPCGPMonitorDLL.GetSize()
    if sizeTRACE==0:
        sizeTRACE=1
        print "Size of FROG trace is zero. Probably not right."
    tdP = c_double*sizeTRACE
    ptrtdP = tdP()
    
    
    #Function Argument:double* fdl
    sizeTRACE = FROGPCGPMonitorDLL.GetSize()
    if sizeTRACE==0:
        sizeTRACE=1
        print "Size of FROG trace is zero. Probably not right."
    fdl = c_double*sizeTRACE
    ptrfdl = fdl()
    
    #Function Argument: double* fdP
    sizeTRACE = FROGPCGPMonitorDLL.GetSize()
    if sizeTRACE==0:
        sizeTRACE=1
        print "Size of FROG trace is zero. Probably not right."
    fdP = c_double*sizeTRACE
    ptrfdP = fdP()
    
    #Use the function
    FROGPCGPMonitorDLL.ReturnPulse(ptrpulse, ptrtdl, ptrtdP,ptrfdl,ptrfdP)
    If anyone is interested, the C function is for a DLL to control the Mesa Photonics VideoFROG. The manual is here:

    Page 68 (appendix C) and page 69 contain the function prototype and the description of the function. I'm pretty sure GetSize() is working, so that eliminates one potential error point.

    The error I get, when I call the function, is:
    WindowsError: exception: access violation writing 0x00001001

    I'm beginning to come to my wit's end with this problem. Any and all help or guidance of any kind is greatly appreciated!!
    Thanks all!
    Last edited by bvdet; Sep 9 '09, 12:59 PM. Reason: Add code tags
Working...