MainFrm.pas
上传用户:psxgmh
上传日期:2013-04-08
资源大小:15112k
文件大小:2k
- unit MainFrm;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls;
- type
- //定义DLL中引出的过程类型
- TShowDLLForm = procedure(aHandle: THandle); stdcall;
- EDLLError = class(Exception);
- TFrmMain = class(TForm)
- btnShowModal: TButton;
- btnShow: TButton;
- procedure btnShowModalClick(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure btnShowClick(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- private
- //指向加载后DLL句柄
- DLLHandle: THandle;
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- FrmMain: TFrmMain;
- implementation
- {$R *.dfm}
- //窗体创建时,加载DLL
- procedure TFrmMain.FormCreate(Sender: TObject);
- begin
- DLLHandle := LoadLibrary('..5-1DLLShowForm.dll');
- {如果DLLHandle为0,代表加载DLL失败}
- if DLLHandle = 0 then
- raise EDLLError.Create('不能加载DLLShowForm.dll');
- end;
- //窗体释放时,卸载DLL
- procedure TFrmMain.FormDestroy(Sender: TObject);
- begin
- FreeLibrary(DLLHandle);
- end;
- //模式显示窗口
- procedure TFrmMain.btnShowModalClick(Sender: TObject);
- var
- ShowDLLModalForm: TShowDLLForm;
- begin
- {链接DLL中的输出函数,以被调用}
- if (@ShowDLLModalForm = nil) then
- RaiseLastWin32Error;
- ShowDLLModalForm(Application.Handle);
- end;
- //非模式显示窗口
- procedure TFrmMain.btnShowClick(Sender: TObject);
- var
- ShowDLLForm: TShowDLLForm;
- begin
- @ShowDLLForm := GetProcAddress(DLLHandle, 'ShowDLLForm');
- if (@ShowDLLForm = nil) then
- RaiseLastWin32Error;
- ShowDLLForm(Application.Handle);
- end;
- end.