Hi there,
I have an application that sometimes makes use of a DLL, but usually
doesn't. Therefore I'd like to load the DLL only if required.
However, instead of coding a LoadLibrary/GetProcAddress - FreeLibrary around
each call of a function in the DLL, I had the idea to leave the
application's code as is and only change the interface-unit that links to
the DLL as follows:
type TCallFoo = Function(I: integer): integer; stdcall; // Prototype of the
function in the DLL
var HLib: THandle = 0;
Function Foo: TCallFoo;
begin
if HLib = 0 then HLib := LoadLibrary(...);
Result := GetProcAddress(HLib,...);
end;
So far, so good. But in my application when I have the code
var I: integer;
...
I := Foo(5);
I get two error messages. The first one says "Too many parameters", as Foo
doesn't require any parameters. The second one is "Type mismatch: integer
and TCallFoo", because the type of the result of Foo is TCallFoo and not
integer. Of course my intention is to call the result of Foo (which is the
address 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?
Thanks!
Gunnar
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi