How to view printf output in a Win32 application on Visual Studio 2010?

0

Issue

How can you view printf output in a Win32 application (entering with a WinMain) in Visual Studio 2010?

Solution

Edit 2021, Visual Studio 2019

To write debug messages to the Output window use the OutputDebugStringA from debugapi.h (include windows.h)

test.c

#include <windows.h>
#include <stdio.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdShow, int nCmdShow)
{
    int number = 10;
    char str[256];
    sprintf_s(str, sizeof(str), "It works! - number: %d \n", number);

    OutputDebugStringA(str);

    return 0;
}

Tested on Visual Studio 2019, Debug / x64.

Or alternatively utilize my drop-in header file.

Answered By – rbento

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More