Jump to content
Anna Blanca

How use LoadLibrary in FMX?

Recommended Posts

Hello. How i can use LoadLibrary in FMX, on the not-Windows platforms? When i try wright 'LoadLibrary' in FMX-project, it emphasized by red. That is, FMX not supporting this function. It's working, when i connected WinAPI, but i want use dynamic connect for dynamic libraryes, not on the Windows. 

Share this post


Link to post

LoadLibrary() is a Win32 API function, so it is only available on Windows, you CAN'T use it on other platforms.

 

That being said, other platforms have their own equivalents. For example, 'Nix-based platforms (which includes OSX, iOS, Linux, and Android) have dlopen() instead.

 

You are going to have to use the appropriate API for each platform you want to support.

Edited by Remy Lebeau

Share this post


Link to post
7 hours ago, Anna Blanca said:

How i can use LoadLibrary in FMX, on the not-Windows platforms?

For Posix systems (Android, iOS, macOS, Linux) use LoadLibrary from System.SysUtils - it wraps dlopen, which Remy mentioned.

  • Like 1

Share this post


Link to post
Just now, Remy Lebeau said:

Do you mean SafeLoadLibrary()?

The OP asked about LoadLibrary, so I referred to LoadLibrary. The documentation does not list it, but it's there.

Share this post


Link to post
17 hours ago, Dave Nottage said:

For Posix systems (Android, iOS, macOS, Linux) use LoadLibrary from System.SysUtils - it wraps dlopen, which Remy mentioned.

Thank you, that's works. Normal compile. Truly, when i'm writing next code:

procedure TForm1.Button1Click(Sender: TObject);
var
I : Integer;
SoName : THandle;
ExportFunc : function(X, Y : Integer) : Integer;
begin
SoName := LoadLibrary('/storage/emulated/0/Documents/libTestLibrary.so');
if SoName <> 0 then
begin
ExportFunc := GetProcAddress(SoName, 'Launch');
I := ExportFunc(3, 5);
Label1.Text := IntToStr(I);
end;
end;

Nothing not happens....Even when i writed wrong library name, app not fired out with error. 

Edited by Anna Blanca

Share this post


Link to post
Just now, Anna Blanca said:

Nothing not happens....Even i writed wrong library name, app not fired out with error. 

I expect there will be a permissions error in the system logs (which you can view using a log viewer), unless you are using an earlier version of Android and have requested the relevant permissions. On Android 11 or higher, I doubt you'll make LoadLibrary work at all using that path. Is there some reason you are not deploying libTestLibrary.so with the application? 

Share this post


Link to post
11 minutes ago, Dave Nottage said:

Is there some reason you are not deploying libTestLibrary.so with the application? 

I need to launch so-library not at once, but after any time. Maybe, my app will download library from the Internet, it new version will be released.... 

 

In actualy, is Android a new iOS?

Edited by Anna Blanca

Share this post


Link to post
5 minutes ago, Anna Blanca said:

I need to launch so-library not at once, but after any time. Maybe, my app will download library from the Internet, it new version will be released.... 

If your app itself is downloading it, it won't need to go in a shared folder (which is what /storage/emulated/0/Documents is). The app could download it to a subfolder of the internal documents folder, e.g. a folder like this:

LLibFolder := TPath.Combine(TPath.GetDocumentsPath, 'Lib');
ForceDirectories(LLibFolder);
LLibFileName := TPath.Combine(LLibFolder, 'libTestLibrary.so');

Your download routine could then download the file to the filename specified by LLibFileName, and call LoadLibrary using the same path.

11 minutes ago, Anna Blanca said:

In actualy, is Android a new iOS?

Android and iOS are two very different operating systems.

Share this post


Link to post
10 minutes ago, Dave Nottage said:

If your app itself is downloading it, it won't need to go in a shared folder (which is what /storage/emulated/0/Documents is). The app could download it to a subfolder of the internal documents folder, e.g. a folder like this:

O'K, thanks, but its not solved my problem - LoadLibrary not loading my library. You solution is only for simplification directly downloading from server.

Share this post


Link to post

 

51 minutes ago, Dave Nottage said:

Android and iOS are two very different operating systems.

So, how can i use dynamic loading of librarys in Android 14?

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×