par Michael DELIQUE » 05 Nov 2007 à 18:00
- Code : Tout sélectionner
Public Function GetIPFromHostName_API(Byval sHostName As String) As String
%REM
'Variables API pour la fonction GetIPFromHostName_API
Declare Function inet_ntoa Lib "wsock32.dll" (Byval addr As Long) As Long
Declare Function lstrlenA Lib "kernel32" (lpString As Any) As Long
Declare Function lstrcpyA Lib "kernel32" (Byval RetVal As String, Byval Ptr As Long) As Long
Declare Function gethostbyname Lib "wsock32" (Byval hostname As String) As Long
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (xDest As Any,xSource As Any, Byval nbytes As Long)
Class HostName
Private HostNameStr As String
Public IPAddress As String
Public ErrMsg As String
Public Error As Integer
Sub New(host As String)
If SocketsInitialize_API() Then
Me.IPAddress = GetIPFromHostName_API(host)
Me.Error = 0
Me.ErrMsg = ""
If Not SocketsCleanup_API Then
Me.Error = 200
Me.ErrMsg = "Windows Sockets error occurred in Cleanup."
End If
Else
Me.Error = 100
Me.ErrMsg = "Windows Sockets for 32 bit Windows is not successfullyresponding."
Me.IPAddress = ""
End If
End Sub
End Class
%END REM
'Déclaration Variable
Dim nbptrHosent As Long
Dim nbptrName As Long
Dim nbptrAddress As Long
Dim nbptrIPAddress As Long
Dim nbdwAddress As Long
Dim nbptrString As Long
On Error Goto ErreurGetIPFromHostName_API
nbptrHosent = gethostbyname(sHostName & Chr(0))
If nbptrHosent <> 0 Then
nbptrName = nbptrHosent
nbptrAddress = nbptrHosent + 12
CopyMemory nbptrAddress, Byval nbptrAddress, 4
CopyMemory nbptrIPAddress, Byval nbptrAddress, 4
CopyMemory nbdwAddress, Byval nbptrIPAddress, 4
nbptrString = inet_ntoa(nbdwAddress)
GetIPFromHostName_API = String(lstrlenA(Byval nbptrString), 0)
Call lstrcpyA(Byval GetIPFromHostName_API , Byval nbptrString)
Else
GetIPFromHostName_API = ""
End If
Exit Function
ErreurGetIPFromHostName_API:
Msgbox "("+Cstr(Getthreadinfo (1))+" Call by "+Cstr(Getthreadinfo(10))+")"+Chr(10)+"Erreur " + Str(Err) + " : "+Chr(10) + Cstr(Error)+". "+Chr(10)+"Ligne N° "+Cstr(Erl),16," ERREUR !"
GetIPFromHostName_API = ""
Exit Function
End Function
Cordialement
Michael (SMS-Phobique)
----------------------------
"La théorie, c'est quand on sait tout et que rien ne fonctionne. La pratique, c'est quand tout fonctionne et que personne ne sait pourquoi."
Albert EINSTEIN