[SOLVED] Delphi DLL called from Lazarus EXE lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- DanishMale · 2023-04-03 18:29 Hi all, I have a DLL created in Delphi and works perfectly with a Delphi EXE, however with a Lazarus EXE I get this error: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i External exception EEDFADE The test is done on Win10 x64, Lazarus Exe by v2.2.24 x64 and the DLL by Delphi CE 10.4 x64 HTTP protocol is HTTP/2 the external function is defined like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function GetExtWEB2(URLstr: PChar): PChar; stdcall; external 'HTTP2.dll'; the expected result is something like this Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {"translations":[{"detected_source_language":"EN","text":"Dette er en testlinje for at se, om det virker"}]} and I call the DLL like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i       try       Result := String(GetExtWEB2(PChar('https://api-free.deepl.com/v2 /translate?auth_key=00000000-0000-0000-0000- 000000000000:00&text='+HTTPencode(OrgStr)+'&source_lang='+Sprog+'&targ et_lang=DA')));      except        on E: Exception do        begin        Result := 'Get Translation - '+E.Message;        end;      end;  Any one got an idea to get these items to do as wanted ??? Help really appriciated ---------------------------------------------------------------------- balazsszekely · 2023-04-03 18:52 IIRC since Delphi 2009, PChar defines a pointer to a memory location that contains WideChar values.  Did you try PWideChar instead of PChar in your Lazarus executable? ---------------------------------------------------------------------- ojz0r · 2023-04-03 18:56 Maybe if you try using it as a dynamic library? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  ...  dynlibs; type TGetExtWEB2 = function(URLstr: PChar): PChar; var  GetExtWEB2: TGetExtWEB2;  Lib: TLibHandle; begin  Lib := LoadLibrary(GetCurrentDir + '\' +  'HTTP2.dll');  if Lib = 0 then exit;  GetExtWEB2 := TGetExtWEB2(GetProcedureAddress(Lib, 'GetExtWEB2'));  ...end. ---------------------------------------------------------------------- gidesa · 2023-04-03 19:42 Hello, you has to be sure that also Delphi DLL use stdcall convention, as in FPC signature. And, as pointed, that PChar in FPC and Delphi are the same, PAnsichar or PWidechar. Delphi 10 by default use PChar = PWidechar. FPC don't know. ---------------------------------------------------------------------- DanishMale · 2023-04-03 19:50 @GetMem and @ojz0r  ...  I have tried both your suggestions neither of them changes the result...  :'( @gidesa ... I have tried with and with out stdcall and various string variations ---------------------------------------------------------------------- KodeZwerg · 2023-04-03 20:30 Maybe by properly casting everything like it is expected? Maybe let in your delphi dll print somewhere what you get as input etc... Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function GetExtWEB2(URLstr: PWideChar): PWideChar; stdcall; external 'HTTP2.dll';      try         // just a try to bring your current input into a good WideString         WideString1 := WideString('https://api-free.deepl.com/v2/translate?auth_key=00000000- 0000-0000-0000-000000000000:00&text=') + WideString(HTTPencode(OrgStr)) + WideString('&source_lang=') + WideString(Sprog) + WideString('&target_lang=DA');         Result := AnsiString(GetExtWEB2(PWideChar(WideString1));      except        on E: Exception do        begin          Result := 'Get Translation - '+E.Message;        end;      end; ---------------------------------------------------------------------- Ozz_Nixon · 2023-04-04 03:00 Not sure if this helps... but the address of EEDFADE is built-in to Delphi's SYSTEM.PAS: See Article: https://marc.durdin.net/2012/05/windbg-and-delphi-exceptions-in-x64/ ---------------------------------------------------------------------- gidesa · 2023-04-04 06:57 In Delphi 10 help I read: QuoteCalling convention: When you declare a procedure or function, you can specify a calling convention using one of the directives register, pascal, cdecl, stdcall, safecall, and winapi. For example, ...... The default calling convention is register. Then, if you don't specify a convention in Delphi DLL,  probably in FPC signature have to use register convention, if FPC has it. Or you have to modify Delphi DLL using one of conventions recognized from FPC (I am sure cdecl is). ---------------------------------------------------------------------- DanishMale · 2023-04-04 14:11 @gidesa -- thanks for pointing me in the right direction The solution was this was missing in the DLL: {$ifdef win32} Stdcall;{$endif} Export; THANKS TO ALL for their help and suggestions ---------------------------------------------------------------------- gidesa · 2023-04-04 16:11 Great! You are welcome.