Jump to content
  • Advertisement
Sign in to follow this  

Windows API Problem

This topic is 5135 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!