You need two separate projects, one for the DLL itself, and one for the project that uses the DLL.
In the DLL project, you use exports
, eg:
library my;
uses
Shellapi;
{$R *.res}
procedure ExecuteFile(FileName: WideString); stdcall;
begin
ShellExecuteW(0, nil, PWideChar(FileName), nil, nil, SW_NORMAL);
end;
exports
ExecuteFile;
begin
end.
Then, in the consuming project, you use an external
declaration to import the function from the DLL, eg:
procedure ExecuteFile(FileName: WideString); stdcall; external 'my.dll';
Then the project can call ExecuteFile()
like any other function, eg:
ExecuteFile('filename');
Just make sure the exporting DLL is:
located somewhere on the OS's search path, preferably in the same folder as the consuming app.
compiled to use the same bitness (32bit or 64bit) as the consuming project.
Otherwise, it won't load correctly.