var
hnextHookProc: HHook;
ProcSaveExit: Pointer;
//你的function GetParams(): TstringList
function KeyBoardHookHandler(iCode: Integer; wParam: WPARAM; lParam: LParam): lresult;stdcall; export;
function EnableHotKeyHook: Bool; export;
function DisableHotKeyHook: Bool; export;
procedure HotKeyHookExit; far;
implementation
function KeyboardHookHandler(iCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT
stdcall; export;
const
_KeyPressMask = $80000000; //按键代码
begin //开始一个循环的钩子
Result := 0;
if iCode < 0 then
begin
Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);
Exit;
end;
// 监测 Ctrl + C 组合热键
if ((lParam and _KeyPressMask) = 0) and (GetKeyState(vk_Control) < 0) and (wParam = Ord('C')) then
begin
Result := 1;
WinExec('c:\windows\calc.exe', sw_Normal); //运行计算器程序
end;
end;
function EnableHotKeyHook: BOOL; export;
begin
Result := False;
if hNextHookProc <> 0 then Exit;
// 挂上钩子并保留返回值形成钩子环(Hook Loop)
hNextHookProc := SetWindowsHookEx(WH_KEYBOARD, KeyboardHookHandler, HInstance, 0);
Result := hNextHookProc <> 0;
end;
function DisableHotKeyHook: BOOL; export;
begin
if hNextHookProc <> 0 then
begin
UnhookWindowshookEx(hNextHookProc); // 解除键盘钩子
hNextHookProc := 0;
MessageBeep(0); //扬声器鸣叫提示
end;
Result := hNextHookProc = 0;
end;
procedure HotKeyHookExit;
begin
//即使忘了解除 HOOK,自动解除
if hNextHookProc <> 0 then DisableHotKeyHook;
ExitProc := procSaveExit;
end;
file -> new -> other ->Active X Library
在uses後裏寫函數然後
exports
showAbout,calc_x2; //相應的要對外發布的函數名。
例如:
library dll;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
Classes,
Forms,
About in 'About.pas' {frmAbout};
procedure showAbout(title:shortString);stdcall;
var frmAbout:TfrmAbout;
begin
frmAbout:=TfrmAbout.Create(Application);
frmAbout.Caption:=title;
frmAbout.ShowModal;
frmAbout.Release;
end;
function calc_x2(i:integer):integer;stdcall;
begin
result:=i*i;
end;
{$R *.res}
exports
showAbout,calc_x2;
begin
end.