getting IP adress using hostname (IN CHINESE ENVIROMENT)
From: Abdullah Ali (abdullah_at_visual-2000.com)
Date: 08/12/04
- Next message: Randy Birch: "Re: getting IP adress using hostname (IN CHINESE ENVIROMENT)"
- Previous message: Chipmonk: "Re: WinINET API... Yay or Nay?"
- Next in thread: Randy Birch: "Re: getting IP adress using hostname (IN CHINESE ENVIROMENT)"
- Reply: Randy Birch: "Re: getting IP adress using hostname (IN CHINESE ENVIROMENT)"
- Messages sorted by: [ date ] [ thread ]
Date: 12 Aug 2004 11:58:42 -0700
Hello,
I am currectly working on a project within a chinese enviroment. It is
an Access project using VBA. I have a function that returns an IP
address based on the input of a HOST name.
The function works properly on my side, but when I implement the same
function in a chinese enviroment, the error occurs at "apiCopyMemory
ByVal sAddress, ByVal ptrIPAddress, hstHost.hLength" in the function
GETIPFROMHOSTNAME.
This is supposed to return a ASCII value, and then from there , it
will convert the ASCII to a IP string using the function IPTOTEXT
(this is where the 'real' crash occurs
Instead, it returns 1 chinese char, which cannot be read by the
function IPTOTEXT.
Why is it doing this and is there a way to resolve this problem
ANY help is appreciated
----------------------------------------------------------------------------------------------------
Private Declare Sub apiCopyMemory Lib "kernel32" Alias "RtlMoveMemory"
(xDest As Any, xSource As Any, ByVal nBytes As Long)
Public Function GetIPFromHostName(ByVal sHostName As String) As String
'converts a host name to an IP address.
Dim nBytes As Long
Dim ptrHosent As Long
Dim hstHost As HOSTENT
Dim ptrName As Long
Dim ptrAddress As Long
Dim ptrIPAddress As Long
Dim sAddress As String 'declare this as Dim sAddress(1) As String
if you want 2 ip addresses returned
'try to initalize the socket
If InitializeSocket() = True Then
'try to get the IP
ptrHosent = apiGetHostByName(sHostName & vbNullChar)
If ptrHosent <> 0 Then
'get the IP address
apiCopyMemory hstHost, ByVal ptrHosent, LenB(hstHost)
apiCopyMemory ptrIPAddress, ByVal hstHost.hAddrList, 4
'fill buffer
sAddress = Space$(4)
'if you want multiple domains returned,
'fill all items in sAddress array with 4 spaces
----> THIS IS WHERE THE CHINESE CHAR POPS UP IN sAddress <------
----> INSTEAD OF ASCII CODE <-----
apiCopyMemory ByVal sAddress, ByVal ptrIPAddress,
hstHost.hLength
'change this to
'CopyMemory ByVal sAddress(0), ByVal ptrIPAddress,
hstHost.hLength
'if you want an array of ip addresses returned
'(some domains have more than one ip address associated
with it)
'get the IP address
GetIPFromHostName = IPToText(sAddress)
'if you are using multiple addresses, you need
IPToText(sAddress(0)) & "," & IPToText(sAddress(1))
'etc
End If
Else
GetIPFromHostName = "NO"
End If
End Function
-----> CAUSING THIS FUNCTION TO CRASH <-----
Private Function IPToText(ByVal IPAddress As String) As String
'converts characters to numbers
IPToText = CStr(Asc(IPAddress)) & "." & _
CStr(Asc(Mid$(IPAddress, 2, 1))) & "." & _
CStr(Asc(Mid$(IPAddress, 3, 1))) & "." & _
CStr(Asc(Mid$(IPAddress, 4, 1)))
End Function
------------------------------------------------------------------------------------------------
Thanks
Abdullah
- Next message: Randy Birch: "Re: getting IP adress using hostname (IN CHINESE ENVIROMENT)"
- Previous message: Chipmonk: "Re: WinINET API... Yay or Nay?"
- Next in thread: Randy Birch: "Re: getting IP adress using hostname (IN CHINESE ENVIROMENT)"
- Reply: Randy Birch: "Re: getting IP adress using hostname (IN CHINESE ENVIROMENT)"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|