无法将参数 1 从“WCHAR [100]”转换为“char *”

本文介绍了在MFC编程中遇到的类型转换问题,即如何从`WCHAR [100]`安全地转换为`char *`。通过使用`wcscpy_s`函数,可以实现字符串的正确复制,例如`wcscpy_s(szWindowClass, L"xxxxxxx");`。建议读者查阅MSDN获取更多详细信息。" 137916302,7337247,微信小程序在线点餐系统设计与算法详解,"['微信小程序', '点餐系统', '移动支付', '推荐算法', 'Python开发']
摘要由CSDN通过智能技术生成

使用window提供的wcscpy_s 可以解决

errno_t wcscpy_s(
   wchar_t *strDestination,
   size_t numberOfElements,
   const wchar_t *strSource 
);

例如:

WCHAR szWindowClass[MAX_LOADSTRING]; 

  wcscpy_s(szWindowClass, L"xxxxxxx"); //把“xxxxxxx” copy到szWindowClass。

 

有兴趣的,可以详细看如下之前MSDN上的描述:

 

 

strcpy_s, wcscpy_s, _mbscpy_s

 

Copy a string. These are versions of strcpy, wcscpy, _mbscpy with security enhancements as described in Security Enhancements in the CRT.

 
errno_t strcpy_s(
   char *strDestination,
   size_t numberOfElements,
   const char *strSource 
);
errno_t wcscpy_s(
   wchar_t *strDestination,
   size_t numberOfElements,
   const wchar_t *strSource 
);
errno_t _mbscpy_s(
   unsigned char *strDestination,
   size_t numberOfElements,
   const unsigned char *strSource 
);
template <size_t size>
errno_t strcpy_s(
   char (&strDestination)[size],
   const char *strSource 
); // C++ only
template <size_t size>
errno_t wcscpy_s(
   wchar_t (&strDestination)[size],
   const wchar_t *strSource 
); // C++ only
template <size_t size>
errno_t _mbscpy_s(
   unsigned char (&strDestination)[size
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值