Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connect To Internet Directly by Visual Basic 6.0

Status
Not open for further replies.

darknesszero

Programmer
Aug 9, 2003
1
MX
How Do I a connection to internet by a program without using the window that window calls to make it?
 
You can use the InternetOpen and InternetConnect API to get started.
Code:
Public Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long

Public Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal hInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUsername As String, ByVal sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long

Const INTERNET_SERVICE_FTP = 1
Const INTERNET_OPEN_TYPE_DIRECT = 1

The following example sets up an internet connection for some FTP work.

lLng_OpenHand = InternetOpen(&quot;<YourConnectionName&quot;, INTERNET_OPEN_TYPE_DIRECT, &quot;&quot;, &quot;&quot;, 0)
If (lLng_OpenHand > 0) Then
lLng_ConnHand = InternetConnect(lLng_OpenHand, &quot;<IP Address>&quot;, 0, &quot;<User ID>&quot;, &quot;<Password>&quot;, INTERNET_SERVICE_FTP, 0, 0)
If (lLng_ConnHand > 0) Then
' Do what you need to do
InternetCloseHandle (lLng_ConnHand)
Else
MsgBox &quot;Failed to Log onto Host&quot;
End If
InternetCloseHandle (lLng_OpenHand)
Else
MsgBox &quot;Internet Channel Open Failed&quot;
End If
[/code]
There are other uses besides FTP, but this should get you started.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top