|
-
Feb 14th, 2002, 03:09 PM
#1
Fhooking hooks!
Hi all,
I'm just trying to make a program that hooks all keystrokes and displays them in a console window. I only
learnt how to use DLLs today so I not very good yet.
Hears my code, I didn't expect it to work and it didn't, any ideas why?:
The DLL:
#include <iostream.h>
#include "stdafx.h"
LRESULT CALLBACK FilterFunc(int nCode, WPARAM wparam,LPARAM lParam)
{
MessageBox (NULL, "IT WORKS!" , "WORKS!", 0 + MB_ICONQUESTION);
return CallNextHookEx(NULL, nCode, wparam , lParam);
}
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
The APP:
//#pragma hdrstop
//#include <condefs.h>
#include <iostream.h>
#include <conio.h>
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
HINSTANCE dllres;
HOOKPROC adss;
HHOOK setres;
cout << GetLastError() << endl;
dllres = LoadLibrary("hook.dll");
cout << GetLastError();
if(dllres != NULL)
{
adss = (HOOKPROC)GetProcAddress(dllres, "FilterFunc");
setres = SetWindowsHookEx(WH_KEYBOARD, adss, dllres, 0);
if(setres == NULL )
cout << "Yeah, it is shagged ";
}
else
cout << "Error loading hook.dll";
getch();
return 0;
}
P.S I dose compile 
Thanks in advance
-Jon
-
Feb 14th, 2002, 03:57 PM
#2
Check if GetProcAddress returns a valid address. If not, you might need to add a .def file to the dll (search the forum)
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.
-
Feb 14th, 2002, 05:56 PM
#3
Wow, thanks mate
I added a .def file and set that up for my callback function and everything worked perfectly!
I don't surpose anyone knows a good way of relaying the hook codes back to my app do you?
Thanks again
jOn
-
Feb 15th, 2002, 12:43 PM
#4
You could create an InitDll function where you give the dll a hwnd where it should post notification messages. But I don't know if the global hook is executed in the processes address space, so you must watch out where you store the hwnd.
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.
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
|