unicode中的Wsarecv问题 [英] Wsarecv problem in unicode
问题描述
WSARecv正在ansi工作,但它不能用于unicode
CStringA str(缓冲区);
WSABUF WSABuf [] = {nMaxLen,str.GetBuffer()};
if(!:: WSARecv(m_hSocket, WSABuf,1,& dwBytesRecv,& dwFlags,NULL,NULL))
return(int)dwBytesRecv;
str.ReleaseBuffer ();
Pleaese让我知道可能是什么问题。
我尝试了什么:
WSARecv返回10053错误,但是它在ansi
关于发布的代码片段,ANSI和Unicode版本之间应该没有区别。错误10053是WSAECONNABORTED
(已建立的连接已被主机中的软件中止。)。因此错误源可能在此处未显示的代码部分中的其他位置。
但是为什么要使用CStringA
缓冲在这里?难道你不能只使用缓冲区
?
另外CStringA $ c当接收成功时,$ c>缓冲区永远不会被释放。
最后我不确定你的WSABUF
array initilisation可以这种方式使用(它是一个带有两个初始元素的结构数组)。要在保存方面,你应该使用(在这里使用缓冲区
):
WSABUF WSABuf = {nMaxLen,Buffer} ;
并将WSABuf
的地址传递给WSARecv
WSARecv is working in ansi but its not working in unicode
CStringA str(Buffer);
WSABUF WSABuf[] = { nMaxLen, str.GetBuffer() };
if ( !::WSARecv(m_hSocket, WSABuf, 1, &dwBytesRecv, &dwFlags, NULL, NULL) )
return (int)dwBytesRecv;
str.ReleaseBuffer();
Pleaese let me know what might be the problem.
What I have tried:
WSARecv is returning 10053 error but its working in ansi
There should be no difference between ANSI and Unicode builds regarding the posted code snippet. Error 10053 isWSAECONNABORTED
("An established connection was aborted by the software in your host machine."). So the error source might be somewhere else in code portions not shown here.
But why you are using aCStringA
buffer here? Can't you just useBuffer
?
Also theCStringA
buffer is never released when the receive is succesful.
Finally I'm not sure if yourWSABUF
array initilisation can be used that way (it is an array of a struct with two initial elements). To be on the save side you should use (usingBuffer
here):
WSABUF WSABuf = { nMaxLen, Buffer };
and pass the address ofWSABuf
toWSARecv
.
这篇关于unicode中的Wsarecv问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!