working with python cdll windows dll got an memory exception

0

I receive this error when I try to call this function written in Delphi. But another code works fine. Maybe I'm not declaring the args ans result types? I am using 32Bit python 3.7). Related code snippets:

Delphi:

Test(deposit, MarginCall: double; CallBack: TProgrCallBackProc); stdcall;

Python:

self.FTCore = ctypes.WinDLL(self.FTCore_library_path)
self.FTCore.Test.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double)]
self.FTCore.Test.restype = ctypes.POINTER(ctypes.c_char)
deposit = ctypes.c_double(100)
callback = ctypes.c_double(1)
self.FTCore.Test(deposit, callback)

Error:

violation reading 0x00000004
python
delphi
asked on Stack Overflow Feb 11, 2020 by Evgeniya Smirnova • edited Feb 11, 2020 by Tonechas

1 Answer

3

Three errors that I can see:

  1. The Delphi function accepts three arguments, you define only two in argtypes. You will need to define the third argument, TProgrCallBackProc defined somewhere in the Delphi code.
  2. The two double parameters are passed by value, but you define them as pointers to double in your argtypes definition. They should be defined as plain ctypes.c_double.
  3. The Delphi function has no return value, but your restype contradicts that. You need to set restype to None.
answered on Stack Overflow Feb 11, 2020 by David Heffernan • edited Feb 11, 2020 by David Heffernan

User contributions licensed under CC BY-SA 3.0