能力值:
( LV4,RANK:50 )
2 楼
.386
.model flat,stdcall
option casemap:none
include windows.inc
include user32.inc
include kernel32.inc
include ws2_32.inc
includelib user32.lib
includelib kernel32.lib
includelib ws2_32.lib
include D:\WinAsm\masm32\macros\macros.asm
main proto
.code
start:
invoke main
invoke ExitProcess,0
main proc
LOCAL @wsaData:WSADATA
LOCAL @sockid:SOCKET
LOCAL @addr:sockaddr_in
LOCAL @Event:HANDLE
LOCAL EventWork:WSANETWORKEVENTS
LOCAL buf[100]:BYTE
invoke WSAStartup,202h,addr @wsaData
mov @sockid,FUNC(socket,AF_INET,SOCK_STREAM,0)
mov @addr.sin_family,AF_INET
mov @addr.sin_addr.S_un.S_addr,FUNC(inet_addr,SADD("127.0.0.1"))
invoke htons,90
mov @addr.sin_port,ax
invoke bind,@sockid,addr @addr,sizeof @addr
invoke WSACreateEvent
mov @Event,eax
invoke WSAEventSelect,@sockid,@Event,FD_CONNECT or FD_CLOSE
invoke connect,@sockid,addr @addr,sizeof @addr
;invoke wsprintf,addr buf,SADD("%d"),FUNC(WSAGetLastError)
;invoke MessageBox,0,addr buf,0,0
.while TRUE
invoke WSAWaitForMultipleEvents,1,addr @Event,FALSE,INFINITE,FALSE
invoke WSAResetEvent,@Event
invoke WSAEnumNetworkEvents,@sockid,@Event,addr EventWork
.if EventWork.lNetworkEvents == FD_CONNECT
.if EventWork.iErrorCode[FD_CONNECT_BIT] != 0
invoke MessageBox,0,SADD("连接失败"),0,0
.break
.endif
invoke MessageBox,0,SADD("连接成功"),0,0
.elseif EventWork.lNetworkEvents == FD_CLOSE
invoke MessageBox,0,SADD("连接关闭"),0,0
.endif
.endw
invoke WSACleanup
Ret
main EndP
end start 完整代码~~
连接成功了,还是会进入invoke MessageBox,0,SADD("连接失败"),0,0
为什么????????????????????
实在不懂
能力值:
( LV2,RANK:10 )
3 楼
The iErrorCode array is used to contain any associated error codes with the array index corresponding to the position of event bits in lNetworkEvents. Identifiers such as FD_READ_BIT and FD_WRITE_BIT can be used to index the iErrorCode array. Note that only those elements of the iErrorCode array are set that correspond to the bits set in lNetworkEvents parameter. Other parameters are not modified
看最后一句,呵呵,原因在此