无法将光标位置输出到调试字符串 (WIN32)

Cannot output cursor location to debug string (WIN32)

出于某种原因,当我尝试使用以下代码在给定 WIN32 window 中输出鼠标光标的位置时:

//Global Variable
POINT cursorLocation;

// Win32 Windowing subsystem code redacted

LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){

cursorLocation.x = GET_X_LPARAM(lParam);
cursorLocation.y = GET_Y_LPARAM(lParam);

 switch(message){
   case WM_MOUSEMOVE:
   // mouse movement handle
   OutputDebugString(cursorLocation.x + "," + cursorLocation.y);
   OutputDebugString("\n");
   // WM_MOUSEMOVE break
   break;
 }
}

现在,当我 运行 程序并移动鼠标时,控制台会记录以下文本:

a smaller data type has caused a loss of data.
If this was intentional, you should mask the source of the cast with the appropriate bitmask.
For example: char c = (i & 0xFF);
Changing the code in this way will not affect the quality of the resulting optimized code.

我什至尝试将传递给 OutputDebugString 的变量类型转换为 LONG,因为那是 POINT class 中变量的类型并且没有差异。

有谁知道如何将值通过 GET_X_LPARAMGET_Y_LPARAM 传递到调试控制台? 谢谢。

这不是字符串连接,而是将 .x.y 添加到指向 "," 的指针:

cursorLocation.x + "," + cursorLocation.y

改为尝试例如:

char s[256];
sprintf_s(s, "%d,%d", cursorLocation.x, cursorLocation.y);
OutputDebugStringA(s); // added 'A' after @IInspectable's comment, but
                       // using UNICODE and wchar_t might be better indeed                    

字符串连接不适用于整数。 尝试使用 std::ostringstream:

std::ostringstream out_stream;
out_stream << cursorLocation.x << ", " << cursorLocation.y;
OuputDebugString(out_stream.str().c_str());