无法将参数从 char[#] 转换为 LPWSTR [英] cant convert parameter from char[#] to LPWSTR

查看:40
本文介绍了无法将参数从 char[#] 转换为 LPWSTR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 Visual C++ 中编译此代码时,出现以下错误.可以帮我解决这个问题..

When I compile this code in Visual C++, I got the below error. Can help me solve this issue..

DWORD nBufferLength = MAX_PATH;
char szCurrentDirectory[MAX_PATH + 1];
GetCurrentDirectory(nBufferLength, szCurrentDirectory); 
szCurrentDirectory[MAX_PATH +1 ] = '\0';

错误信息:

Error   5   error C2664: 'GetCurrentDirectoryW' : cannot convert parameter 2 from 'char [261]' to 'LPWSTR'  c:\car.cpp

推荐答案

您的程序被配置为编译为 unicode.这就是为什么 GetCurrentDirectory 是 GetCurrentDirectoryW,它需要一个 LPWSTR (wchar_t*).

Your program is configured to be compiled as unicode. Thats why GetCurrentDirectory is GetCurrentDirectoryW, which expects a LPWSTR (wchar_t*).

GetCurrentDirectoryW 需要 wchar_t 而不是 char 数组.您可以使用 TCHAR 执行此操作,它与 GetCurrentDirectory 类似,取决于 unicode 设置并始终表示适当的字符类型.

GetCurrentDirectoryW expects a wchar_t instead of char array. You can do this using TCHAR, which - like GetCurrentDirectory - depends on the unicode setting and always represents the appropriate character type.

不要忘记在 '\0' 前面加上 L 以便使字符文字也成为 unicode!

Don't forget to prepend your '\0' with an L in order to make the char literal unicode, too!

这篇关于无法将参数从 char[#] 转换为 LPWSTR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆