Private Sub Command1_Click()
Dim host_path As String
Dim VerReq As Integer, rc As Long
Dim wsaDD As wsaDATA
Dim HostAddress As Long, lphostinfo As Long
Dim HostEntCopy As hostent, AddressListPoint As Long
Dim lpHostAddress As lpHostAddress
Me.Command1.Enabled = False
host_path = Me.Text1.Text
VerReq = MakeInteger(1, 1)
rc = WSAStartup(VerReq, wsaDD)
If rc <> 0 Then
MsgBox "WinSockの初期化失敗", , "Error"
Exit Sub
End If
HostAddress = inet_addr(host_path)
If HostAddress = INADDR_NONE Then
lphostinfo = gethostbyname(host_path)
If lphostinfo <> 0 Then
Call MoveMemory(HostEntCopy, ByVal lphostinfo, Len(HostEntCopy))
Call MoveMemory(AddressListPoint, ByVal HostEntCopy.h_addr_list, Len(AddressListPoint))
Call MoveMemory(HostAddress, ByVal AddressListPoint, Len(HostAddress))
Call MoveMemory(lpHostAddress, ByVal AddressListPoint, Len(HostAddress))
With lpHostAddress
MsgBox "[HostName]->" & .szhostAddress(0) & "." & .szhostAddress(1) & _
"." & .szhostAddress(2) & "." & .szhostAddress(3)
End With
Else
MsgBox "ホスト名からIPアドレスが取得できませんでした"
Exit Sub
End If
End If
Call WSACleanup
Me.Command1.Enabled = True
End Sub
Private Sub Form_Load()
Me.Text1.Text = "www.winapi-database.com"
Me.Command1.Enabled = True
End Sub
Private Sub Text1_Change()
Dim txt As String
txt = Me.Text1.Text
If txt = "" Then
Me.Command1.Enabled = False
Else
Me.Command1.Enabled = True
End If
End Sub
|