Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print in a Windows Universal C++ project

I feel so dumb asking this question but honestly I can't understand why System namespace can't be used! What am I doing wrong? Is there any other way to print a single line in the output? (I am using Visual Studio 2015)

like image 784
GTS Avatar asked Oct 13 '15 12:10

GTS


2 Answers

I can't understand why System namespace can't be used

Windows Universal app is totally different with traditional desktop app, please check Windows Runtime APIs and Win32 and COM API which lists all Win32 and COM APIs supported for use in UWP apps.

Is there any other way to print a single line in the output? (I am using Visual Studio 2015)

If you need to print message to Output window, use OutputDebugString function in UWP C++/CX project, adding #include to access it, for example:

void CPPUWPApp1::MainPage::LogMessage(Object^ parameter)
{
    auto paraString = parameter->ToString();
    auto formattedText = std::wstring(paraString->Data()).append(L"\r\n");
    OutputDebugString(formattedText.c_str());
}

Usage:

LogMessage("Hello World!");
like image 106
Franklin Chen - MSFT Avatar answered Nov 12 '22 22:11

Franklin Chen - MSFT


You could do this directly:

OutputDebugString(L"Hello World");

Notice the L in front of the string, to convert it directly to LPCWSTR.

like image 1
Tudor Avatar answered Nov 12 '22 22:11

Tudor