於表單少布置一text1及command1
測試下列API但CONNECT時有問題
請問各位先進,何處錯了呢?
'Option Explicit
Private Type tagWSAData
wVersion As Integer
wHighVersion As Integer
szDescription As String * 257 'WSADESCRIPTION_LEN_1
szSystemStatus As String * 129 'WSASYSSTATUS_LEN_1
iMaxSockets As Integer
iMaxUdpDg As Integer
lpVendorInfo As String * 200
End Type
Private Type sockaddr_in
sin_family As Integer
sin_port As Integer
sin_addr As Long
sin_zero As String * 8
End Type
Private Declare Function WSAStartup Lib "wsock32" (ByVal wVersionRequested As Integer, lpWSAData As tagWSAData) As Integer
Private Declare Function htons Lib "wsock32" (ByVal hostshort As Integer) As Integer
Private Declare Function htonl Lib "wsock32" (ByVal hostshort As Long) As Long
Private Declare Function inet_addr Lib "wsock32" (ByVal ipaddr As String) As Long
Private Declare Function connect Lib "wsock32" (ByVal s As Integer, add As sockaddr_in, ByVal name As Integer) As Long
Private Declare Function WSACleanup Lib "wsock32" () As Integer
Private Declare Function WSAGetLastError Lib "wsock32" () As Integer
Private Declare Function WSAAsyncSelect Lib "wsock32" (ByVal s As Integer, ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal lEvent As Long) As Integer
Private Declare Function socket Lib "wsock32" (ByVal af As Integer, ByVal socktype As Integer, ByVal protocal As Integer) As Integer
Private Sub Command1_Click()
Dim ws As tagWSAData
Dim i_sock As sockaddr_in
'Dim newsocket As Integer
Debug.Print "wsastartup==>"; WSAStartup(&H101, ws) ' if return 0 is sucessful
Print ws.wVersion
Print ws.szDescription
Print ws.szSystemStatus
DoEvents
newsocket = socket(2, 1, 0)
DoEvents
Debug.Print "new_socket==>"; newsocket
Debug.Print "asyncselect ==>"; WSAAsyncSelect(newsocket, Form1.Text1.hWnd, &H200, &H10)
DoEvents
i_sock.sin_family = 2
i_sock.sin_port = htons(110)
i_sock.sin_addr = inet_addr("210.59.228.46")
i_sock.sin_zero = ""
Debug.Print "sin_addr==>"; i_sock.sin_addr
Debug.Print "connect==>"; connect(newsocket, i_sock, 16) ' if return 0 is sucessful
DoEvents
Debug.Print "last error==>"; WSAGetLastError()
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Print "This Is KeyDown"
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
Print "This Is KeyUp"
End Sub