Recent

Author Topic: Access Violation When Function Reaches END;  (Read 8088 times)

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1584
    • Lebeau Software
Re: Access Violation When Function Reaches END;
« Reply #30 on: March 16, 2021, 05:28:43 pm »
isn't there Somewhere an Example to how to use ZAJsonRequestW ? :o

Try this:

Code: Pascal  [Select][+][-]
  1. //Def
  2. TZAJsonRequestW = function(sRequest : PWideChar): PWideChar; stdcall;
  3.  
  4. //Calling The DLL
  5. Function Call_ZAJsonRequestW(const sRequest : UnicodeString): UnicodeString;
  6. var
  7.   // Legt eine passende Variable (Datenfeld) für das DLL-Unterprogramm an
  8.   ZAJsonRequestW : TZAJsonRequestW;
  9.   // Legt einen Handle für den Handle der DLL an
  10.   LibHandle: THandle;
  11. begin
  12.   Result := '';
  13.   //Einbinden Der DLL
  14.   LibHandle := LoadLibrary(PChar('C:\DLLS\FANselect.dll'));
  15.   if (LibHandle <> 0) then
  16.   try
  17.     // Weisst der Variablen ZAJsonRequestW die Adresse des Unterprogrammaufrufs zu
  18.     // 'ZAJsonRequestW' aus der DLL FANSelect.dll zu.
  19.     Pointer(ZAJsonRequestW) := GetProcAddress(LibHandle, 'ZAJsonRequestW');
  20.  
  21.     // Prüft, ob eine gültige Adresse zurück gegeben wurde
  22.     if Assigned(ZAJsonRequestW) then begin
  23.       //Blackbox aufrufen
  24.       Result := ZAJsonRequestW(PWideChar(sRequest));
  25.     end;
  26.   finally
  27.     FreeLibrary(LibHandle);
  28.   end;
  29. end;
  30.  
  31. //Calling in Code
  32. //Both Strings Here are UnicodeStrings
  33. JZaRueckgabe := DLLAufrufe.Call_ZAJsonRequestW(JZa);

Alternatively:

Code: Pascal  [Select][+][-]
  1. //Def
  2. TZAJsonRequestW = function(sRequest : PWideChar): PWideChar; stdcall;
  3.  
  4. //Calling The DLL
  5. Function Call_ZAJsonRequestW(const sRequest : UTF8String): UTF8String;
  6. var
  7.   // Legt eine passende Variable (Datenfeld) für das DLL-Unterprogramm an
  8.   ZAJsonRequestW : TZAJsonRequestW;
  9.   // Legt einen Handle für den Handle der DLL an
  10.   LibHandle: THandle;
  11. begin
  12.   Result := '';
  13.   //Einbinden Der DLL
  14.   LibHandle := LoadLibrary(PChar('C:\DLLS\FANselect.dll'));
  15.   if (LibHandle <> 0) then
  16.   try
  17.     // Weisst der Variablen ZAJsonRequestW die Adresse des Unterprogrammaufrufs zu
  18.     // 'ZAJsonRequestW' aus der DLL FANSelect.dll zu.
  19.     Pointer(ZAJsonRequestW) := GetProcAddress(LibHandle, 'ZAJsonRequestW');
  20.  
  21.     // Prüft, ob eine gültige Adresse zurück gegeben wurde
  22.     if Assigned(ZAJsonRequestW) then begin
  23.       //Blackbox aufrufen
  24.       Result := UTF8Encode(ZAJsonRequestW(PWideChar(UTF8Decode(sRequest))));
  25.     end;
  26.   finally
  27.     FreeLibrary(LibHandle);
  28.   end;
  29. end;
  30.  
  31. //Calling in Code
  32. //Both Strings Here are UTF8Strings
  33. JZaRueckgabe := DLLAufrufe.Call_ZAJsonRequestW(JZa);
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 881
Re: Access Violation When Function Reaches END;
« Reply #31 on: March 16, 2021, 07:53:21 pm »
Thanks Guys :)

It Did work with The Pointers. Not The Result i wanted but atleast i dont get AV Anymore.

Thanks again for ur effort and patience.
BSTR variant need extensive testing with asm debugger. But I don't have time to do it and don't want to mess with some libraries, I'm unfamiliar with. Sometimes only asm debugging can fix problem. For example one of hardest tasks for me was - to use 7z.so in my Lazarus project. It had taken so much time to realize, what kind of strings are used there.
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

Weitentaaal

  • Hero Member
  • *****
  • Posts: 554
Re: Access Violation When Function Reaches END;
« Reply #32 on: March 17, 2021, 08:19:19 am »
Thanks Guys :)

It Did work with The Pointers. Not The Result i wanted but atleast i dont get AV Anymore.

Thanks again for ur effort and patience.
BSTR variant need extensive testing with asm debugger. But I don't have time to do it and don't want to mess with some libraries, I'm unfamiliar with. Sometimes only asm debugging can fix problem. For example one of hardest tasks for me was - to use 7z.so in my Lazarus project. It had taken so much time to realize, what kind of strings are used there.

100 % Agree on that... we never looked that detailed into "Strings" in Shool (finished Shool last year)... first expreience with Strings like that.

 

TinyPortal © 2005-2018