0

Good Day,

I'm trying to implement a device dll to later enable me to automate scanning measurements using a python script. Currently I'm Struggling with calling the required functions from the DLL receiving the error:

OSError: exception: access violation reading 0x00000000571E89E1

The code I am trying to use is:

import ctypes as ct

p517 = ct.cdll.LoadLibrary("PI_GCS2_DLL_x64.dll")
p517.PI_InterfaceSetupDlg.restype = ct.c_int
p517.PI_InterfaceSetupDlg.argtype = ct.c_char_p
p517.PI_InterfaceSetupDlg()

I'm new to working with C in Python but looking at the relevant function in the DLL:

int PI_InterfaceSetupDlg (const char* szRegKeyName)
Open dialog to let user select the interface and create a new PI object. All future calls to control this controller need the ID returned by this call. See Interface Settings (p. 19) for a detailed description of the dialogs shown.
Arguments: szRegKeyName key in the Windows registry in which to store the settings, the key used is "HKEY_LOCAL_MACHINE\SOFTWARE<your keyname>" if keyname is NULL or "" the default key "HKEY_LOCAL_MACHINE\SOFTWARE\PI\PI_GCS2_DLL" is used.
Returns: ID of new object, -1 if user pressed "CANCEL", the interface could not be opened, or no controller is responding.

I thought I had defined the argtype and restype correctly, but most of the problems similar to this seem to have been caused by false type definition. Am I missing something here? Thanks in advance for any advice

  • 1
    The attribute is "argtype**s**" and expects a list of types. – Michael Butscher Jul 01 '20 at 16:13
  • Ah, okay then, my misunderstanding was that I thought if I only had a single argument, it would be a different command, as the argtypes command previously didn't work for me. Tested it now and it works, thank you! – PH_Braves Jul 02 '20 at 08:51
  • This is a duplicate of https://stackoverflow.com/questions/58610333/c-function-called-from-python-via-ctypes-returns-incorrect-value/58611011#58611011. Follow the instructions there, and let us know about the result. – CristiFati Jul 02 '20 at 10:35

0 Answers0