const char *hook_map="sample hook memflag";<br>const char *hook_mux="Hook MUtex";<br>HANDLE memfile,HookMutex;<br>LPVOID lpMapAddress;<br>DWORD dwnumber;<br>HHOOK hNextHookProc;<br>HOOKPROC TMP;<br>LRESULT CALLBACK KeyboardProc(int code, WPARAM wParam, LPARAM lParam)<br> { const<br> _KeyPressMask = 0x80000000;<br> int Result=0;<br> if (code<0)<br> Result = CallNextHookEx(hNextHookProc, code, wParam, lParam);<br> else<br> { if((lParam & _KeyPressMask)== 0 )<br> //ShowMessage("OK");<br> {<br> dwnumber = *((LPDWORD) lpMapAddress);<br> ++dwnumber;<br> *((LPDWORD) lpMapAddress) = dwnumber;<br> }<br> }<br> return Result;<br>}<br>bool _stdcall EnableHotKeyHook()<br>{ TMP=(HOOKPROC)KeyboardProc;<br> bool Result=false;<br> if (hNextHookProc==0)<br> {<br> hNextHookProc = SetWindowsHookEx(WH_KEYBOARD,<br> TMP,<br> HInstance,<br> 0);<br> Result=(hNextHookProc!=0);<br> <br> HookMutex=CreateMutex(NULL,true,hook_mux);<br> memfile=OpenFileMapping(FILE_MAP_WRITE,<br> false,<br> hook_map);<br> if (memfile==NULL)<br> memfile=CreateFileMapping( (HANDLE)0xFFFFFFFF,<br> NULL,<br> PAGE_READWRITE,<br> 0,<br> sizeof(LPVOID),<br> hook_map);<br><br> lpMapAddress=MapViewOfFile(memfile,<br> FILE_MAP_WRITE,<br> 0,<br> 0,<br> 0);<br> ReleaseMutex(HookMutex);<br> CloseHandle(HookMutex);<br> *((LPDWORD) lpMapAddress)=0;<br> <br> }<br> return Result;<br>}<br>bool _stdcall DisableHotKeyHook()<br>{ bool Result=false;<br>if (hNextHookProc!=0)<br> {<br> UnhookWindowsHookEx(hNextHookProc);<br> hNextHookProc = 0;<br> Result=(hNextHookProc == 0);<br> if (memfile!=NULL)<br> {<br> UnmapViewOfFile(lpMapAddress);<br> CloseHandle(memfile);<br> }<br> }<br> return Result;<br>}<br>DWORD _stdcall keynumber()<br>{<br>DWORD number;<br>number=*((LPDWORD) lpMapAddress);<br>return number;<br>}<br>数据共享应用内存映射文件来完成,以上代码hook好使,但数据共享不管用,不知为何?