int len =WideCharToMultiByte(CP_ACP,0,m_MsgS,-1,NULL,0,NULL,NULL);
WideCharToMultiByte(CP_ACP,0,m_MsgS,-1,m_ClientSocket.m_szBuffer,len,NULL,NULL );
上面是转换代码,
需要转换的两个变量定义如下
CString m_MsgS;
char m_szBuffer[5096];
编译错误显示
error C2664: 'WideCharToMultiByte' : cannot convert parameter 3 from 'class CString' to 'const unsigned short *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
2 个解决方案
#1
WideCharToMultiByte(CP_ACP,0,
(LPCWSTR)m_MsgS,
#2
//将用户输入的数据从CString转化为char *字符串,即Unicode-->ANSI,并保存到m_ClientSocket.m_szBuffer中
#ifdef UNICODE
int len =WideCharToMultiByte(CP_ACP,0,m_MsgS.GetBuffer(2547),-1,NULL,0,NULL,NULL);
WideCharToMultiByte(CP_ACP,0,m_MsgS,-1,m_ClientSocket.m_szBuffer,len,NULL,NULL );
#else
strncpy(m_szBuffer,m_MsgS.GetBuffer(5095),5095);m_szBuffer[5095]=0;
#endif
#1
WideCharToMultiByte(CP_ACP,0,
(LPCWSTR)m_MsgS,
#2
//将用户输入的数据从CString转化为char *字符串,即Unicode-->ANSI,并保存到m_ClientSocket.m_szBuffer中
#ifdef UNICODE
int len =WideCharToMultiByte(CP_ACP,0,m_MsgS.GetBuffer(2547),-1,NULL,0,NULL,NULL);
WideCharToMultiByte(CP_ACP,0,m_MsgS,-1,m_ClientSocket.m_szBuffer,len,NULL,NULL );
#else
strncpy(m_szBuffer,m_MsgS.GetBuffer(5095),5095);m_szBuffer[5095]=0;
#endif