T
Thomas
Hi newsgroup !
I'm trying to use functions from the Wininet library but I've some problems.
During the execution, both on PPC2003 and on a CE.NET 4.2 device, the
InternetOpen function returns me a valid handle but the InternetConnect
fuction always raises a native exception.
According to samples I found on Internet, I can't see my errors. Maybe you
can help me ?
Here is my code :
'---------------------------------------------------------------------------
'Déclaration des fonctions de la bibliothèque DLL Wininet.dll
'---------------------------------------------------------------------------
'Initialisation d'une connexion
<DllImport("wininet.dll", EntryPoint:="InternetOpenW")> _
Public Function InternetOpen(ByVal sAgent As String, ByVal nAccessType As
Int32, ByVal sProxy As String, _
ByVal sProxyBypass As String, ByVal nFlags As Int32) As Int32
End Function
'Ouverture d'une connexion à interun serveur FTP
<DllImport("wininet.dll", EntryPoint:="InternetConnectW",
CharSet:=CharSet.Unicode)> _
Public Function InternetConnect(ByVal hInternet As Int32, ByVal ServerName
As String, ByVal ServerPort As Int16, _
ByVal sUserName As String, ByVal sPassword As String, ByVal nService As
Int32, ByVal nFlags As Int32, _
ByVal nContext As Int32) As Int32
End Function
'---------------------------------------------------------------------------
'---------------------------------------------------------------------------
'Définition des constantes utilisées par les fonctions de la DLL Wininet.dll
'---------------------------------------------------------------------------
Const INTERNET_INVALID_PORT_NUMBER = 0
Const INTERNET_DEFAULT_FTP_PORT = 21
Const INTERNET_DEFAULT_GOPHER_PORT = 70
Const INTERNET_DEFAULT_HTTP_PORT = 80
Const INTERNET_DEFAULT_HTTPS_PORT = 443
Const INTERNET_DEFAULT_SOCKS_PORT = 1080
Const INTERNET_FLAG_PASSIVE = &H8000000
Const INTERNET_FLAG_TRANSFER_ASCII = &H1
Const INTERNET_FLAG_TRANSFER_BINARY = &H2
Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Const INTERNET_OPEN_TYPE_DIRECT = 1
Const INTERNET_OPEN_TYPE_PROXY = 3
Const INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY = 4
Const INTERNET_SERVICE_FTP = 1
Const INTERNET_SERVICE_GOPHER = 2
Const INTERNET_SERVICE_HTTP = 3
'---------------------------------------------------------------------------
'---------------------------------------------------------------------------
'Définition des membres de la classe
'---------------------------------------------------------------------------
Dim HandleConnexion As Int32
Dim HandleFTP As Int32
'---------------------------------------------------------------------------
Public Function Connexion() As Boolean
Try
'Initialisation de la connexion
HandleConnexion = InternetOpen("Test", INTERNET_OPEN_TYPE_PRECONFIG,
vbNullString, vbNullString, 0)
MsgBox(HandleConnexion)
'Ouverture de la connexion
HandleFTP = InternetConnect(HandleConnexion, "192.168.1.7",
INTERNET_DEFAULT_FTP_PORT, "pageup", "pageup", INTERNET_SERVICE_FTP, 0, 0)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
I'm trying to use functions from the Wininet library but I've some problems.
During the execution, both on PPC2003 and on a CE.NET 4.2 device, the
InternetOpen function returns me a valid handle but the InternetConnect
fuction always raises a native exception.
According to samples I found on Internet, I can't see my errors. Maybe you
can help me ?
Here is my code :
'---------------------------------------------------------------------------
'Déclaration des fonctions de la bibliothèque DLL Wininet.dll
'---------------------------------------------------------------------------
'Initialisation d'une connexion
<DllImport("wininet.dll", EntryPoint:="InternetOpenW")> _
Public Function InternetOpen(ByVal sAgent As String, ByVal nAccessType As
Int32, ByVal sProxy As String, _
ByVal sProxyBypass As String, ByVal nFlags As Int32) As Int32
End Function
'Ouverture d'une connexion à interun serveur FTP
<DllImport("wininet.dll", EntryPoint:="InternetConnectW",
CharSet:=CharSet.Unicode)> _
Public Function InternetConnect(ByVal hInternet As Int32, ByVal ServerName
As String, ByVal ServerPort As Int16, _
ByVal sUserName As String, ByVal sPassword As String, ByVal nService As
Int32, ByVal nFlags As Int32, _
ByVal nContext As Int32) As Int32
End Function
'---------------------------------------------------------------------------
'---------------------------------------------------------------------------
'Définition des constantes utilisées par les fonctions de la DLL Wininet.dll
'---------------------------------------------------------------------------
Const INTERNET_INVALID_PORT_NUMBER = 0
Const INTERNET_DEFAULT_FTP_PORT = 21
Const INTERNET_DEFAULT_GOPHER_PORT = 70
Const INTERNET_DEFAULT_HTTP_PORT = 80
Const INTERNET_DEFAULT_HTTPS_PORT = 443
Const INTERNET_DEFAULT_SOCKS_PORT = 1080
Const INTERNET_FLAG_PASSIVE = &H8000000
Const INTERNET_FLAG_TRANSFER_ASCII = &H1
Const INTERNET_FLAG_TRANSFER_BINARY = &H2
Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Const INTERNET_OPEN_TYPE_DIRECT = 1
Const INTERNET_OPEN_TYPE_PROXY = 3
Const INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY = 4
Const INTERNET_SERVICE_FTP = 1
Const INTERNET_SERVICE_GOPHER = 2
Const INTERNET_SERVICE_HTTP = 3
'---------------------------------------------------------------------------
'---------------------------------------------------------------------------
'Définition des membres de la classe
'---------------------------------------------------------------------------
Dim HandleConnexion As Int32
Dim HandleFTP As Int32
'---------------------------------------------------------------------------
Public Function Connexion() As Boolean
Try
'Initialisation de la connexion
HandleConnexion = InternetOpen("Test", INTERNET_OPEN_TYPE_PRECONFIG,
vbNullString, vbNullString, 0)
MsgBox(HandleConnexion)
'Ouverture de la connexion
HandleFTP = InternetConnect(HandleConnexion, "192.168.1.7",
INTERNET_DEFAULT_FTP_PORT, "pageup", "pageup", INTERNET_SERVICE_FTP, 0, 0)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function