Home > Blockchain >  Delphi: Windows service calling DLL method: access violation error
Delphi: Windows service calling DLL method: access violation error

Time:11-10

I have a Delphi Berlin Windows Service which will call a Delphi 11 DLL. This Delphi 11 DLL has REST API calls. I have used the following code to call the DLL method from my service:

function RESTAPICall(sURL, sDomain, sID, sJson: String;
    var slLog: TStringList) : Boolean; stdcall; External Restcall.dll' name 'RESTAPICall' delayed;

Then I call this DLL method in the OnTimer() event in the Windows Service. But it throws an access violation error during runtime:

Access violation at address 633381F4 in module 'Restcall.dll'. Read of address FFFFFFFC.

Also sometimes I get this AV error:

Access violation at address 21285195 in module 'borlndmm.dll'. Write of address 6347C370.

Please note this error occurs only during Service call, it works fine if I call the DLL from EXE.

CodePudding user response:

In simple words: you can't pass Strings or dynamic Arrays directly between application and DLL. You need to do one of the following:

  1. Use the same memory manager for application and DLL by including it as first unit via uses.
  2. Design you DLL functions to accept PChar, not String.

Note: I used FastMM in a lot of projects but I don't know if it is working with Delphi Alexandria.

  • Related