hi, ich versuche in meinem programm eine
dll dynamisch zu laden und ihr eine info zu entlocken. Ich poste hier einfach mal den code:
Hier wird die
DLL geladen und die funktion ausgeführt:
Delphi-Quellcode:
function TForm1.GetPluginInfo (Name : PChar; Plugin : String) : PChar;
type
TDLLFunc = function():PChar;
var
DLLHandle : THandle;
Ret : PChar;
func : TDllFunc;
begin
Ret := '';
DLLHandle := LoadLibrary (PChar(ExtractFilePath (Application.ExeName) + 'Plugins\' + Plugin + '.dll'));
if DLLHandle >= 32 then
begin
@func := GetProcAddress (DLLHandle, Name);
if Assigned (func) then Ret := func();
FreeLibrary (DLLHandle);
end;
result := Ret;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage (String (GetPluginInfo ('GetButtonFunc', 'winamp')));
end;
Hier ist der code der
dll:
Delphi-Quellcode:
library winamp;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
Classes;
{$R *.res}
function GetButtonFunc():PChar;
export;
begin
result := PChar('
Play|Pause|Stop|Start|Close|ToggleShuffle|ToggleRepeat|NextTrack|PreviousTrack|Volume');
end;
exports
GetButtonFunc;
begin
end.
Das problem ist das ich eine
Access violation bekomme.
Mittlerweile hab ich rausbekommen das es an FreeLibrary liegt, wenn ichs weglasse tut alles wunnerbar.
mfG