![]() |
| | #1 |
| Registered User Join Date: Jul 2002
Posts: 3
| HHOOK hKeyboardHook = NULL; int i = 0; LRESULT CALLBACK KeyboardHookProc(int code, WPARAM wParam, LPARAM lParam) { if (code < 0) return CallNextHookEx(hKeyboardHook, code, wParam, lParam); if (i = 0) { MessageBox(NULL, "ERROR, DATA NOT COMMUNICATED", "ERROR", 0); } return 0; } extern "C" HHOOK CFHookKeyboard(void) { if (!hKeyboardHook) hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD, KeyboardHookProc, (HINSTANCE)hMod, 0); i = 1; return hKeyboardHook; } Anyone knows of any fix? |
| junbin is offline | |
| | #2 |
| &TH of undefined behavior Join Date: Aug 2001
Posts: 5,183
| The problem you have is that each dll will have a seperate copy of hKeyboardHook......in the process of the app that creates the hook, it will be valid, but in all other instances if will be void........ Many compilers offer a global memory option for dlls - kind of like a static variable in a c++ class - you can have as many dlls running in the system as you need, but they all refer to one area of system memory.....in that shared area, you place the HHOOK For VC++ you use; Code: #pragma data_seg(".syshook") //Set shareable segment
HHOOK hKeyboardHook = NULL; //Handle to my hook
#pragma data_seg()
#pragma comment(linker, "/section:.syshook,rws")
Also add to this that the hook procedure (when called) exists in another process.........that means all shared handles (file...etc) are unusable (and you cant share them accross process boundries as you dont have a list of the processes that need them)...they way I get around this is for the launching app to open a MailSlot (CreateMailSlot()) and then create a thread to recieve messages......then I use CreateFile() in the hook dll to get a handle to the Mailslot (which is usable in my process) and write output to it.......
__________________ "If A is success in life, then A equals x plus y plus z. Work is x; y is play; and z is keeping your mouth shut." Albert Einstein (1879 - 1955) Board Rules |
| Fordy is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Simulate Keys with a Keyboard Hook | guitarist809 | Windows Programming | 3 | 11-14-2008 08:14 PM |
| Code review | Elysia | C++ Programming | 71 | 05-13-2008 09:42 PM |
| get keyboard and mouse events | ratte | Linux Programming | 10 | 11-17-2007 05:42 PM |
| Linking errors with static var | Elysia | C++ Programming | 8 | 10-27-2007 05:24 PM |
| Warnings, warnings, warnings? | spentdome | C Programming | 25 | 05-27-2002 06:49 PM |