将char类型的字符数组转换成为wchar_t类型的数组,在线等

zhangjundriver 2008-08-25 08:40:42
WSABUF DataBuf;
DataBuf.buf = new char[200];
DataBuf.len = 200;

DWORD dwRead;
DWORD dwFlag = 0;

SOCKADDR_IN addr_from;
int len = sizeof(SOCKADDR);

CString str;
CString strtemp;
wchar_t charBuf[20];

WSARecvFrom(m_socket,(LPWSABUF)&DataBuf,1,&dwRead,&dwFlag,(SOCKADDR*)&addr_from,&len,NULL,NULL);

charBuf = A2W(inet_ntoa(addr_from.sin_addr));

下面是编译的时候编译错误:错误都是由于A2W宏引起的,郁闷中
c:\documents and settings\administrator\my documents\visual studio 2005\projects\chat\chat\chatdlg.cpp(113) : error C2065: '_lpa' : undeclared identifier
c:\documents and settings\administrator\my documents\visual studio 2005\projects\chat\chat\chatdlg.cpp(113) : error C2065: '_convert' : undeclared identifier
c:\documents and settings\administrator\my documents\visual studio 2005\projects\chat\chat\chatdlg.cpp(113) : error C2065: '_acp' : undeclared identifier
...全文
156 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
vrace 2008-08-26
  • 打赏
  • 举报
回复
char ansiText[] = "Hello";
wchar_t unicodeText[6] = {0};

mbstowcs(unicodeText, ansiText, strlen(ansiText));
Splendour 2008-08-26
  • 打赏
  • 举报
回复
A2W是ATL的宏,需要定义USES_CONVERSION
Splendour 2008-08-26
  • 打赏
  • 举报
回复
使用该API之前添加
USES_CONVERSION;

LPWSTR x= A2W(lpsz)
jia_xiaoxin 2008-08-26
  • 打赏
  • 举报
回复
char* ConvertLPWSTRToLPSTR (LPWSTR lpwszStrIn)
{
LPSTR pszOut = NULL;
if (lpwszStrIn != NULL)
{
int nInputStrLen = wcslen (lpwszStrIn);

// Double NULL Termination
int nOutputStrLen = WideCharToMultiByte (CP_ACP, 0, lpwszStrIn, nInputStrLen, NULL, 0, 0, 0) + 2;
pszOut = new char [nOutputStrLen];

if (pszOut)
{
memset (pszOut, 0x00, nOutputStrLen);
WideCharToMultiByte(CP_ACP, 0, lpwszStrIn, nInputStrLen, pszOut, nOutputStrLen, 0, 0);
}
}
return pszOut;
}

jay的Fans 2008-08-26
  • 打赏
  • 举报
回复
#include <iostream>

using namespace std;

int main()
{
wchar_t wstr[] = {'中' , '国' , '人' , '0'};
size_t len;
len = wcslen(wstr);

char *pcstr = new char[2 * len + 1];
memset(pcstr , 0 , 2 * len + 1);
size_t j = 0;
for(size_t i = 0 ; i != len ; ++i)
{
pcstr[j] = wstr[i] >> 8;
++j;
pcstr[j] = wstr[i];
++j;
}

cout << pcstr << endl;
delete []pcstr;

system("pause");
return 0;
}
linzhang16 2008-08-25
  • 打赏
  • 举报
回复
你这个宏怎么定义的,没贴出来啊

64,318

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧