WinHttpGetDefaultProxyConfiguration function (winhttp.h)

The WinHttpGetDefaultProxyConfiguration function retrieves the default WinHTTP proxy configuration from the registry.

Syntax

WINHTTPAPI BOOL WinHttpGetDefaultProxyConfiguration(
  [in, out] WINHTTP_PROXY_INFO *pProxyInfo
);

Parameters

[in, out] pProxyInfo

A pointer to a variable of type WINHTTP_PROXY_INFO that receives the default proxy configuration.

Return value

Returns TRUE if successful or FALSE otherwise. To retrieve a specific error message, call GetLastError. Error codes returned include the following.

Error Code Description
ERROR_WINHTTP_INTERNAL_ERROR
An internal error has occurred.
ERROR_NOT_ENOUGH_MEMORY
Not enough memory was available to complete the requested operation. (Windows error code)

Remarks

WinHttpGetDefaultProxyConfiguration retrieves the proxy configuration set by WinHttpSetDefaultProxyConfiguration or ProxyCfg.exe.

The default proxy configuration can be overridden for a WinHTTP session by calling WinHttpSetOption and specifying the WINHTTP_OPTION_PROXY flag.
WinHttpGetDefaultProxyConfiguration does not retrieve the configuration for the current session. It retrieves the configuration specified in the registry.

If the registry contains a list of proxy servers, the dwAccessType member of pProxyInfo is set to WINHTTP_ACCESS_TYPE_NAMED_PROXY. Otherwise, it is set to WINHTTP_ACCESS_TYPE_NO_PROXY.

WinHttpGetDefaultProxyConfiguration allocates memory for the string members of pProxyInfo. To free this memory, call GlobalFree.

Even when WinHTTP is used in asynchronous mode (that is, when WINHTTP_FLAG_ASYNC has been set in WinHttpOpen), this function operates synchronously. The return value indicates success or failure. To get extended error information, call GetLastError.

Note  For Windows XP and Windows 2000, see the Run-Time Requirements section of the WinHTTP Start Page.
 

Examples

The following code example shows how to retrieve the default proxy configuration from the registry.

    WINHTTP_PROXY_INFO proxyInfo;

    // Retrieve the default proxy configuration.
    WinHttpGetDefaultProxyConfiguration( &proxyInfo );

    // Display the proxy servers and free memory 
    // allocated to this string.
    if (proxyInfo.lpszProxy != NULL)
    {
        printf("Proxy server list: %S\n", proxyInfo.lpszProxy);
        GlobalFree( proxyInfo.lpszProxy );
    }

    // Display the bypass list and free memory 
    // allocated to this string.
    if (proxyInfo.lpszProxyBypass != NULL)
    {
        printf("Proxy bypass list: %S\n", proxyInfo.lpszProxyBypass);
        GlobalFree( proxyInfo.lpszProxyBypass );
    }

Requirements

Requirement Value
Minimum supported client Windows XP, Windows 2000 Professional with SP3 [desktop apps only]
Minimum supported server Windows Server 2003, Windows 2000 Server with SP3 [desktop apps only]
Target Platform Windows
Header winhttp.h
Library Winhttp.lib
DLL Winhttp.dll
Redistributable WinHTTP 5.0 and Internet Explorer 5.01 or later on Windows XP and Windows 2000.

See also

ProxyCfg.exe, a Proxy Configuration Tool

WinHTTP Versions

WinHttpSetDefaultProxyConfiguration