thank you Blestan
i did not succeed in the 3rd issue.
to make the dll generic i picked the shell32.dll from Windows in order to interrogate for the DLL version information as per:
https://msdn.microsoft.com/en-us/library/windows/desktop/bb776404(v=vs.85).aspx and
https://msdn.microsoft.com/en-us/library/windows/desktop/bb773263(v=vs.85).aspx . althouth there is version 2 of structure i understood the DllGetVersion is backward compatible and would return a structure like the below:
typedef struct _DllVersionInfo {
DWORD cbSize;
DWORD dwMajorVersion;
DWORD dwMinorVersion;
DWORD dwBuildNumber;
DWORD dwPlatformID;
} DLLVERSIONINFO;
so what i did i mapped the returning structure to a record type - TVersionInfoRecord .
i defined the entry point in the DLL but the question that arises is how do i get access to the record member values?
something like v.cbSize would return an error with 'Error: illegal qualifier . found'. so in this case how do i create a record from the function call result?
thank you!
program learn_dlls;
{$mode objfpc}{$H+}
uses
Classes,
SysUtils,
CustApp,
CTypes,
dynlibs;
type
TWorkDLL = class(TCustomApplication)
protected
procedure DoRun; override;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
end;
type
TVersionInfoRecord = record
cbSize: word;
dwMajorVersion: word;
dwMinorVersion: word;
DdwBuildNumber: word;
dwPlatformID: word;
end;
type
TLibVersion = function: TVersionInfoRecord; stdcall;
procedure TWorkDLL.DoRun;
var
DLLInstance: THandle;
v: TLibVersion;
i: TVersionInfoRecord;
begin
try
try
DLLInstance := SafeLoadLibrary('C:\Windows\System32\shell32.dll');
if DLLInstance <> NilHandle then
begin
v := TLibVersion(GetProcedureAddress(DLLInstance, 'DllGetVersion'));
if @v <> nil then
begin
i:= @v; //how do i create a record from the function call result?
end;
end
else
writeln('there was an error');
finally
FreeLibrary(DLLInstance);
end;
except
on E: Exception do
begin
writeln('error: ' + E.Message);
end;
end;
Terminate;
end;
constructor TWorkDLL.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
StopOnException := True;
end;
destructor TWorkDLL.Destroy;
begin
inherited Destroy;
end;
var
Application: TWorkDLL;
begin
Application := TWorkDLL.Create(nil);
Application.Title := 'Test_DLL';
Application.Run;
Application.Free;
end.