At 10:00 AM 7/28/2007, Gunnar Blumert wrote:
>type TCallFoo = Function(I: integer): integer; stdcall; // Prototype of the
>function in the DLL
>
>The only way I could find that works is
>
>var I: integer;
> CallFoo: TCallFoo;
>...
> CallFoo := Foo;
> I := CallFoo(5);
>
>In other words, I had to change the code of my application again. Is there a
>way to avoid the variable CallFoo?
I would do this:
Make your Foo function itself (not the returned result) have the signature
of TCallFoo. Then just call Foo(5) like you have already done. The new Foo
function would then look something like
type
TCallFoo = Function(I: integer): integer; stdcall;
Function Foo(I: Integer): Integer;
const
HLib: THandle = 0;
var
RealFoo: TCallFoo
begin
if HLib = 0 then
HLib := LoadLibrary(...);
RealFoo := GetProcAddress(HLib,...);
Result := RealFoo(I);
end;
and the program call go back to doing
var I: integer;
...
I := Foo(5);
which calls the wrapper Foo that automatically encapsulates the tracking of
whether the DLL was loaded.
All that remains is a way to unload the DLL if you need to do that explicitly.
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi