Windows API Problem

Started by
2 comments, last by kernkraft 19 years, 7 months ago
I've been working on a new project recently and I've had problems with the HINSTANCE passed to my program in my WinMain() function. Earlier on, ALL the arguments passed to me by Windows were garbage. Now, after fixing a couple of mistakes, they're good values (I've tested it) but Windows refuses to register a window to my HINSTANCE through RegisterClassEx(). I verified my code dozens of time, comparing to previous projects that worked fine with the same code, still no solution... Then I started using the GetLastError() function at each Windows API-related lines to see what the problem was. RegisterClassEx() gives me "Parameter is incorrect.". Just for fun, I put GetLastError() as the first line of WinMain(). It gives me "Handle invalid.". Help please! I've spent days on this darn problem. I don't understand how windows could send me an instance and then refuse to create a window with it.
Advertisement
Can you post the source code so we can have a look over it
I seriously doubt the error is with the HINSTANCE value, as for virtually all exe's that will be 0x400000. It more than likely has to do with the window class you are registering. Oh, and even in a perfectly working program, the last windows error code is undefined until you call a Win32 function. That is, a perfectly working program could have a non-zero last windows error code when it jumps into your WinMain.

.
Doh! Stupid me, I should have included the source code in the first place. Forgot to do so. Here it is:

Source code registering my window:
// Fill in the WNDCLASSEX structurethis->m_oWndClass.lpszClassName		= ToWChar(this->m_pWndInfo->m_sCaption);this->m_oWndClass.cbSize			= sizeof(WNDCLASSEX);this->m_oWndClass.style			= CS_HREDRAW | CS_VREDRAW;this->m_oWndClass.lpfnWndProc		= CallWndProc;//this->m_oWndClass.hInstance		= pInstance;this->m_oWndClass.hCursor			= LoadCursor(Null, IDC_ARROW);this->m_oWndClass.hbrBackground		= (HBRUSH)GetStockObject(WHITE_BRUSH);this->m_oWndClass.lpszMenuName		= Null;this->m_oWndClass.cbClsExtra		= Null;																				// Of no use.this->m_oWndClass.cbWndExtra		= sizeof(this);																		// This is the amount of memory that Windows® uses to allocate the 'Per-Window Data'. Kinda like a tag property.// Register CWnd with Windows® systemRegisterClassEx(&this->m_oWndClass);


Thanks for the insight Mastaba, I was wondering why the hell I had the same handle every time :). By removing the line where I fill in the hInstance object of WNDCLASSEX, I was able to register my window! But it is still kludged...Any thoughts?

This topic is closed to new replies.

Advertisement