- 注册时间
- 2011-3-6
- 最后登录
- 1970-1-1
该用户从未签到
|
发表于 2011-4-2 08:56:25
|
显示全部楼层
你的代码我就不看了,头晕,我给你一个我在使用的,一切正常
library HookDll;
{ 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
Windows,
Messages,
SysUtils,
Classes,
Forms,
Variants,
uDll in 'uDll.pas' {FrmDll},
uFunc in 'uFunc.pas',
uGlobal in 'uGlobal.pas';
{$R *.res}
var
HK: HHOOK = 0;
HMod: Pointer;
ProcID: Cardinal;
//--------------------------勾子子程-----------------------------------
function HookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
label
ToExit;
begin
if nCode < 0 then goto ToExit;
if nCode <> HC_ACTION then goto ToExit;
if (LPARAM and $80000000) = 0 then goto ToExit;
if WPARAM=VK_F12 then
begin
if FrmDll = nil then FrmDll:=TFrmDll.Create(Application);
FrmDll.Visible := not FrmDll.Visible;
end;
ToExit:
Result := CallNexthookex(HK,nCode,wparam,lparam);
end;
//--------------------------安装勾子-----------------------------------
function HookOn(AHwd: HWND): LongInt; stdcall; export;
begin
ProcID := GetWindowThreadProcessId(AHwd,HMod);
if ProcID <> 0 then HK := SetWindowsHookEx(WH_KEYBOARD,@HookProc,hinstance,ProcID);
Result := HK;
end;
//--------------------------关闭勾子-----------------------------------
function HookOff(AHHK: HHOOK): Boolean; stdcall; export;
begin
Result := False;
if AHHK <> 0 then begin
UnhookWindowsHookEx(AHHK);
Result := True;
end;
end;
procedure MyDllProc(Reason: Integer);
begin
case Reason of
DLL_PROCESS_DETACH:
begin
FreeAndNil(FrmDll);
//ShowMessage('整个DLL的善後程序');
end;
DLL_Process_Attach:
begin
//ShowMessage('整个DLL的初始化代码');
end;
DLL_Thread_Attach:
begin
//FrmDll:=TFrmDll.Create(Application);
//ShowMessage('当主叫端开始一个Thread时');
end;
DLL_Thread_Detach:
begin
//ShowMessage('当主叫端终止一个Thread时');
end;
end;
end;
exports HookOn, HookOff;
begin
//DllProc := @MyDllProc
end. |
|