Thank you for the link! However, I think that I have fallen onto a Windows thread hook instead. This seems to me, the best way to simulate event driven programming for win32 C. But, unfortunently, I really am not very good with Windows hooks! Here is the code that I currently have, problems I encountered below:
Code:
#define _WIN32_WINNT 0x0400
#include <windows.h>
#include <iostream>
#include <string>
using namespace std;
HHOOK hKeywait; // The keyboard hook var
string s = "aaa"; // "Bruteforce" string
LRESULT CALLBACK FilterFunction(int nCode, WORD wParam, DWORD lParam) {
cout << s << endl;
// This is a test and it appears
// this proc is never actually being
// called. Shouldn't the hook be
// doing something to get us here??
if (wParam == WM_KEYDOWN)
{
}
return CallNextHookEx(hKeywait, nCode, wParam, lParam);
}
DWORD WINAPI Generator(void *Params) {
// Function runs in a thread, creating
// all combo's of a string a-z for length
// of the global "bruteforce" variable
int i = 0;
int length = s.length();
while(s[i]++)
{
while(s[i] == 'z' + 1) {
s[i] = 'a';
s[++i]++;
}
if(i == length) { break; }
i = 0;
}
return 0;
}
void MsgLoop()
{
// This code spins about spitting messages
// everywhere. Will the WM_KEYDOWN message
// ever get to the FilterProc? I dunno
MSG message;
while (GetMessage(&message,NULL,0,0)) {
TranslateMessage( &message );
DispatchMessage( &message );
}
}
int main(int argc, char* argv[]) {
DWORD dwThread;
HANDLE hThread;
hThread = CreateThread
(NULL, NULL, Generator,
(void*) 0, NULL, &dwThread);
hKeywait = SetWindowsHookEx (
WH_KEYBOARD, // Local process keyboard thread hook
(HOOKPROC) FilterFunction, // "Hook proc", which confuses me
(HINSTANCE) NULL, // Null, hook proc isn't in DLL mod
(DWORD) hThread ); // Thee local thread to hook from
MsgLoop();
UnhookWindowsHookEx(hKeywait);
return 0;
}
Well, this code might look familiar to what is described in a NewOrder article about a keylogger here: http://neworder.box.sk/newsread.php?newsid=10952 because a lot of the topics seem fairly relevent (even though my goal is hardly a keylogger here). So, my problem here, is that it does not seem we ever actually get to my filter procedure, however from what I was lead to believe (I probably read the diagram wrong) from this image: http://msdn.microsoft.com/library/en.../hooks32_1.gif is that the hook add's the FilterProc to the chain, and starts being executed and such.
I'm probably wrong in my interpretation here, and I don't really know what I'm doing. Any help is much appreciated.