Jump to content
  • Advertisement
Sign in to follow this  
SteveDeFacto

ShowWindow( hWnd, SW_SHOW ); causes my program to crash on windows 7?

This topic is 2838 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

Alright, I had a friend test my program on his Windows 7 machine and when it calls ShowWindow( hWnd, SW_SHOW ); after creating a window the program crashes. I compiled it on windows vista and used a bunch of message boxes for my friend to read so I could pin point the offending line of code. This is the full code I use to create a window:



WNDCLASSEX wcex;
ZeroMemory( &wcex, sizeof( wcex ) );
wcex.cbSize = sizeof( WNDCLASSEX );
wcex.lpfnWndProc = WinProc;
wcex.hInstance = GetModuleHandle( NULL );
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor( NULL, IDC_ARROW );
wcex.lpszClassName = L"DefaultWindowClass";
RegisterClassEx( &wcex );
hWnd = CreateWindow( L"DefaultWindowClass", L"test", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 1024, 768, NULL, NULL, wcex.hInstance, NULL );
UnregisterClass( L"DefaultWindowClass", NULL );
ShowWindow( hWnd, SW_SHOW );



At the very end when I try to show the window it crashes?...

Share this post


Link to post
Share on other sites
Advertisement
Don't unregister the window class while you are still using it. Unregister it at the very end, after the window has been closed. Also, don't just assume that your calls succeeded, always check for errors. MSDN lists the return values on both success and error for all Win32 functions. If you get an error then use GetLastError() to get more information.

Edit: This article shows how get a user friendly error message from GetLastError.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!