2

I'm trying to add a simple diagnostic output to a C++ UWP shared project akin to System.Diagnostics.Debug.WriteLine in C#. Following the documentation for OutputDebugString here and this solution here I've tried this:

char buf[1024];
sprintf(buf, "frequency = %f", (float)result);
OutputDebugString(buf);

but I get the compiler error

argument of type "char*" is incompatible with parameter of type "LPCWSTR"

How do I fix this?

Community
  • 1
  • 1
dumbledad
  • 16,305
  • 23
  • 120
  • 273

2 Answers2

3

A colleague advised me to add

#include "strsafe.h"

after any pre-compiled headers and then use this code instead

TCHAR buf[1024];
size_t cbDest = 1024 * sizeof(TCHAR);
StringCbPrintf(buf, cbDest, TEXT("frequency = %f"), (float)result);
OutputDebugString(buf);

I also needed to remember to swap the debugger to handle mixed code:

VS2015 screenshot

dumbledad
  • 16,305
  • 23
  • 120
  • 273
  • https://msdn.microsoft.com/en-us/library/windows/desktop/ff381407(v=vs.85).aspx describes when TCHAR is char or wchar_t, etc – Anthony Wieser Nov 14 '16 at 17:01
0

Here is what I use most of the time (notice the "L"):

#include <Windows.h>
OutputDebugString(L"Sarah Connor ?\n");
Jonathan ANTOINE
  • 9,021
  • 1
  • 23
  • 33