c++ - char类型的参数* lpcwstr类型的参数

标签 c++ winapi error-handling

我在c++上收到错误“类型为char的参数*类型为lpcwstr的参数”,该如何修复?

char text[MAX_PATH]= {};
sprintf(text, "Number of Words: %S", computerName);
sprintf(text, "Number of Sentences: %S", userName);
sprintf(text, "Number of Digits: %d", objSystemInfo.dwNumberOfProcessors);
sprintf(text, "Number of Upper Case: %d", bit);
MessageBox(NULL, text , L"Sistem Bilgisi", MB_OK);

最佳答案

MessageBox接收LPCWSTR,您可以将其表示为wchar_t而不是char,并使用wsprintf在wchar_t中进行写入,如下所示:

wchar_t text[MAX_PATH]= {};
wsprintf(text, L"Number of Words: %s", computerName);
wsprintf(text, L"Number of Sentences: %s", userName);
wsprintf(text, L"Number of Digits: %d", objSystemInfo.dwNumberOfProcessors);
wsprintf(text, L"Number of Upper Case: %d", bit);
MessageBox(NULL, text , L"Sistem Bilgisi", MB_OK);

关于c++ - char类型的参数* lpcwstr类型的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27680065/

相关文章:

c++ - 如何在控制台 C++ 应用程序中使用 lib 文件

windows - Windows MSI 可以安装多个包吗?

c - 获取任务栏句柄

node.js - Node 进程即使在使用时也存在

c# - 如何对全局错误处理程序进行单元测试?

c++ - 在 lambda 中访问循环控制变量

c++ - 我找不到 qt-creator 应该制作的 .exe 文件

c++ - 人工神经元程序

winapi - MFTransform 编码器->ProcessInput 返回 E_FAIL

delphi - 用户友好的异常错误delphi