DLL代码如下:
-------------
library Inject;{ 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,
UnitHook in 'UnitHook.pas';{$R *.res}
exports
StartHook,StopHook;begin
end.UnitHook代码如下:
------------------
unit UnitHook;interfaceuses Windows, SysUtils, Classes, math, messages, dialogs;const
WM_TestMessage = WM_USER + 2004;
WM_IATMessage = WM_USER + 2005; TrapMode = False; //True陷阱式,False表示改引入表式 function StartHook(mHandle : longint;QQProcID : Cardinal):boolean;stdcall;export;
function StopHook():boolean;stdcall;export;implementationvar
MainHandle : longint;
MessageHook : HHOOK;function MyHookProc(iCode:Integer;wParam:WPARAM;lParam:LPARAM):LRESULT; stdcall;
begin
if iCode < 0 then
begin
Result := CallNextHookEx(MessageHook, iCode, wParam, longint(@lParam));
exit;
end;
if iCode = HC_ACTION then
begin
if PMsg(lParam)^.Message = WM_TestMessage then
begin
showmessage('Recv This Msg');
end;
end;
Result := CallNextHookEx(MessageHook, iCode, wParam, longint(@lParam));
end;function StartHook(mHandle : longint;QQProcID : Cardinal):boolean;stdcall;export;
begin
MainHandle := mHandle;
showmessage(IntToStr(MainHandle) + ' - ' + IntToStr(QQProcID));
Result := false;
if MessageHook = 0 then
begin
MessageHook := SetWindowsHookEx(WH_GETMESSAGE,MyHookProc,hInstance,0);
if longint(MessageHook) <> 0 then
Result := True
else
showmessage('Hook Error');
end;
end;function StopHook():boolean;stdcall;export;
begin
if MessageHook <> 0 then
begin
UnHookWindowsHookEx(MessageHook);
MessageHook := 0;
end;
Result := True;
end;end.调用StartHook函数时,showmessage显示的值和传入的值不等,不知何故。请高手指点。
-------------
library Inject;{ 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,
UnitHook in 'UnitHook.pas';{$R *.res}
exports
StartHook,StopHook;begin
end.UnitHook代码如下:
------------------
unit UnitHook;interfaceuses Windows, SysUtils, Classes, math, messages, dialogs;const
WM_TestMessage = WM_USER + 2004;
WM_IATMessage = WM_USER + 2005; TrapMode = False; //True陷阱式,False表示改引入表式 function StartHook(mHandle : longint;QQProcID : Cardinal):boolean;stdcall;export;
function StopHook():boolean;stdcall;export;implementationvar
MainHandle : longint;
MessageHook : HHOOK;function MyHookProc(iCode:Integer;wParam:WPARAM;lParam:LPARAM):LRESULT; stdcall;
begin
if iCode < 0 then
begin
Result := CallNextHookEx(MessageHook, iCode, wParam, longint(@lParam));
exit;
end;
if iCode = HC_ACTION then
begin
if PMsg(lParam)^.Message = WM_TestMessage then
begin
showmessage('Recv This Msg');
end;
end;
Result := CallNextHookEx(MessageHook, iCode, wParam, longint(@lParam));
end;function StartHook(mHandle : longint;QQProcID : Cardinal):boolean;stdcall;export;
begin
MainHandle := mHandle;
showmessage(IntToStr(MainHandle) + ' - ' + IntToStr(QQProcID));
Result := false;
if MessageHook = 0 then
begin
MessageHook := SetWindowsHookEx(WH_GETMESSAGE,MyHookProc,hInstance,0);
if longint(MessageHook) <> 0 then
Result := True
else
showmessage('Hook Error');
end;
end;function StopHook():boolean;stdcall;export;
begin
if MessageHook <> 0 then
begin
UnHookWindowsHookEx(MessageHook);
MessageHook := 0;
end;
Result := True;
end;end.调用StartHook函数时,showmessage显示的值和传入的值不等,不知何故。请高手指点。
解决方案 »
- 请教下谁有具体点的idhttp或者webbrowser的使用方法?
- 求助!这两个sql表能合并吗?
- 简单问题:怎样使combobox控件不可编辑.
- 如何在编程环境下生成和编辑pdf文件
- 我安装ehlib时总是出错,谁能说一下ehlib是怎样安装的 ?谢谢!
- 改变DBEDIT的对齐方式,对所有数据类型都为左对齐
- listview是不是有个LOADFROMFILE的方法啊,可是我就是找不到,麻烦谁告诉我一下好吗?
- 我想读出某string的最后几个字,如,我想读出IP:61.136.123.12最后一个句号之后的内容(例子中为12),请问怎么做?
- 问个很菜的问题
- Delphi6与Delphi5之间的一个难以解决的问题
- 如何把JPEG等转换为PDF格式的?
- 请问有没有介绍Object Pascal 方面的书?
请注意 MessageHook 所在的进程空间。楼主是想获得 qq密码框里的密码,呵呵,我也做过啊,是练习使用钩子的好途径。
为什么在StartHook中显示正确了,MainHandle到了别的函数里又变成0了呢?