Einzelnen Beitrag anzeigen

Nuclear-Ping
(Gast)

n/a Beiträge
 
#3

Re: DLL dynamisch laden/ Verwendung in Kompo zur Designzeit

  Alt 14. Sep 2007, 08:02
Du musst in der DLL zuerst die Funktionen unter "exports" aufführen, die du exportieren willst.

Dann erstellst du (ich glaube das heisst so ^^) Prototypen von diesen exportieren Funktionen und weisst diese entsprechenden Variablen zu. Im konkreten sieht das z.B. so aus:
Delphi-Quellcode:
type
  TGetPluginVersion = function: Integer; stdcall;
  TGetPluginAuthor = function: PChar; stdcall;

  TCreateChild = procedure (ModuleConfiguration: TModuleConfiguration);
  {...}

  TModulePlugin = class
    {...}
  public
    GetPluginVersion: TGetPluginVersion;
    GetPluginAuthor: TGetPluginAuthor;
    CreateChild: TCreateChild;
    {...}
  end;
Dann lädst du die DLL und importierst die Funktionen mit GetProcAddress.
Delphi-Quellcode:
  Handle := LoadLibrary (APluginFileName);
  if (Handle = 0) then
    raise Exception.Create ('TModulePlugin.Create: LoadLibrary failed to load Plugin Module' + #13#10#13#10 +
                            APluginFileName);

  CreateChild := GetProcAddress (Handle, 'CreateChild');
  if @CreateChild = nil then
    raise Exception.Create ('TModulePlugin.Create: Function "CreateChild" not found in Plugin Module');

  GetPluginVersion := GetProcAddress (Handle, 'GetPluginVersion');
  if @GetPluginVersion = nil then
    raise Exception.Create ('TModulePlugin.Create: Function "GetPluginVersion" not found in Plugin');

  {...}
Sollte helfen, oder?
  Mit Zitat antworten Zitat