打印本文 打印本文 关闭窗口 关闭窗口
如何在vb 中用api函数代替winsock控件建立网络连接?
作者:武汉SEO闵涛  文章来源:敏韬网  点击数2820  更新时间:2009/4/23 18:57:41  文章录入:mintao  责任编辑:mintao
EAD

End Sub
Private Function getipaddress(host As String) As Long
Dim he As Long
Dim hedesthost As hostent
Dim addrlist As Long
Dim rc As Long
he = gethostbyname(host)
If he = 0 Then
MsgBox "主机名错误或网络错误!"
rc = 0
Exit Function
End If
CopyMemory hedesthost, ByVal he, Len(hedesthost)
CopyMemory addrlist, ByVal hedesthost.h_addr_list, 4
CopyMemory rc, ByVal addrlist, hedesthost.h_length
getipaddress = rc
End Function

 

Private Sub Text5_KeyDown(KeyCode As Integer, Shift As Integer)
Dim datareceived As String
Dim datasend As String
datareceived = String$(255, Chr(0))
rc = recv(sll, datareceived, 255, 0)
If rc <= 0 Then Exit Sub
Text5.Text = Text5.Text & Left(datareceived, rc)
If Left(datareceived, 3) = "220" Then datasend = "helo " & Text4.Text & vbCrLf
If Left(datareceived, 3) = "250" And mailok = False Then
datasend = "mail from:" & Text4.Text & vbCrLf
mailok = True
ElseIf Left(datareceived, 3) = "250" And mailok = True And rcptok = False Then
datasend = "rcpt to:" & Text2.Text & vbCrLf
rcptok = True
ElseIf Left(datareceived, 3) = "250" And rcptok = True And sendok = False Then
datasend = "data" & vbCrLf
sendok = True
ElseIf Left(datareceived, 3) = "250" And sendok = True Then
Text5.Text = Text5.Text & "邮件发送成功!"
closesocket sll
WSACleanup
Exit Sub
End If
If Left(datareceived, 3) = "354" Then datasend = Text3.Text & vbCrLf & "." & vbCrLf
If Left(datareceived, 1) = "5" Then
Text5.Text = Text5.Text & "邮件发送失败!"
closesocket sll
WSACleanup
End If
rc = send(sll, ByVal datasend, Len(datasend), 0)

End Sub

 

 

上一页  [1] [2] 

打印本文 打印本文 关闭窗口 关闭窗口