unicode中的Wsarecv问题 [英] Wsarecv problem in unicode

查看:64
本文介绍了unicode中的Wsarecv问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 缓冲区永远不会被释放。



最后我不确定你的 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 is WSAECONNABORTED ("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 a CStringA buffer here? Can't you just use Buffer?

Also the CStringA buffer is never released when the receive is succesful.

Finally I'm not sure if your WSABUF 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 (using Buffer here):

WSABUF WSABuf = { nMaxLen, Buffer };


and pass the address of WSABuf to WSARecv.


这篇关于unicode中的Wsarecv问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆