char 类型与lpcwstr,类型“char *”的参数与类型“LPWSTR”的参数不兼容。
发布日期:2022-03-15 11:50:03 浏览次数:22 分类:技术文章

本文共 1107 字,大约阅读时间需要 3 分钟。

This has probably been asked before but I can't seem to find the solution:

std::string GetPath()

{

char buffer[MAX_PATH];

::GetSystemDirectory(buffer,MAX_PATH);

strcat(buffer,"\\version.dll");

return std::string(buffer);

}

This returns an error stating:

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

So yeah. Anyone got an answer?

解决方案

You need to use the ansi version:

std::string GetPath()

{

char buffer[MAX_PATH] = {};

::GetSystemDirectoryA(buffer,_countof(buffer)); // notice the A

strcat(buffer,"\\version.dll");

return std::string(buffer);

}

Or use unicode:

std::wstring GetPath()

{

wchar_t buffer[MAX_PATH] = {};

::GetSystemDirectoryW(buffer,_countof(buffer)); // notice the W, or drop the W to get it "by default"

wcscat(buffer,L"\\version.dll");

return std::wstring(buffer);

}

Rather than call the A/W versions explicitly you can drop the A/W and configure the whole project to use ansi/unicode instead. All this will do is change some #defines to replace foo with fooA/W.

Notice that you should use _countof() to avoid incorrect sizes depending on the buffers type too.

转载地址:https://blog.csdn.net/weixin_34614004/article/details/118813848 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:利用计算机说话,科学网-刘瑞祥:怎样利用VBA或者VBS让计算机说话-孙冰的博文...
下一篇:尝试重新启动计算机和应用程序 错误4,win10开机提示登录组件错误4 请重新启动电脑管家怎么办...

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2024年04月07日 14时15分49秒