怎么用WSAGetLastError ?

聆心雨落 2009-05-09 07:05:58
我做的程序,调试没有问题,但就是不执行结果,怎么解决啊?我做的是屏幕截图,就是出现不了屏幕图像。
我看到好多说 用 WSAGetLastError 检测的,怎么用的,怎么才能知道错误呢?谢谢了
...全文
3480 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
麻浦区保安 2012-03-08
  • 打赏
  • 举报
回复
o 哦哦懂了!!
狂妄Beyond 2010-05-05
  • 打赏
  • 举报
回复
必须在加载winsock后,该函数才起作用
flyuniverse_shell 2009-09-02
  • 打赏
  • 举报
回复 1
switch (WSAGetLastError())
{
case WSANOTINITIALISED:
TRACE("A successful WSAStartup call must occur before using this function. ");
break;
case WSAENETDOWN:
TRACE("The network subsystem has failed. ");
break;
case WSAEACCES:
TRACE("The requested address is a broadcast address, but the appropriate flag was not set. Call setsockopt with the SO_BROADCAST parameter to allow the use of the broadcast address. ");
break;
case WSAEINVAL:
TRACE("An unknown flag was specified, or MSG_OOB was specified for a socket with SO_OOBINLINE enabled. ");
break;
case WSAEINTR:
TRACE("A blocking Windows Sockets 1.1 call was canceled through WSACancelBlockingCall. ");
break;
case WSAEINPROGRESS:
TRACE("A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function. ");
break;
case WSAEFAULT:
TRACE("The buf or to parameters are not part of the user address space, or the tolen parameter is too small. ");
break;
case WSAENETRESET:
TRACE("The connection has been broken due to keep-alive activity detecting a failure while the operation was in progress. ");
break;
case WSAENOBUFS:
TRACE("No buffer space is available. ");
break;
case WSAENOTCONN:
TRACE("The socket is not connected (connection-oriented sockets only). ");
break;
case WSAENOTSOCK:
TRACE("The descriptor is not a socket. ");
break;
case WSAEOPNOTSUPP:
TRACE("MSG_OOB was specified, but the socket is not stream-style such as type SOCK_STREAM, OOB data is not supported in the communication domain associated with this socket, or the socket is unidirectional and supports only receive operations. ");
break;
case WSAESHUTDOWN:
TRACE("The socket has been shut down; it is not possible to sendto on a socket after shutdown has been invoked with how set to SD_SEND or SD_BOTH. ");
break;
case WSAEWOULDBLOCK:
TRACE("The socket is marked as nonblocking and the requested operation would block. ");
break;
case WSAEMSGSIZE:
TRACE("The socket is message oriented, and the message is larger than the maximum supported by the underlying transport. ");
break;
case WSAEHOSTUNREACH:
TRACE("The remote host cannot be reached from this host at this time. ");
break;
case WSAECONNABORTED:
TRACE("The virtual circuit was terminated due to a time-out or other failure. The application should close the socket as it is no longer usable. ");
break;
case WSAECONNRESET:
TRACE("The virtual circuit was reset by the remote side executing a hard or abortive close. For UPD sockets, the remote host was unable to deliver a previously sent UDP datagram and responded with a \"Port Unreachable\" ICMP packet. The application should close the socket as it is no longer usable. ");
break;
case WSAEADDRNOTAVAIL:
TRACE("The remote address is not a valid address, for example, ADDR_ANY. ");
break;
case WSAEAFNOSUPPORT:
TRACE("Addresses in the specified family cannot be used with this socket. ");
break;
case WSAEDESTADDRREQ:
TRACE("A destination address is required. ");
break;
case WSAENETUNREACH:
TRACE("The network cannot be reached from this host at this time. ");
break;
case WSAETIMEDOUT:
TRACE("The connection has been dropped, because of a network failure or because the system on the other end went down without notice. ");
break;
default:
TRACE("Unknown socket error. ");
break;
一条晚起的虫 2009-05-09
  • 打赏
  • 举报
回复
http://msdn.microsoft.com/en-us/library/ms741580(VS.85).aspx

最好的函数手册 MSDN
在线的 msdn.microsoft.com/en-us
一条晚起的虫 2009-05-09
  • 打赏
  • 举报
回复
if(socket失败)
{
DWORD dwError = WSAGetLastError();
}
  • 打赏
  • 举报
回复
先学会知道socket是否失败
聆心雨落 2009-05-09
  • 打赏
  • 举报
回复
//在socket函数失败之后,调用WSAGetLastError判断具体错误//

应该怎么调用呢?

我发现我真的什么都不会,谢谢大家的帮助了,我真的很想努力的解决问题
一条晚起的虫 2009-05-09
  • 打赏
  • 举报
回复
但就是不执行可能是什么原因呢
//如果是多线程的,可能涉及线程同步问题。

在socket函数失败之后,调用WSAGetLastError判断具体错误
WaistCoat19 2009-05-09
  • 打赏
  • 举报
回复
判断函数返回值,如果失败了离开调用WSAGetLastError
聆心雨落 2009-05-09
  • 打赏
  • 举报
回复
把这句话放在哪里呢?

还有调试的时候没有问题,但就是不执行可能是什么原因呢?我现在做的是屏幕抓图,涉及到套接字,不知道是不是套接字的问题。
ouyh12345 2009-05-09
  • 打赏
  • 举报
回复
if( 0 > send(...))
{
printf("send error:%d\n", WSAGetLastError);
//错误处理
}
聆心雨落 2009-05-09
  • 打赏
  • 举报
回复
我就是想获取socket错误,可是我不知道怎么用?
WaistCoat19 2009-05-09
  • 打赏
  • 举报
回复
WSAGetLastError是获取Socket错误的。

如果普通API函数调用失败后应该调用GetLastError。
在用pb开发信息管理系统时,为了安全期间,我们希望记录每个登录用户的信息,并生成日志,其中最重要的是知道是哪个机器运行程序的?这样,只要获取运行程序的机器ip问题就解决了,然而,pb中没有象delphi 中有现成的函数可以很方便的获的机器的ip,我们只好利用外部函数来实现了。 首先声明外部函数 function int WSAStartup( uint UIVersionRequested, ref s_WSAData lpWSAData ) library "wsock32.dll" function int WSACleanup() library "wsock32.dll" function int WSAGetLastError ( ) library "wsock32.dll" function int gethostname ( ref string name, int namelen ) library "wsock32.dll" function string GetHost(string lpszhost, ref blob lpszaddress ) library "PBWS32.DLL" 然后在form的open事件中执行如下代码就可以了 s_wsadata l_WSAData int li_version = 257 blob{4} lb_hostaddress IF wsastartup ( li_version, l_WSAData ) = 0 THEN IF gethostname ( ls_HostName, len(ls_HostName) ) < 0 THEN messagebox("GetHostName",WSAGetLastError()) ELSE GetHost(ls_HostName, lb_HostAddress) //获得主机名和IP地址 ls_IpAddress = string(asc(string(blobmid(lb_HostAddress,1,1))),"000") + "." ls_IpAddress += string(asc(string(blobmid(lb_HostAddress,2,1))),"000") + "." ls_IpAddress += string(asc(string(blobmid(lb_HostAddress,3,1))),"000") + "." ls_IpAddress += string(asc(string(blobmid(lb_HostAddress,4,1))),"000") //将IP地址的ASC码形式转化为***.***.***.***字符串格式 END IF WSACleanup() ELSE messagebox("GetHostName",WSAGetLastError()) END IF

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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