Visual Studio Watch Window show WClass whenever I debug a simple windows application from its execuatble

0

Here's the code for just displaying a window using WinApi
For ref this code is from here.

#include <windows.h>

const char g_szClassName[] = "myWindowClass";

// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_CLOSE:
            DestroyWindow(hwnd);
        break;
        case WM_DESTROY:
            PostQuitMessage(0);
        break;
        default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
{
    WNDCLASSEX wc;
    HWND hwnd;
    MSG Msg;

    //Step 1: Registering the Window Class
    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style         = 0;
    wc.lpfnWndProc   = WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = g_szClassName;
    wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

    if(!RegisterClassEx(&wc))
    {
        MessageBox(NULL, "Window Registration Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    // Step 2: Creating the Window
    hwnd = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        g_szClassName,
        "The title of my window",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
        NULL, NULL, hInstance, NULL);

    if(hwnd == NULL)
    {
        MessageBox(NULL, "Window Creation Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    // Step 3: The Message Loop
    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }
    return Msg.wParam;
}

Then I open the executable in Visual Studio 2019 with:

cl -Zi example.cpp user32.lib
devenv example.exe

When I run it using F5, I get this in the Watch Window:

NAME = WClass
VALUE = Unable to evaluate the expression. Operation not supported. Unknown error: 0x80070057.

On hovering over the VALUE I get this: The value for this item is stale due to a problem that occurred while evaluating it.
On hovering over the refresh button I get this: The value of this expression may be incorrect. It could not be evaluated because: "
This problem however does not arise when I open a Windows Application Project in Visual Studio and dump this code. In that case, when I build the solution, the Watch Window is empty.

PS: The Program runs properly as expected but I am curious why WClass shows up in Watch Window.

c++
visual-studio
winapi
visual-c++
visual-studio-debugging
asked on Stack Overflow Dec 10, 2020 by Grey

1 Answer

0

The watch window doesn't do anything on its own. The user has to enter a symbol or expression for it to become active.

If your watch window shows an entry with name WClass, then that's an entry you entered. Given the code you provided, there is no symbol with that name, so the debugger cannot evaluate it.

If this is freaking you out, just delete the entry in your watch window. When done, switch to the Autos and Locals window. That's probably what you were looking for anyway.

answered on Stack Overflow Dec 10, 2020 by IInspectable

User contributions licensed under CC BY-SA 3.0