1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| unit Shai_Header;
interface
uses ...
function ShaiFunction(const lpParam: TParamStruct): TResultStruct;
function AutreFunction(Truc: PChar): TResultStruct;
implementation
var
APIHandle: THandle = 0;
APIFunctions: record
_ShaiFunction: function(const lpParam: TParamStruct): TResultStruct; stdcall; // tu note _ !
_AutreFunction: function(Truc: PChar): TResultStruct; // j'en ai tout un tas ...
...
end;
// la fonction magique qui charge tout mes fonctions
procedure InitFunction(const FunctionName: string; var FunctionHandle: Pointer);
var
ModuleFileName: string;
begin
if FunctionHandle = nil then
begin
if APIHandle <= 0 then
begin
ModuleFileName := ExtractFilePath(WindowsEx.GetCurrentModuleFileName()) + '***.dll';
APIHandle := LoadLibrary(PChar(ModuleFileName));
end;
if APIHandle > 0 then
begin
FunctionHandle := GetProcAddress(APIHandle, PChar(FunctionName))
end
else
begin
raise EOleExceptionShai.Create(ERR_MAPPING_COM_API_NOT_FOUND);
end;
end;
if FunctionHandle = nil then
begin
raise EOleExceptionShai.Create(ERR_MAPPING_COM_API_FUNCTION_NOT_FOUND);
end;
end;
function ShaiFunction(const lpParam: TParamStruct): TResultStruct;
begin
InitFunction('ShaiFunction', @APIFunctions._ShaiFunction);
Result := APIFunctions._SearchPatient(lpParam);
end;
function AutreFunction(Truc: PChar): TResultStruct;
begin
InitFunction('AutreFunction', @APIFunctions._AutreFunction);
Result := APIFunctions._AutreFunction(Truc);
end; |