InternetOpenA function (wininet.h)

Initializes the WinInet service.

Overview

The InternetOpenA function initializes the application to use the WinInet API. It informs the WinInet service of the application's presence and allows the application to specify the context and behavior of its Internet sessions.

Syntax


HINTERNET InternetOpenA(
  [in, optional] LPCSTR lpszAgent,
  [in]           DWORD  dwAccessType,
  [in, optional] LPCSTR lpszProxyName,
  [in, optional] LPCSTR lpszProxyBypass,
  [in]           DWORD  dwFlags
);
                

Parameters

Parameter Description
lpszAgent

A pointer to a null-terminated string that contains the name of the calling application or object. This name is used in protocol requests, such as FTP or HTTP.

dwAccessType

The type of access to the Internet. This parameter can be one of the following values:

  • INTERNET_OPEN_TYPE_PRECONFIG: Uses the registry configuration to determine the access method.
  • INTERNET_OPEN_TYPE_DIRECT: Accesses the Internet directly, without a proxy server.
  • INTERNET_OPEN_TYPE_PROXY: Uses the proxy server specified by lpszProxyName.
lpszProxyName

A pointer to a null-terminated string that specifies the name and path of the proxy server to use when dwAccessType is INTERNET_OPEN_TYPE_PROXY. If dwAccessType is INTERNET_OPEN_TYPE_PRECONFIG, this parameter must be NULL.

lpszProxyBypass

A pointer to a null-terminated string that specifies an optional list of addresses that should be bypassed when using a proxy server. This parameter is only used when dwAccessType is INTERNET_OPEN_TYPE_PROXY.

dwFlags

Flags that control the behavior of the session. This parameter can be zero or a combination of the following values:

  • INTERNET_FLAG_ASYNC: Enables asynchronous operations.
  • INTERNET_FLAG_FROM_CACHE: Retrieves data from the cache only.
  • INTERNET_FLAG_OFFLINE: Retrieves data from the cache only, if available.

Return Value

If the function succeeds, it returns a valid handle to the WinInet service. An application must close this handle by calling the InternetCloseHandle function.

If the function fails, it returns NULL. To get extended error information, call GetLastError.

Remarks

This is the first WinInet function an application must call. It allocates and prepares an HINTERNET handle for subsequent calls.

If dwAccessType is INTERNET_OPEN_TYPE_PRECONFIG, WinInet reads proxy settings from the registry.

If dwAccessType is INTERNET_OPEN_TYPE_PROXY, WinInet uses the proxy server specified in lpszProxyName. If lpszProxyName is NULL and dwAccessType is INTERNET_OPEN_TYPE_PROXY, an error is returned.

If lpszProxyBypass is not NULL, it specifies a list of addresses that should not be routed through the proxy server. The addresses are separated by semicolons (;). Wildcards can be used in host names. For example, "*.example.com;192.168.1.0/24".

The INTERNET_FLAG_ASYNC flag enables asynchronous operations, which means WinInet functions will return immediately without waiting for the operation to complete. The application must then implement a mechanism to receive notifications when the operation is finished.

Note

It is recommended to use the wide-character version of this function, InternetOpenW, to avoid potential issues with character encoding.

Requirements

Component Value
Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Header wininet.h
Library wininet.lib
DLL wininet.dll

See Also

InternetCloseHandle

InternetConnectA

InternetOpenUrlA

InternetSetOptionA

WinInet Functions

WinInet Overview