谁有hook代码 (50分)

  • 主题发起人 主题发起人 liaoshu
  • 开始时间 开始时间
L

liaoshu

Unregistered / Unconfirmed
GUEST, unregistred user!
要能hook sendmessage的
 
unit UnitHookMsg;<br><br>interface<br>&nbsp;uses windows,messages,SysUtils;<br><br>const<br>&nbsp; WM_HOOKMSG = WM_USER + $1000;<br>&nbsp; _mapFile = '_msgHookMap';<br><br>&nbsp; procedure StartMsg ; stdcall;<br>&nbsp; procedure StopMsg; &nbsp;stdcall;<br><br>implementation<br><br>var<br>&nbsp; NextHook &nbsp; &nbsp; &nbsp;: HHook;<br>&nbsp; FileMapHandle : THandle;<br>&nbsp; PViewInteger &nbsp;: ^Integer;<br><br>function HookHandler( Code &nbsp; &nbsp;: Integer;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wParam &nbsp;: WPARAM;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lParam &nbsp;: LPARAM<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ) &nbsp; &nbsp; &nbsp; : LRESULT; stdcall;<br><br>var<br>&nbsp; Msg : PMSG;<br>begin<br>&nbsp; if code=HC_ACTION then<br>&nbsp; begin<br>&nbsp; Msg := PMSG(lParam);<br>&nbsp; case Msg.message of<br>&nbsp; WM_CREATE:<br>&nbsp; begin<br>&nbsp; &nbsp; PostMessage(PViewInteger^,WM_HOOKMSG,wParam,lParam);<br>&nbsp; end;<br>&nbsp; end;<br>&nbsp; end;<br>&nbsp; Result := CallNextHookEx(NextHook, Code, wParam, lParam);<br>end;<br><br>procedure StartMsg; stdcall;<br>begin<br>&nbsp; NextHook:=SetWindowsHookEx((*WH_GETMESSAGE,WH_CALLWNDPROCRET*)WH_CALLWNDPROC, HookHandler, HInstance , 0);<br>(*HOOK在MySpy里是用的最多的技术,从获取密码到截获系统的消息都是HOOK技术,可以说这<br>个技术已经不是什么技术了,网上随便一个编程站点都可以找到相关介绍资料,但截获系统<br>消息的还是比较麻烦的,作者就介绍一下它吧,截获系统消息无非是安装系统钩子WH_CALLWNDPROC、<br>WH_CALLWNDPROCRET和WH_GETMESSAGE,为什么要安装这么多,因为系统消息有很多不同的类型,<br>有Send,Post还有处理消息返回也是需要截获的,当然如果你对系统菜单也感兴趣,还需要安<br>装WH_SYSMSGFILTER钩子,因为这是一个系统范围的钩子,所以必须编写成为DLL,而核心代码<br>也不过就是:<br><br>WH_CALLWNDPROC和WH_CALLWNDPROCRET Hooks使你可以监视发送到窗口过程的消<br>息。系统在消息发送到接收窗口过程之前调用WH_CALLWNDPROC Hook子程,并且在窗口过程处理<br>完消息之后调用WH_CALLWNDPROCRET Hook子程。 &nbsp;WH_CALLWNDPROCRET Hook传递指针到<br>CWPRETSTRUCT结构,再传递到Hook子程。CWPRETSTRUCT结构包含了来自处理消息的窗口过程的<br>返回值,同样也包括了与这个消息关联的消息参数。<br>*)<br>end;<br><br>procedure StopMsg; &nbsp;stdcall;<br>begin<br>&nbsp; UnhookWindowsHookEx(NextHook);<br>end;<br><br>initialization<br>&nbsp; &nbsp; &nbsp; FileMapHandle:=OpenFileMapping(FILE_MAP_READ,False,_mapFile);<br>&nbsp; &nbsp; &nbsp; if FileMapHandle=0 then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; FileMapHandle := CreateFileMapping($FFFFFFFF,nil,PAGE_READWRITE,0,SizeOf(Integer),_mapFile);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; if FileMapHandle=0 then Exception.Create('不能建立共享内存!');<br><br>&nbsp; &nbsp; &nbsp; PViewInteger:=MapViewOfFile(FileMapHandle,FILE_MAP_READ,0,0,0);<br>&nbsp; &nbsp; &nbsp; if PViewInteger = nil then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; CloseHandle(FileMapHandle);<br>&nbsp; &nbsp; &nbsp; &nbsp; Exception.Create('不能映射共享内存!');<br>&nbsp; &nbsp; &nbsp; end;<br>finalization<br>&nbsp; &nbsp; &nbsp; UnmapViewOfFile(PViewInteger);<br>&nbsp; &nbsp; &nbsp; CloseHandle(FileMapHandle);<br>end.<br><br>上面是dll源码,调用程序需要先映射共享内存,设定主窗口句柄,然后StartMsg就行了
 
不好意思,中间那点文字是从别的地方找到的一点注释,写在自己程序里做参考的,可以忽略
 
to:品梅小哥<br>请问以下C++代码中的if(wparam==0x3e9)在delphi中应该如何写?<br>LRESULT CALLBACK MyMsgProc(HWND hwnd,UINT umsg,WPARAM wparam,LPARAM lparam)<br>{<br> //消息过滤<br> switch (umsg)<br> {<br> case WM_ACTIVATEAPP:<br> case WM_ACTIVATE:<br> case WM_KILLFOCUS:<br> case WM_SETFOCUS:<br> case WM_CLOSE:<br> return 0;//这里是个关键,把这个计时器kill<br> case WM_TIMER:<br> if(wparam==0x3e9)<br> KillTimer(hwnd,wparam);<br> break;<br>&nbsp; &nbsp; }
 
if wparam=$3e9 then
 
PostMessage(PViewInteger^,WM_HOOKMSG,wParam,lParam);<br>负责通知主窗口WM_HOOKMSG消息,也就是说当前截获到了消息,这个时候<br>lparam中保存的是一个PMSG结构,<br>当主窗口收到这个消息以后要<br>Msg := PMSG(lParam);<br>&nbsp;Msg.message才是你要的WM_ACTIVATEAPP...<br>应该这样:<br>switch (Msg.messages)<br>&nbsp;{<br>&nbsp;case WM_ACTIVATEAPP:<br><br>if(wparam==0x3e9)转化成<br>if (wParam = Integer($3E9))<br>&nbsp;
 
to:品梅小哥<br>&nbsp; &nbsp; Msg := PMSG(lParam);<br>&nbsp; &nbsp; case Msg.message of<br>&nbsp; &nbsp; &nbsp; WM_TIMER:<br>&nbsp; &nbsp; &nbsp; &nbsp; if wparam=integer($3e9) then<br> &nbsp;KillTimer(h,wparam);<br>是否一定要加上后面的:<br>&nbsp; &nbsp; &nbsp; WM_CREATE:<br>&nbsp; &nbsp; &nbsp; &nbsp; PostMessage(PViewInteger^,WM_HOOKMSG,wParam,lParam);
 
呵呵,你理解错我的意思了<br>那个是个例子,你在设置钩子的时候(dll里),<br>这个时候你的钩子会钩到所有消息<br>function HookHandler( Code &nbsp; &nbsp;: Integer;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wParam &nbsp;: WPARAM;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lParam &nbsp;: LPARAM<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;) &nbsp; &nbsp; &nbsp; : LRESULT; stdcall;<br><br>var<br>&nbsp;Msg : PMSG;<br>begin<br>&nbsp;if code=HC_ACTION then<br>&nbsp;begin<br>&nbsp;Msg := PMSG(lParam);<br>&nbsp;case Msg.message of<br>&nbsp;///////////////////////////这里加入你要钩的消息s<br>&nbsp;WM_ACTIVATEAPP:<br>&nbsp;WM_ACTIVATE:<br>&nbsp;WM_KILLFOCUS:<br>&nbsp;WM_SETFOCUS:<br>&nbsp;WM_CLOSE:<br>&nbsp;//////////////////然后通知设置这个钩子的主窗口已经截到需要的消息了<br>&nbsp;begin<br>&nbsp; &nbsp;PostMessage(PViewInteger^,WM_HOOKMSG,wParam,lParam);<br>&nbsp;end;<br>&nbsp;end;<br>&nbsp;end;<br>&nbsp;Result := CallNextHookEx(NextHook, Code, wParam, lParam);<br>end;<br><br>上面是在dll里面需要做的工作<br><br>在主程序里面,首先映射内存,设定钩子发送消息的窗口句柄,也就是主程序的句柄<br>procedure TFrmMain.btnMsgStartClick(Sender: TObject);<br>begin<br>&nbsp; &nbsp;hMapMsg := OpenFileMapping(FILE_MAP_WRITE,False,_msgHookMap);///映射内存<br>&nbsp; &nbsp;if hMapMsg=0 then<br>&nbsp; &nbsp; &nbsp;raise Exception.Create( '创建内存映射文件时出错');<br>&nbsp; &nbsp;pMemMsg:=MapViewOfFile(hMapMsg,FILE_MAP_WRITE,0,0,0);<br>&nbsp; &nbsp;if pMemMsg = nil then exit;<br>&nbsp; &nbsp;pMemMsg^:=Handle;//////////////////////////////////当截到消息时,就给该句柄发送消息<br>&nbsp; StartMsg;<br>end;<br>//////////停止钩子的时候要关闭内存映射<br>procedure TFrmMain.btnMsgStopClick(Sender: TObject);<br>begin<br>&nbsp; StopMsg;<br>&nbsp; if hMapMsg&lt;&gt;0 then<br>&nbsp; begin<br>&nbsp; &nbsp; UnmapViewOfFile(pMemMsg);<br>&nbsp; &nbsp; CloseHandle(hMapMsg);<br>&nbsp; end;<br>&nbsp; hMapMsg := 0;<br>end;<br><br>另外你还要一个你已经定义的消息处理函数,就是这个消息WM_HOOKMSG = WM_USER + $1000;<br>当你的程序受到这个消息,说明dll里面的钩子截到了你需要的消息<br>然后你就要处理它了<br>定义<br>&nbsp; &nbsp; procedure HookMsg(var messages: TMessage); message &nbsp;WM_HOOKMSG ;<br>过程<br>procedure TFrmMain.HookMsg(var messages: TMessage);<br>var<br>&nbsp;Msg : PMSG;<br>begin<br>&nbsp;Msg := PMSG(lParam);<br>&nbsp;case Msg.message of<br>&nbsp;WM_ACTIVATEAPP:<br>&nbsp;WM_ACTIVATE:<br>&nbsp;WM_KILLFOCUS:<br>&nbsp;WM_SETFOCUS:<br>&nbsp;WM_CLOSE:<br>&nbsp;begin<br>&nbsp; &nbsp;//do your things<br>&nbsp;end;<br>&nbsp;end;<br>end;<br><br><br><br><br><br><br>
 
另外wparam和lparam两个参数你一定要搞清楚<br>钩子截下来以后,整个消息就被封装在当时的lparam里了<br>function HookHandler( Code : Integer;wParam: WPARAM;[red]lParam: LPARAM [/red]) : LRESULT; stdcall;<br>Msg := PMSG(lParam); &nbsp;//这个才是你要的消息<br><br>在主程序中也是一样,<br>所以你这句<br>if wparam=integer($3e9) then<br>&nbsp; &nbsp;KillTimer(h,wparam);<br>我觉得可能得改成<br>if Msg.wparam=integer($3e9) then<br>&nbsp; &nbsp;KillTimer(h,Msg.wparam);<br>
 
to:品梅小哥<br>实在不好意思,我是新手没什么分,等下我用朋友的号再给100分,请你帮看一下下面的代码<br>以下是我的程序<br>dll部分:<br>library HookApi;<br><br>uses<br>&nbsp; SysUtils,<br>&nbsp; windows,<br>&nbsp; Messages;<br><br>type<br>&nbsp;PData = ^TData;<br>&nbsp;TData = record<br>&nbsp; &nbsp;Hook: THandle;<br>&nbsp; &nbsp;Hooked: Boolean;<br>&nbsp;end;<br>&nbsp;<br>var<br>&nbsp;DLLData: PData;<br>&nbsp;h:thandle;<br>{------------------------------------}<br>{过程名:HookProc<br>{过程功能:HOOK过程<br>{过程参数:nCode, wParam, lParam消息的相<br>{ &nbsp; &nbsp; &nbsp; &nbsp; 关参数<br>{------------------------------------}<br>procedure HookProc(nCode, wParam, lParam: LongWORD);stdcall;<br>var<br>&nbsp;Msg : PMSG;<br>begin<br>&nbsp;if ncode=HC_ACTION then<br>&nbsp;begin<br> SetWindowLong(h,GWL_STYLE,GetWindowLong(h,GWL_STYLE) or WS_CAPTION);//修改窗体的exstyle属性<br> SetWindowLong(h,GWL_EXSTYLE,GetWindowLong(h,GWL_EXSTYLE)<br>&nbsp; &nbsp; or WS_EX_APPWINDOW or WS_EX_WINDOWEDGE);<br>&nbsp; //设置窗体的位置,取消其最前端显示,为图简单807,632是我自己随便设的//当然最好是先用AdjustWindowRect函数调整一下大小<br> SetWindowPos(h,HWND_NOTOPMOST,0,0,640,480,SWP_SHOWWINDOW);<br>&nbsp; &nbsp;ShowWindow(h,SW_SHOWNORMAL);<br>&nbsp; &nbsp;Msg := PMSG(lParam);<br>&nbsp; &nbsp;///////////////////////////这里加入你要钩的消息s<br>&nbsp; &nbsp;if Msg.wparam=integer($3e9) then<br>&nbsp; &nbsp; &nbsp;KillTimer(h,Msg.wparam);<br>&nbsp; &nbsp;DLLData^.Hooked := True;<br>&nbsp;end;<br>&nbsp;//调用下一个Hook<br>&nbsp;CallNextHookEx(DLLData^.Hook, nCode, wParam, lParam);<br>end;<br><br><br>{------------------------------------}<br>{函数名:InstallHook<br>{函数功能:在指定窗口上安装HOOK<br>{函数参数:sWindow:要安装HOOK的窗口<br>{返回值:成功返回TRUE,失败返回FALSE<br>{------------------------------------}<br>function InstallHook(SWindow: LongWORD):Boolean;stdcall;<br>var<br>&nbsp;ThreadID: LongWORD;<br>begin<br>&nbsp;Result := False;<br>&nbsp;DLLData^.Hook := 0;<br>&nbsp;h:=swindow;<br>&nbsp;ThreadID := GetWindowThreadProcessId(sWindow, nil);<br>&nbsp;//给指定窗口挂上钩子<br>&nbsp;DLLData^.Hook := SetWindowsHookEx(WH_GETMESSAGE, @HookProc, Hinstance, ThreadID);<br>&nbsp;if DLLData^.Hook &gt; 0 then<br>&nbsp; &nbsp;Result := True &nbsp;//是否成功HOOK<br>&nbsp;else<br>&nbsp; &nbsp;exit;<br>end;<br><br>{------------------------------------}<br>{过程名:UnHook<br>{过程功能:卸载HOOK<br>{过程参数:无<br>{------------------------------------}<br>procedure UnHook;stdcall;<br>begin<br>&nbsp;//卸载Hook<br>&nbsp;UnhookWindowsHookEx(DLLData^.Hook);<br>end;<br><br>{------------------------------------}<br>{过程名:DLL入口函数<br>{过程功能:进行DLL初始化,释放等<br>{过程参数:DLL状态<br>{------------------------------------}<br>procedure MyDLLHandler(Reason: Integer);<br>var<br>&nbsp;FHandle: LongWORD;<br>begin<br>&nbsp;case Reason of<br>&nbsp; &nbsp;DLL_PROCESS_ATTACH:<br>&nbsp; &nbsp;begin &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//建立文件映射,以实现DLL中的全局变量<br>&nbsp; &nbsp; &nbsp;FHandle := CreateFileMapping($FFFFFFFF, nil, PAGE_READWRITE, 0, $ffff, 'MYDLLDATA');<br>&nbsp; &nbsp; &nbsp;if FHandle = 0 then<br>&nbsp; &nbsp; &nbsp;if GetLastError = ERROR_ALREADY_EXISTS then<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp;FHandle := OpenFileMapping(FILE_MAP_ALL_ACCESS, False, 'MYDLLDATA');<br>&nbsp; &nbsp; &nbsp; &nbsp;if FHandle = 0 then Exit;<br>&nbsp; &nbsp; &nbsp;end else Exit;<br>&nbsp; &nbsp; &nbsp;DLLData := MapViewOfFile(FHandle, FILE_MAP_ALL_ACCESS, 0, 0, 0);<br>&nbsp; &nbsp; &nbsp;if DLLData = nil then<br>&nbsp; &nbsp; &nbsp; &nbsp;CloseHandle(FHandle);<br>&nbsp; &nbsp;end;<br>&nbsp; &nbsp;DLL_PROCESS_DETACH:<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;if Assigned(DLLData) then<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp;UnmapViewOfFile(DLLData);<br>&nbsp; &nbsp; &nbsp; &nbsp;DLLData := nil;<br>&nbsp; &nbsp; &nbsp; &nbsp;h:=0;<br>&nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp;end;<br>&nbsp;end;<br>end;<br><br>{$R *.res}<br>exports<br>&nbsp;InstallHook, UnHook, HookProc;<br><br>begin<br>&nbsp;DLLProc := @MyDLLHandler;<br>&nbsp;MyDLLhandler(DLL_PROCESS_ATTACH);<br>&nbsp;DLLData^.Hooked := False;<br>end.<br><br>主程序部分<br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; InstallHook: function(SWindow:LongWORD):boolean;stdcall;<br>&nbsp; UnHook: procedure;stdcall;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; &nbsp; @InstallHook := GetProcAddress(hw, 'InstallHook');<br>&nbsp; &nbsp; @UnHook := GetProcAddress(hw, 'UnHook');<br>&nbsp; &nbsp; if InstallHook(h) then<br>&nbsp; &nbsp; &nbsp; caption:='hook';<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>&nbsp; &nbsp;Unhook;<br>end;<br>不知道为什么勾不到.<br><br><br>
 
SetWindowsHookEx(WH_GETMESSAGE, @HookProc, Hinstance, ThreadID);<br><br>SetWindowsHookEx(WH_GETMESSAGE, @HookProc, Hinstance, 0);//试试看??<br>SetWindowsHookEx(WH_CALLWNDPROC, @HookProc, Hinstance, 0);//不行用这个,这个是消息被处理前,肯定能钩到<br>SetWindowsHookEx(WH_CALLWNDPROCRET, @HookProc, Hinstance, 0);//消息被处理后<br><br>你先试试看,这样行不行,<br>另外<br>if ncode=HC_ACTION then<br>begin<br>&nbsp; SetWindowLong(h,GWL_STYLE,GetWindowLong(h,GWL_STYLE) or WS_CAPTION);//修改窗体的exstyle属性<br>&nbsp; SetWindowLong(h,GWL_EXSTYLE,GetWindowLong(h,GWL_EXSTYLE)<br>&nbsp; &nbsp;or WS_EX_APPWINDOW or WS_EX_WINDOWEDGE);<br>&nbsp;//设置窗体的位置,取消其最前端显示,为图简单807,632是我自己随便设的//当然最好是先用AdjustWindowRect函数调整一下大小<br>&nbsp; SetWindowPos(h,HWND_NOTOPMOST,0,0,640,480,SWP_SHOWWINDOW);<br>&nbsp; ShowWindow(h,SW_SHOWNORMAL);<br><br>这里好像不大好,截取系统消息以后,会出现N多的ncode=HC_ACTION 消息,这段程序应该放在别的地方
 
SetWindowsHookEx(WH_CALLWNDPROC, @HookProc, Hinstance, 0);<br>这个是全局钩子,会影响别的程序吧?
 
SetWindowsHookEx(WH_CALLWNDPROC, @HookProc, Hinstance, ThreadID);<br>这个时候截获消息以后,需要判断是否当前进程的消息<br><br>if ncode=HC_ACTION then<br>begin<br>&nbsp; if (wparam &lt;&gt; 0) then<br>&nbsp; begin<br>&nbsp; &nbsp; //表示是当前进程,可以在这里处理<br>&nbsp; end;<br><br>你试试看吧,不行把程序发给我我帮你改一下
 
实在搞不定了,你拿去看看吧,还有别人的c++代码<br>http://sky.9226.com/hookapi.rar<br>谢谢
 
不好意思,你的程序有点乱,我自己做了一个应用程序调用dll<br>点击按钮设定钩子,程序里面在case的地方少了一个end<br>&nbsp; &nbsp;Msg := PMSG(lParam);<br>&nbsp; &nbsp; case msg.message of<br>&nbsp; &nbsp; WM_TIMER:<br>&nbsp; &nbsp; &nbsp; if (wparam=integer($3e9)) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;KillTimer(h,Msg.wparam);<br>&nbsp; &nbsp; end;////////////////////////////////////////////加上这个<br>&nbsp; &nbsp; DLLData^.Hooked := TRUE;<br>运行以后效果应该是你想要的<br> SetWindowLong(h,GWL_STYLE,GetWindowLong(h,GWL_STYLE) or WS_CAPTION);//修改窗体的exstyle属性<br> SetWindowLong(h,GWL_EXSTYLE,GetWindowLong(h,GWL_EXSTYLE)<br>&nbsp; &nbsp; or WS_EX_APPWINDOW or WS_EX_WINDOWEDGE);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //设置窗体的位置,取消其最前端显示,为图简单807,632是我自己随便设的//当然最好是先用AdjustWindowRect函数调整一下大小<br> SetWindowPos(h,HWND_NOTOPMOST,0,0,640,480,SWP_SHOWWINDOW);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShowWindow(h,SW_SHOWNORMAL);<br>这几句都运行到了,所以消息是截到了已经,如果没有你要的效果,那说明你自己在后面的处理过程中有问题,我不知道你主程序的目的是什么,包括你在那里SetTimer,所以你要的<br>WM_TIMER消息我没办法帮你测试,你自己再看看怎么改<br><br>1.最好用nCode = HC_ACTION,虽然HC_ACTION定义也是0,这是一个风格问题<br>2.你好想还是没有理解,当截获这个消息的时候,原来的整个你需要的消息被封装在lparam<br>中了所以Msg.wParam才是 WM_TIMER消息的wParam,所以<br>&nbsp; if (wparam=integer($3e9)) then可能需要改成 if(Msg.wParam = Integer($3E9))<br>3.你内存映射中的Hooked需要和主程序之间共享吗?如果是dll内部变量,就不要写入内存映<br>射了,<br><br><br>另外我用delphi程序调用了C++写的dll<br>var<br>hTemp : HWND;<br>begin<br>&nbsp; hTemp := GetWindowThreadProcessId(Handle, nil);<br>&nbsp; InstallHook(true, hTemp);<br>end;<br>运行效果和C++程序运行相同<br><br>如果你还搞不定,那把主调程序也发给我看一下
 
另外我希望你能理解我的编程风格,我个人觉得,封装起来的功能模块尽量要功能简单通用,<br>就像这个钩子dll一样,我觉得应该钩子只负责钩消息,而不负责处理,你要处理了,那这个dll<br>的扩展性就没了,当钩到消息以后你为什么不能把它发给主程序处理呢?你只要SendMessage<br>或者PostMessage给主程序,接下来就不用dll管了,你主程序再要作甚么是你自己的事,和dll<br>就无关了.<br>
 
接受答案了.
 
后退
顶部