Re: こんばんにゃ


[コメントツリー表示を見る] [発言時刻順表示を見る]

Posted by Uz on 2000/10/04 00:57:46

In Reply to: こんばんにゃ Posted by 麻生英亜 on 2000/10/04 00:01:04


    > お元気してますか?
    お久しぶり。

    > 先日、同じ部活だったM本氏に遭遇
    俺は、もう高校時代の記憶があやふやに。

    > さて、質問なのですが
    > VB4の16bit版でカスタムコントロールを使わずに
    なして、いまどき16Bit版?

    > 自分のIPアドレスを表示するようなことはできるのでしょうか?
    > APIでできる物なんでしょうかねぇ〜
    32Bitなら分かるんだけど、16Bitはわからん。
    多分WinSockの16Bit版にも同等の関数はあると思うので、
    僕のサンプルを16Bit版に作り直してみれば?
    (出来るかどうか保証できないけど・・・)

    サンプル

    Option Explicit

    Private Const INADDR_NONE& = &HFFFF

    Private Type WSAData
    wVersion As Integer
    wHighVersion As Integer
    szDescription As String * 257
    szSystemStatus As String * 129
    iMaxSockets As Integer
    iMaxUdpDg As Integer
    lpVendorInfo As String * 200
    End Type

    Private Type HostEnt
    h_name As Long
    h_aliases As Long
    h_addrtype As Integer
    h_length As Integer
    h_addr_list As Long
    End Type

    Private Declare Function WSAStartup Lib "wsock32.dll" ( _
    ByVal wVersionRequired As Long, _
    lpWSAData As WSAData _
    ) As Long
    Private Declare Function GetHostName Lib "wsock32.dll" Alias "gethostname" ( _
    ByVal hostname As String, _
    ByVal namelen As Integer _
    ) As Long
    Private Declare Function inet_addr Lib "wsock32.dll" ( _
    ByVal cp As String _
    ) As Long
    Private Declare Function gethostbyname Lib "wsock32.dll" ( _
    ByVal hostname As String _
    ) As Long
    Private Declare Function WSACleanUp Lib "wsock32.dll" Alias "WSACleanup" () As Long
    Private Declare Function WSAUnhookBlockingHook% Lib "wsock32.dll" ()

    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
    Dest As Any, _
    sour As Any, _
    ByVal bytes As Long _
    )

    Private Sub Command1_Click()
    Dim Version As Long
    Dim StartUpInfo As WSAData
    Dim sHostName As String
    Dim nIP As Long
    Dim nRet As Long

    Dim heHost As HostEnt
    Dim nAddr As Long
    Dim I As Integer
    Dim sAddress As String
    Dim sIpAddress As String

    Version = 257

    If WSAStartup(Version, StartUpInfo) < 0 Then
    MsgBox "Windows Socket初期化失敗"
    End If

    sHostName = String(256, 0)
    nRet = GetHostName(sHostName, 256)
    sHostName = Left$(sHostName, InStr(sHostName, Chr(0)) - 1)
    Call MsgBox(sHostName)

    nIP = inet_addr(sHostName)

    If nIP = INADDR_NONE Then
    nRet = gethostbyname(sHostName)
    If nRet <> 0 Then
    I = 0
    Do
    Call CopyMemory(heHost, ByVal nRet, Len(heHost))
    Call CopyMemory(nAddr, ByVal heHost.h_addr_list + I * 4, 4)
    If nAddr = 0 Then Exit Do
    Call CopyMemory(nIP, ByVal nAddr, heHost.h_length)

    Call MsgBox(CLng("&H" & Mid$(Hex(nIP), 7, 2)) & "." & _
    CLng("&H" & Mid$(Hex(nIP), 5, 2)) & "." & _
    CLng("&H" & Mid$(Hex(nIP), 3, 2)) & "." & _
    CLng("&H" & Mid$(Hex(nIP), 1, 2)))
    I = I + 1
    Loop
    End If
    End If

    Call WSAUnhookBlockingHook
    Call WSACleanUp
    End Sub


記事スレッド一覧