📄 mainform.pas
字号:
unit MainForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TDLLDemo = function(x, y: Integer): Integer; stdcall;
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
DllHandle: THandle;
DllPointer: Pointer;
MyDLLFunc: TDLLDemo;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
DllHandle := LoadLibrary('DLLDemo.dll');
if DllHandle > 0 then
try
DllPointer := GetProcAddress(DllHandle, PChar('AddIt'));
if DllPointer <> nil then begin
MyDLLFunc := TDLLDemo(DllPointer);
Edit1.Text := IntToStr(MyDLLFunc(5, 3));
end
else
ShowMessage('没有找到AddIt');
DllPointer := GetProcAddress(DllHandle, PChar('SubIt'));
if DllPointer <> nil then begin
MyDLLFunc := TDLLDemo(DllPointer);
Edit2.Text := IntToStr(MyDLLFunc(5, 3));
end
else
ShowMessage('没有找到SubIts');
finally
FreeLibrary(DllHandle);
end
else
ShowMessage('没有找到DLLDemo.dll');
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -