[Tutorial] Como utilizar uma DLL
:: Programação :: Delphi :: Delphi Tutoriais.
Página 1 de 1 • Compartilhe •
[Tutorial] Como utilizar uma DLL
Como utilizar uma DLL?
Estetópico ensinará como criar uma DLL- biblioteca de ligação dinâmica.
Procedimentos a serem executados:
ü File -> CloseAll
ü File->New->Other->DLL Wizard
ü Apagueo comentário após a linha LibraryProject2;
ü Digiteas funções que farão parte da DLL e deixe-a da seguinte maneira:
Library DLLCurso;
Uses SysUtils, Classes;
{$R *.res}
Function Triplo(N: Integer): Integer; stdcall; // permite exportar para C, C++, etc.
begin
Result := N * 3;
end;
Function Dobro (N: Integer): Integer; stdcall;
begin
Result := N * 2;
end;
ExportsTriploIndex 1, Dobro Index 2; // Permiteacesso às funções declaradas
end.
ü Salveo projeto como “C:\Sistema\DLLCurso“ ecompile-o ([Ctrl] + [F9]). Após issoserá criado um arquivo com o nome do projeto, só que com a extensão DLL.
ü Parausar as DLL, crie uma aplicação nova com 02 botões e 01 Edit, e declare suasfunções antes da seção Implementation, noseguinte formato:
Function Triplo(N: Integer): Integer; stdcall;
FunctionDobro(N: Integer): Integer; stdcall;
ü Dentroda seção Implementation, após adiretiva {$R *.DFM}, digite:
FunctionTriplo(N: Integer): Integer; external‘C:\Sistema\DLLCurso.dll';
FunctionDobro(N: Integer): Integer; external‘C:\Sistema\DLLCurso.dll';
ü Chamecada função no evento OnClick dos botões, passando comoparâmetro o número de que se deseja calcular o triplo ou o dobro.
Ex.:Edit1.Text := IntToStr(Dobro(100));// retorna 200
Edit1.Text := IntToStr(Triplo(100)); // retorna 300
Estetópico ensinará como criar uma DLL- biblioteca de ligação dinâmica.
Procedimentos a serem executados:
ü File -> CloseAll
ü File->New->Other->DLL Wizard
ü Apagueo comentário após a linha LibraryProject2;
ü Digiteas funções que farão parte da DLL e deixe-a da seguinte maneira:
Library DLLCurso;
Uses SysUtils, Classes;
{$R *.res}
Function Triplo(N: Integer): Integer; stdcall; // permite exportar para C, C++, etc.
begin
Result := N * 3;
end;
Function Dobro (N: Integer): Integer; stdcall;
begin
Result := N * 2;
end;
ExportsTriploIndex 1, Dobro Index 2; // Permiteacesso às funções declaradas
end.
ü Salveo projeto como “C:\Sistema\DLLCurso“ ecompile-o ([Ctrl] + [F9]). Após issoserá criado um arquivo com o nome do projeto, só que com a extensão DLL.
ü Parausar as DLL, crie uma aplicação nova com 02 botões e 01 Edit, e declare suasfunções antes da seção Implementation, noseguinte formato:
Function Triplo(N: Integer): Integer; stdcall;
FunctionDobro(N: Integer): Integer; stdcall;
ü Dentroda seção Implementation, após adiretiva {$R *.DFM}, digite:
FunctionTriplo(N: Integer): Integer; external‘C:\Sistema\DLLCurso.dll';
FunctionDobro(N: Integer): Integer; external‘C:\Sistema\DLLCurso.dll';
ü Chamecada função no evento OnClick dos botões, passando comoparâmetro o número de que se deseja calcular o triplo ou o dobro.
Ex.:Edit1.Text := IntToStr(Dobro(100));// retorna 200
Edit1.Text := IntToStr(Triplo(100)); // retorna 300
bielzinx- Membro
- Mensagens : 79
Agradecimentos : 8
Data de inscrição : 14/05/2011

» Tutorial Escudo (Formato redondo)
» [TUTORIAL] COMO COLOCAR UM TIME NA CBF
» [TUTORIAL] COMO CADASTRAR JOGADORES
» [TUTORIAL] COMO EDITAR FOTO DE PERFIL E ASSINATURA
» PASTA .MINECRAFT 1.5.1 COMPLETA+SERVER COM MODS MO'CREATURES E OPTFINE+TUTORIAL COMO BAIXAR E USAR
» [TUTORIAL] COMO COLOCAR UM TIME NA CBF
» [TUTORIAL] COMO CADASTRAR JOGADORES
» [TUTORIAL] COMO EDITAR FOTO DE PERFIL E ASSINATURA
» PASTA .MINECRAFT 1.5.1 COMPLETA+SERVER COM MODS MO'CREATURES E OPTFINE+TUTORIAL COMO BAIXAR E USAR
:: Programação :: Delphi :: Delphi Tutoriais.
Página 1 de 1
Permissão deste fórum:
Você não pode responder aos tópicos neste fórum