首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

unicode有关问题,

2012-02-13 
unicode问题,急!!!!!!!voidCWinQQDlg::ProcessReceive(CClientSocket*pSocket){wchar_tbuffer[BUFFER_SIZE

unicode问题,急!!!!!!!
void   CWinQQDlg::ProcessReceive(CClientSocket*   pSocket)
{
wchar_t   buffer[BUFFER_SIZE];

int   nReceived=pSocket-> Receive(buffer,BUFFER_SIZE,0);

buffer[nReceived]=0;


CString   temp;
temp.Format(_T( "%s "),buffer);

m_Msg.AddString(temp);


}

void   CWinQQDlg::SendMsg(CString   strMsg)
{
CString   str;
str.Format(_T( "%s:%s "),m_Name,strMsg);
wchar_t*   p=str.GetBuffer(0);
m_pClient-> Send(p,str.GetLength(),0);
}

发送的wchar_t数组在接收端的值是不对的,socket传输应该不会出错吧?但为什么接收的值跟传输的值不一样呢?求解决方法(必须使用unicode)编码。

[解决办法]
工程使用UNICODE编译
[解决办法]
_MDBCS改成 _UNICODE,UNICODE

link页加上wWinMainCRTStartup
[解决办法]
void CWinQQDlg::SendMsg(CString strMsg)
{

m_pClient-> Send(p,str.GetLength() * sizeof(WCHAR),0);
}
这样试试呢
[解决办法]
void CWinQQDlg::ProcessReceive(CClientSocket* pSocket)
{
wchar_t buffer[BUFFER_SIZE];
int nReceived=pSocket-> Receive(buffer,BUFFER_SIZE * 2,0);
CString temp;
temp.Format(_T( "%s "),buffer);
m_Msg.AddString(temp);
}

void CWinQQDlg::SendMsg(CString strMsg)
{
CString str;
str.Format(_T( "%s:%s "),m_Name,strMsg);
wchar_t* p=str.GetBuffer(0);
m_pClient-> Send(p,(str.GetLength() + 1) * 2, 0); //这里发送发送结束符,所以加1
//如果不发送结束符,在接收端将会更难处理!
}
[解决办法]
发送前转成CHAR.
<windows网络编程> 第七章:
必须牢牢记住这一点:所有关系到收发数据的缓冲都属于简单的c h a r类型。也就是说,这
些函数没有“U n i c o d e”版本。这一点对Windows CE来说尤为重要,因为Windows CE默认使
用U n i c o d e。使用U n i c o d e时有一种选择,即把字符串当作c h a r *或把它造型为c h a r *发送。需要
注意的是,在利用字符串长度函数告诉Winsock API函数收发的数据有多少字符时,必须将这
个值乘以2,因为每个字符占用字串组的两个字节。另一种选择是在将字串数据投给Wi n s o c k
A P I函数之前,用Wi d e C h a r To M u l t i B y t e把U N I C O D E转换成A S C I I码。

热点排行