Einzelnen Beitrag anzeigen

barf00s
(Gast)

n/a Beiträge
 
#8

Re: procedure in dll auslagern

  Alt 6. Jul 2005, 11:58
wenn du die prozedurnamen kennst könntest du dir die LoadProcedureFromDll wie folgt umbauen

Delphi-Quellcode:
function InitDll(const sFileName: string): cardinal;
begin
  Result := LoadLibrary(sFileName);
end;

procedure FreeDll(iDll: cardinal);
begin
  FreeLibrary(iDll);
end;

procedure LoadProcedureFromDll(iDll: cardinal; const sProcedureName: string; var xProcedure: pointer);
begin
  xProcedure := GetProcAddress(iDll, sProcedureName);
end;

type
  TProcedureOne = procedure; stdcall;
  TProcedureTwo = procedure(iParam: integer); stdcall;

var
  hDll: cardinal;
  xProcedureOne: TProcedureOne;
  xProcedureTwo: TProcedureTwo;

procedure WireProcedures;
begin
  hDll := InitDll('myProcedures.dll');
  if iDll <> 0 then begin
    LoadProcedureFromDll(iDll, 'ProcedureOne', {@TProcedureOne(}xProcedureOne{)});
    LoadProcedureFromDll(iDll, 'ProcedureTwo', {@TProcedureTwo(}xProcedureTwo{)});
  end;
end;
  
procedure UnWireProcedure;
begin
  FreeDll(hDll);
  xProcedureOne := nil;
  xProcedureTwo := nil;
end;

procedure Test;
begin
  if Assigned({@}xProcedureOne) then
    xProcedureOne;
  if Assigned({@}xProcedureTwo) then
    xProcedureTwo(20);
end;
ich hoff ich hab jetz kein mist geschrieben
hab hier kein delphi zum testen.
  Mit Zitat antworten Zitat