Hi
I'm struggling to find the answer because I'm not sure what terminologies to use! I did find this and have read it (
https://www.freepascal.org/docs-html/prog/progse55.html)
Basically :
There is a software tool that makes it's own API accessible via a pas file (it supports C, Python, Delphi and Pascal languages) and they have several Delphi demo projects.
I have taken one of the demo projects and converted it to a Lazarus library using Lazarus. The result is library project and there are several functions in that. Lets assume it is called MyLibrary. At the end of the library file is an exports section where each function is exported by name. When compiling in Lazarus, a DLL is produced. When I use the internal mechanisms of the software to call this DLL plugin called MyLibrary.dll, it works fine.
It looks a bit like this :
library MyLibrary
{$MODE Delphi}
uses TheAPI, LCLIntf, LCLType, Windows, strings, sysutils;
function Example1(Parameters....) : LongInt :stdcall; export;
begin
// does stuff, and calls things from TheAPI.pas
end;
function Example2(Parameters....) : LongInt :stdcall; export;
begin
// does stuff, and calls things from TheAPI.pas
end;
function Example3(Parameters....) : LongInt :stdcall; export;
begin
// does stuff, and calls things from TheAPI.pas
end;
function Example4(Parameters....) : LongInt :stdcall; export;
begin
// does stuff, and calls things from TheAPI.pas
end;
exports
Example1,
Example2,
Example3,
Example4;
end.
Compiled result is MyLibrary.dll
What I want to do next is build an interface so that the user can pass some preferred parameters to the functions such as Example1 and Example2 in the DLL instead of it just doing things that I have hard coded into it. I know this can be done with the API because other plugins for this tool have their own interfaces which appear when the calling program executes the DLL so that the user can pass options to it.
However, I am totally unclear how I create a new application with a new form and some buttons that can then call the functions of this API based DLL or MyLibrary file. How do I link form1 and unit1.pas to the DLL, or better still, the MyLibrary pas file so that all the functions in my library file (and ergo the DLL) are accessible from the form? I have tried just adding the name of it (MyLibrary) to the uses of unit.pas but that is not working.
I have done something similar in the past (calling a DLL from my program) but in that case I did not have the source code to the DLL...only the name of the functions that I could call from it. So I used
if FileExists(SomeDLL.dll) then
begin
@SomeValue1 := GetProcAddress(THandle, 'Function1');
@SomeValue2 := GetProcAddress(THandle, 'Function2');
@SomeValue3 := GetProcAddress(THandle, 'Function3');
end;
But in my case, I do have the functions, in MyLibrary file. So I don't think I need to link to the DLL directly. I just want my application and unit to be able to utilise the functions in MyLibrary and have it all wrapped up together at compile time as a single DLL plugin that can be called from the parent program that they are designed to work with