Jump to content
  • Advertisement
Sign in to follow this  
BattleMetalChris

Why does my win32 application terminate early?

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

This is driving me insane.

I've had some time off my main project, - my own DX10 rendering system comprising some 20,000 lines of code - and have this week come back to it.

I've found it's (for no reason I can work out) terminating around 15 seconds into execution. With some murderous application of comment tags, I've stripped the entire thing back to just window creation and message loop in one main.cpp file (I've commented out all the preprocessor lines in there too) and it's STILL doing it.

It's not a quit message - I've placed breakpoints after the message loop terminates and it never reaches them.

For what it's worth, this is the current program as it's currently set to compile, in it's entirety:




#include <windows.h>



LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);


int g_clientWidth = 800;
int g_clientHeight = 600;


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int showCmd)
{

WNDCLASS wc;

wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)::GetStockObject(BLACK_BRUSH);
wc.hCursor = ::LoadCursor(0, IDC_ARROW);
wc.hIcon = ::LoadIcon(0, IDI_APPLICATION);
wc.hInstance = hInstance;
wc.lpfnWndProc = WinProc;
wc.lpszClassName = "Poo\n";
wc.lpszMenuName = NULL;
wc.style = CS_HREDRAW | CS_VREDRAW;

RegisterClass(&wc);

HWND hWnd = 0;
hWnd = ::CreateWindow(wc.lpszClassName, "Caption", WS_POPUP, 0, 0, g_clientWidth, g_clientHeight, NULL, NULL, hInstance, 0);
ShowWindow(hWnd, showCmd);
UpdateWindow(hWnd);


MSG msg;
ZeroMemory(&msg, sizeof(MSG));

while (msg.message != WM_QUIT)
{
if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
// game loop

}
}
MessageBox(0, "Finished", "FPS", MB_OK);
return 0;
}



LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;

case WM_KEYDOWN:
switch (LOWORD(wParam))
{
case VK_ESCAPE:

DestroyWindow(hWnd);
return 0;

}
break;

}
return DefWindowProc(hWnd, msg, wParam, lParam);
}




Does anyone have ANY idea how I might go about getting to the bottom of this? Various attempts at googling just find tutorials about terminating an application, not ways of stopping it terminating.

Share this post


Link to post
Share on other sites
Advertisement
Have you tried taking a working example of the basic window and build on that. If you can get that working, you can start comparing the code and find out what is happening.

You could also, if you are using Visual Studio, use Spy++ (under the Tools menu) to record all the messages that are send to your application. By looking at what happens before your application terminates you might be able to find out the cause of the sudden exit.

Hope that helps.

Share this post


Link to post
Share on other sites
I don't think it's a code issue, I think it's a problem with VS2010.

Even a new, empty project with just

#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int showCmd)
{
MessageBox(0, "Hello World!", "Message", MB_OK);
}


which is about the simplest Win32 program I can think of, does exactly the same thing. The message box appears for about 15 seconds, then the program exits. Messageboxes are modal, so I don't think there's any message that my application can send which would cause it to exit.

I'm trying a reinstall.

Share this post


Link to post
Share on other sites
Make sure you don't have malware ;-)

(Malware, by the way, potentially includes many half-ass "antivirus" programs that do more harm than good IMHO.)

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!