Error message: The variable msg is being used without being initialized.

Building the program worked just fine, but when I try out its debug .exe, I get an error message that says "The variable 'msg' is being used without being initialized."

I have no idea what I'm doing wrong.

Here's the code for it:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "main.h"

//this is a class that initializes the window
Application g_App;

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
	//show window
	g_App.PostWindowToScreen(g_App.GetWindowHandle(), nCmdShow);

	//needed in the main loop
	MSG msg;

	//enter the main loop
	while(g_App.GetWindowStatus()) //the test for this while loop is there to make sure that the window hasn't been exited
    {
        // Check to see if any messages are waiting in the queue
        while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            // translate keystroke messages into the right format
            TranslateMessage(&msg);

            // send the message to the WindowProc function
            DispatchMessage(&msg);
        }

        // If the message is WM_QUIT, exit the while loop
        if(msg.message == WM_QUIT)
            break;

        // Run game code here
        // ...
        // ...
    }

    // return this part of the WM_QUIT message to Windows
    return msg.wParam;
};

Last edited on
PeekMessage() is failing and your if is checking msg.message unconditionally. memset() msg to zero before calling PeekMessage().
What am I supposed to replace the unconditional if loop with?

Thanks.
Last edited on
Topic archived. No new replies allowed.