Sign in to follow this  
kernkraft

Windows API Problem

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 structure
this->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® system
RegisterClassEx(&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?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this