类型“char *”的参数与类型“LPWSTR”的参数不兼容。 [英] Argument of type "char *" is incompatible with parameter of type "LPWSTR"
本文介绍了类型“char *”的参数与类型“LPWSTR”的参数不兼容。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这可能已经问过,但我似乎找不到解决方案:
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?
推荐答案
您需要使用ansi版本:
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);
}
或使用unicode:
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);
}
不是明确调用A / W版本,并将整个项目配置为使用ansi / unicode。所有这些都是更改一些#defines替换foo与fooA / W。
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.
请注意,你应该使用_countof()避免不正确的大小,取决于缓冲区类型。
Notice that you should use _countof() to avoid incorrect sizes depending on the buffers type too.
这篇关于类型“char *”的参数与类型“LPWSTR”的参数不兼容。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文