用C++ Builder编HOOK程序
作者 佚名技术
来源 程序设计
浏览
发布时间 2012-06-30
sizeof(TShareMem), "ShareForMouseHook"); ShareMem=(TShareMem *)MapViewOfFile(fh, FILE_MAP_ALL_ACCESS, 0,0,0); if (GetLastError()!=ERROR_ALREADY_EXISTS) ZeroMemory(ShareMem,sizeof(TShareMem)); // 共享区初始化 ShareMem->LoadCount+=1; // 装入计数 } if (reason==DLL_PROCESS_DETACH) // DLL出口处理 { ShareMem->LoadCount-=1; CloseHandle(fh); } return 1; } extern "C" __declspec(dllexport) void GetMouse(int &mx,int &my,int &loadcount) // DLL导出函数GetMouse() { if (ShareMem!=NULL) { mx=ShareMem->MouseLoc.x; my=ShareMem->MouseLoc.y; loadcount=ShareMem->LoadCount; } } LRESULT CALLBACK MouseHook(int nCode, WPARAM wParam,LPARAM lParam) { if (nCode==HC_ACTION) { MOUSEHOOKSTRUCT *l=(MOUSEHOOKSTRUCT *)lParam; ShareMem->MouseLoc=l->pt; //送鼠标位置 } return(CallNextHookEx(ShareMem->NewHook,nCode,wParam,lParam)); } extern "C" __declspec(dllexport) void EnableHook() // 导出函数EnableHook() { if (ShareMem!=NULL) if (ShareMem->NewHook==NULL) // 安装新钩子 ShareMem->NewHook=SetWindowsHookEx(WH_MOUSE, (HOOKPROC)MouseHook, DllHinst,0); } extern "C" __declspec(dllexport) void DisableHook() // 导出函数DisableHook() { if (ShareMem!=NULL) if (ShareMem->NewHook!=NULL) { UnhookWindowsHookEx(ShareMem->NewHook); ShareMem->NewHook=NULL; // 卸掉新钩子 } } //======================================================================= #include <vcl.h> #pragma hdrstop #include "CallUnit1.h" #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- extern "C" __declspec(dllimport) void EnableHook(); // DLL导入函数1 extern "C" __declspec(dllimport) void DisableHook(); // DLL导入函数2 extern "C" __declspec(dllimport) void GetMouse(int &mx,int &my,int &loadcount); // DLL导入函数3 void __fastcall TForm1::Button1Click(TObject *Sender) { EnableHook(); int x,y,loadcount; while (!Application->Terminated) { // 不停在从DLL中取回鼠标位置 GetMouse(x,y,loadcount); Edit1->Text=String(x)+","+String(y)+":"+String(loadcount); Application->ProcessMessages(); } } void __fastcall TForm1::Button2Click(TObject *Sender) { DisableHook(); } void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Actio |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
上一篇: 设置壁纸方法下一篇: 用C++Builder检测Windows的启动模式
关于用C++ Builder编HOOK程序的所有评论