|
||||
InternetOpenCategory: InternetHits: 4319 Rating: (2.98) votes 418
Rate: 1-star 2-stars 3-stars 4-stars 5-stars
API Explanation
Initializes an application's use of the Win32 Internet functions. Parameter Information Declare Function InternetOpen Lib "wininet" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType _ As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long · lpszAgent Address of a string that contains the name of the application or entity calling the Internet functions (for example, Microsoft Internet Explorer). This name is used as the user agent in the HTTP protocol. · dwAccessType Type of access required. Can be one of these values: INTERNET_OPEN_TYPE_DIRECT Resolve all host names locally. INTERNET_OPEN_TYPE_PROXY Pass requests to the proxy unless a proxy bypass list is supplied and the name to be resolved bypasses the proxy. In this case, the function proceeds as for INTERNET_OPEN_TYPE_DIRECT. INTERNET_OPEN_TYPE_PRECONFIG Retrieve the proxy or direct configuration from the registry. · lpszProxyName Address of a string that contains the name of the proxy server (or servers) to use if proxy access was specified. If this parameter is NULL, the function reads proxy information from the registry. For more information about this parameter, see the comments below. · lpszProxyBypass Address of an optional list of host names or IP addresses, or both, that are known locally. Requests to these names are not routed through the proxy. The list can contain wildcards, such as "157.55.* *int*", meaning any IP address starting with 157.55, or any name containing the substring "int", will bypass the proxy. If this parameter specifies the " If this parameter is NULL, the function reads the bypass list from the registry. · dwFlags Flag that indicates various options affecting the behavior of the function. Can be a combination of these values: INTERNET_FLAG_OFFLINE Satisfy download operations on this handle through the persistent cache only. If the item does not exist in the cache, the function returns an appropriate error code. INTERNET_FLAG_ASYNC Future operations on this handle may fail with ERROR_IO_PENDING. A status callback will be made with INTERNET_STATUS_REQUEST_COMPLETE. This callback will be on a thread other than the one for the original request. A status callback routine must be registered or the functions will be completed synchronously. Returns a valid handle that the application passes on to subsequent Win32 Internet functions. If InternetOpen fails, it returns NULL. To get a specific error code, call GetLastError.
Code
Const scUserAgent = "API-Guide test program"
Const INTERNET_OPEN_TYPE_DIRECT = 1 Const INTERNET_OPEN_TYPE_PROXY = 3 Const INTERNET_FLAG_RELOAD = &H80000000 Const sURL = "http://www.microsoft.com/index.htm" Private Declare Function InternetOpen Lib "wininet" Alias "InternetOpenA" (ByVal sAgent As String, ByVal _ lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As _ Long) As Long Private Declare Function InternetCloseHandle Lib "wininet" (ByVal hInet As Long) As Integer Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, ByVal sBuffer As String, _ ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer Private Declare Function InternetOpenUrl Lib "wininet" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, _ ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal _ dwFlags As Long, ByVal dwContext As Long) As Long Private Sub Form_Load() Dim hOpen As Long, hFile As Long, sBuffer As String, Ret As Long 'Create a buffer for the file we're going to download sBuffer = Space(1000) 'Create an internet connection hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0) 'Open the url hFile = InternetOpenUrl(hOpen, sURL, vbNullString, ByVal 0&, INTERNET_FLAG_RELOAD, ByVal 0&) 'Read the first 1000 bytes of the file InternetReadFile hFile, sBuffer, 1000, Ret 'clean up InternetCloseHandle hFile InternetCloseHandle hOpen 'Show our file MsgBox sBuffer End Sub |