Thread: WM_QUIT return values

  1. #1
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401

    WM_QUIT return values

    In my program, under WM_DESTROY, I use PostQuitMessage(0). After my message loop, in WinMain(), I return msg.wParam. The exit code for my program however, is always -1080664280 (0xBF965F28). Is this behaviour normal? According to MSDN my exit code should be 0.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Should be zero. Post up the code and we'll have a look.

  3. #3
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Here's the important stuff, should be enough:

    Code:
    LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
    {
    	switch (msg)
    	{
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		return 0;
    Code:
    while (GetMessage(&msg,hwnd,0,0)>0)
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    
    	return msg.wParam;
    Code:
    The thread 0x170 has exited with code -1080664280 (0xBF965F28)
    I've confirmed that it IS exiting through WM_DESTROY.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Put a breakpoint on the return statement. Look at the msg structure. What msg does it have? It should be 0x12 or 18 ( decimal ). Everything else should be 0.

  5. #5
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    The message is 0! Weird. I think it may be because my message loop will exit if GetMessage() doesn't return a positive value. Eibro told me to change this. I'll try it and see.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  6. #6
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    I added the following check to my loop:

    Code:
    while ((bRet=GetMessage(&msg,hwnd,0,0))!=0)
    	{
    		if (bRet==-1)
    			exit(1);
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    
    	return msg.wParam;
    And sure enough it exited with code 1. Apparently that means there's some horrible error like hwnd being invalid. Could that be possible in this case?
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  7. #7
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    If it returns -1 call GetLastError() and see what that says.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. can some one please tell me the cause of the error ?
    By broli86 in forum C Programming
    Replies: 8
    Last Post: 06-26-2008, 08:36 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. Algorithm to walk through a maze.
    By Nutshell in forum C Programming
    Replies: 30
    Last Post: 01-21-2002, 01:54 AM