Dll
12/05/2003
0
E ai galera...
Eu tava afim de usar uma dll no meu programa, só que, não quero carregar ela desde a inicialização do programa, e sim, só quando eu precisasse dela,(por ex, puxar uma função que faz calculos)...Alguem tem idéia de como faço isso?
Eu tava afim de usar uma dll no meu programa, só que, não quero carregar ela desde a inicialização do programa, e sim, só quando eu precisasse dela,(por ex, puxar uma função que faz calculos)...Alguem tem idéia de como faço isso?
Petrified Eyes
Curtir tópico
+ 0
Responder
Posts
12/05/2003
Rafael Heise
Sim ....
You can access routines in a DLL through direct calls to Windows library functions, including LoadLibrary, FreeLibrary, and GetProcAddress (all declared in Delphi’s Windows unit). In this case, use procedural-type variables to reference the imported routines. For example,
uses Windows, ...;
type
TTimeRec = record
Second: Integer;
Minute: Integer;
Hour: Integer;
end;
TGetTime = procedure(var Time: TTimeRec);
THandle = Integer;
var
Time: TTimeRec;
Handle: THandle;
GetTime: TGetTime;
...
begin
Handle := LoadLibrary(´DATETIME.DLL´);
if Handle <> 0 then
begin
@GetTime := GetProcAddress(Handle, ´GetTime´);
if @GetTime <> nil then
begin
GetTime(Time);
with Time do
WriteLn(´The time is ´, Hour, ´:´, Minute, ´:´, Second);
end;
FreeLibrary(Handle);
end;
end;
When you import routines this way, the DLL is not loaded until the code containing the call to LoadLibrary executes. The DLL is later unloaded by the call to FreeLibrary. This allows you to conserve memory, and to run your program even when some of the DLLs it uses are not present.
(Retirado do Help do Delphi) !!!!
se você observar um pouquinho entenderá o exemplo .....
abraços..
You can access routines in a DLL through direct calls to Windows library functions, including LoadLibrary, FreeLibrary, and GetProcAddress (all declared in Delphi’s Windows unit). In this case, use procedural-type variables to reference the imported routines. For example,
uses Windows, ...;
type
TTimeRec = record
Second: Integer;
Minute: Integer;
Hour: Integer;
end;
TGetTime = procedure(var Time: TTimeRec);
THandle = Integer;
var
Time: TTimeRec;
Handle: THandle;
GetTime: TGetTime;
...
begin
Handle := LoadLibrary(´DATETIME.DLL´);
if Handle <> 0 then
begin
@GetTime := GetProcAddress(Handle, ´GetTime´);
if @GetTime <> nil then
begin
GetTime(Time);
with Time do
WriteLn(´The time is ´, Hour, ´:´, Minute, ´:´, Second);
end;
FreeLibrary(Handle);
end;
end;
When you import routines this way, the DLL is not loaded until the code containing the call to LoadLibrary executes. The DLL is later unloaded by the call to FreeLibrary. This allows you to conserve memory, and to run your program even when some of the DLLs it uses are not present.
(Retirado do Help do Delphi) !!!!
se você observar um pouquinho entenderá o exemplo .....
abraços..
Responder
Clique aqui para fazer login e interagir na Comunidade :)