|
-
Jul 7th, 2002, 05:08 PM
#1
Thread Starter
PowerPoster
System-wide hook
I am trying to install a Shell system-wide hook but because I have to put the application-defined procedure (ShellProc) in a dll, so I have created a simple dll using ATL and so far it's working all right.
Here is the procedure which is in a dll:
PHP Code:
LRESULT WINAPI ShellProc(int nCode, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your implementation code here
switch(nCode)
{
case HSHELL_WINDOWCREATED:
MessageBox(NULL,"","Window Created", MB_OK);
break;
case HSHELL_WINDOWDESTROYED:
MessageBox(NULL,"","Window Destroyed", MB_OK);
break;
default:
break;
}
return CallNextHookEx(hhook, nCode, wParam, lParam);
}
There's also a function called "StartHook" in the same dll which actually sets the the WH_SHELL hook using SetWindowsHookEx(). So whenever I call the StartHook function, I start getting the message boxes above correctly but....
I'll have to perform on the messages (ex HSHELL_WINDOWSCREATED) inside the dll because the procedure is inside the dll. How can the calling thread (or me if I am using this dll) be notified which message is recieved? Will have to write my own for getting the address of a CALLBACK message from the programmer and then call that function from the dll? Or will it actually work?
-
Jul 10th, 2002, 07:49 PM
#2
You created the DLL with ATL???
As for your question: either retrieve a function pointer or a window handle to send messages to (would be passed to StartHook)
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jul 10th, 2002, 08:00 PM
#3
Thread Starter
PowerPoster
I am creating a simple DLL - no COM.
Thanks for the ideas. I guess sending the message to the provided window will be the easiest thing.
I'll try that.
-
Jul 10th, 2002, 08:30 PM
#4
Still, a simple Win32 DLL would be better.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jul 10th, 2002, 09:24 PM
#5
Thread Starter
PowerPoster
Ok, it is working but not quite right. Whenever I recieve a message inside my hook procedure, I simply send two messages to the window hosting the dll (the client).
Here isn't the hook procedure inside the DLL:
PHP Code:
HRESULT DLLEXPORT MyhookProc(int code, WPARAM wParam, LPARAM lParam)
{
SendMessage(hookparent, WM_HOOKMESSAGE, (WPARAM)code, 0);
return SendMessage(hookparent, WM_HOOKMESSAGEPARAMS, wParam, lParam);
}
So in the first message, I send which message was recieved. Then the second message I simply send the wParam and lParam values recieved. Then it's up to the client to either call "CallNextHookEx" or block the message. That's why I am returning the value I get from sending WM_HOOKMESSAGEPARAMS. Everything sounds good so far...
In my actual program, I install a hook of type WH_KEYBOARD. It says it installed the hook correctly and then I also recieve a WM_HOOKMESSAGE from the dll to my window procedure telling me about a key pressed. Here's the code I am using two handle about two messages:
PHP Code:
case WM_HOOKMESSAGE:
msghook = (int)wParam; //Store the message
return 0;
case WM_HOOKMESSAGEPARAMS:
// MessageBox(NULL,"Message Recieved","hello",MB_OK);
if ((msghook == HC_ACTION) || (msghook == HC_NOREMOVE))
{
MessageBox(NULL,"Key pressed","hello",MB_OK);
}
return CallNextHookEx(hhk, msghook, wParam, lParam);
I am simply checking if a key is pressed or not. Whenever I press a key I recieve a message saying "Message Recieved" ONLY while my window has the focus although I installed a system-wide hook which is supposed to monitor every thread's message. I also see a message saying "Key pressed" so it means my message value (recieved from the DLL) is wrong. What's going wrong with it?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|