Hi guys, i've been facing this problem with my winAPI32 program.
this is the infamous code
Code:
#include <windows.h>
HWND gMainWnd = 0;
HINSTANCE gAppInst = 0;
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmdLine, int showWnd)
{
const char* className = "RTS-test";
gAppInst = hInstance;
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = gAppInst;
wc.hIcon = ::LoadIcon(0, IDI_APPLICATION);
wc.hCursor = ::LoadCursor(0, IDC_ARROW);
wc.lpszMenuName = 0;
wc.lpszClassName = className;
if(RegisterClass(&wc) == 0)
{
MessageBox(0, "RegisterClass(&wc) function failed.", "Critical error", MB_OK);
return 0;
}
gMainWnd = ::CreateWindow(className, "CAPTION HERE", WS_OVERLAPPED, 0, 0, 500, 500, 0, 0, gAppInst, 0);
if(gMainWnd == 0)
{
MessageBox(0, "CreateWindow function failed.", "Critical error.", MB_OK);
return 0;
}
ShowWindow(gMainWnd, showWnd);
UpdateWindow(gMainWnd);
MSG msg;
ZeroMemory(&msg, sizeof(MSG));
while(GetMessage(&msg, 0, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
when I debug it, the
Code:
MessageBox(0, "RegisterClass(&wc) function failed.", "Critical error", MB_OK);
pops up, then moving the mouse a little gives me this:
http://img356.imageshack.us/img356/1813/errorey1.gif
i'm working on Microsoft Visual Studio 2005 pro
what gives?