Error 30 error C2664: 'HANDLE FindFirstFileW(LPCWSTR,LPWIN32_FIND_DATAW)' : 不能将参数 1 从“char [260]”转换为

17 篇文章 1 订阅
8 篇文章 2 订阅

Error 30 error C2664: 'HANDLE FindFirstFileW(LPCWSTR,LPWIN32_FIND_DATAW)' : 不能将参数 1 从“char [260]”转换为“LPCWST

解决方法:

1、把工程设置里去掉UNICODE宏定义

      项目->XXX属性->配置属性->常规->字符集 改为 “未设置” 就去掉了unicode支持,不过应该回报一个警告

 

2、 如果实在找不到也可以在#include <windows.h>之前加上一句
      #undef UNICODE
      来解决

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
在C++ MFC中,当使用Unicode字符集时,函数FindFirstFileW期望的第一个参数类型是LPCWSTR,即宽字符字符串指针。然而,您传递给该函数的参数是std::string类型的对象,这是一个窄字符字符串。因此,编译器会报错,提示无法将参数从std::string转换LPCWSTR。 要解决这个问题,您需要将std::string类型的对象转换为宽字符字符串。有几种方法可以实现这个转换: 1. 使用MultiByteToWideChar函数将窄字符字符串转换为宽字符字符串[^1]。 ```cpp std::string narrowStr = "your narrow string"; int wideStrLength = MultiByteToWideChar(CP_UTF8, 0, narrowStr.c_str(), -1, nullptr, 0); std::wstring wideStr(wideStrLength, L'\0'); MultiByteToWideChar(CP_UTF8, 0, narrowStr.c_str(), -1, &wideStr[0], wideStrLength); ``` 2. 使用CStringA和CStringW进行转换[^2]。 ```cpp std::string narrowStr = "your narrow string"; CStringA narrowCString(narrowStr.c_str()); CStringW wideCString(narrowCString); LPCWSTR wideStr = wideCString; ``` 3. 使用std::wstring_convert进行转换[^3]。 ```cpp #include <locale> #include <codecvt> std::string narrowStr = "your narrow string"; std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter; std::wstring wideStr = converter.from_bytes(narrowStr); LPCWSTR wideStrPtr = wideStr.c_str(); ``` 请注意,以上方法中的每一种都可以将std::string类型的对象转换LPCWSTR类型的宽字符字符串,您可以根据自己的需求选择其中一种方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值