Using CT 7.8 x64 On Windows 11 x64 with all updates applied.
Also tested using CT 7.8 x64 on Windows 10 x64 with all updates applied.
Using x64 code with x64 DLLs.
I am am uploading a zip file of the project and I tried to leave all the stuff out that you don't need to test such as backup files, etc...
Okay, I am attempting to write a unit to use shared library on Windows (DLL) What I believe is referred to as Early Binding works, but I wanted to try what I believe is referred to Late Binding using LoadLibrary and GetProcedureAddrss and I can't get that to work.
Here is my example code.
Unit uDynamicLoad;
{$mode objFPC}{$H+}
{$DEFINE LOAD_DYNAMIC} // when this is defined the code doesn't work.
Interface
Uses
Classes,
SysUtils;
Const
TESSERACT_LIBRARY = 'tesseract41.dll';
LAME_LIBRARY = 'libmp3lame.dll';
INVALID_HANDLE_VALUE = THANDLE(-1);
{$IFDEF LOAD_DYNAMIC}
Type
TFnTessVersion = Function: PChar; Cdecl;
TFnGetLameVersion = Function: PChar; Cdecl;
TFnGetLameUrl = Function: PChar; Cdecl;
Var
TessVersion : TFnTessVersion;
get_lame_version : TFnGetLameVersion;
get_lame_Url : TFnGetLameUrl;
{$ELSE}
/// This works just fine...
Function TessVersion : pChar; cdecl; external TESSERACT_LIBRARY name 'TessVersion';
function get_lame_version : pChar; cdecl; external LAME_LIBRARY name 'get_lame_version';
function get_lame_url : pChar; cdecl; external LAME_LIBRARY name 'get_lame_url';
{$ENDIF}
Implementation
{$IFDEF LOAD_DYNAMIC}
Var
hTesseract : TLibHandle;
hLame : TLibHandle;
Function IsValidHandle(Const AHandle: THandle): Boolean;
Begin
Result := (AHandle <> 0) And (AHandle <> INVALID_HANDLE_VALUE);
End;
Procedure LoadTesseract;
Begin
TessVersion := Nil;
hTesseract := LoadLibrary(TESSERACT_LIBRARY);
If IsValidHandle(hTesseract) Then
Begin
/// the variable for TessVersion doesn't appear to be assigned the value correctly or I am not assigning the value correctly as this doesn't work
TessVersion := TFnTessVersion(GetProcedureAddress(hTesseract, 'TessVersion'));
// Pointer(TessVersion) := GetProcedureAddress(hTesseract, 'TessVersion');
End;
End;
Procedure UnLoadTesseract;
Begin
If IsValidHandle(hTesseract) Then
Begin
UnLoadLibrary(hTesseract);
End;
End;
Procedure LoadLame;
Begin
get_lame_version := Nil;
get_lame_url := Nil;
hLame := LoadLibrary(LAME_LIBRARY);
If IsValidHandle(hLame) Then
Begin
/// Same here. These don't work.
get_lame_version := TFnGetLameVersion(GetProcedureAddress(hLame, 'get_lame_version'));
get_lame_url := TFnGetLameUrl(GetProcedureAddress(hLame, 'get_lame_url'));
End;
End;
Procedure UnLoadLame;
Begin
If IsValidHandle(hLame) Then
Begin
UnLoadLibrary(hLame);
End;
End;
Initialization
LoadTesseract;
LoadLame;
Finalization
UnLoadLame;
UnLoadTesseract;
{$ENDIF}
End.
in my main using I try something like:
memo1.Lines.Add('Tesseract Version: %s', [ String( TessVersion )]);
memo1.Lines.Add('Lame Version: %s', [ String( get_lame_version) ]);
memo1.Lines.Add('Lame URL: %s', [ String( get_lame_url) ]);
Thanks
Robert
ps. I used vcpkg, which is on git hub, to download and build the DLLs.