WinHttpDetectAutoProxyUrl (winhttp)
Last changed: brubli@outlook.com-141.249.133.142

.
Summary
Get pac url from DHCP or DNS.

C# Signature:

[DllImport("winhttp.dll", SetLastError = true, CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern Boolean WinHttpDetectAutoProxyConfigUrl(
    UInt32 dwAutoDetectFlags,
    [MarshalAs(UnmanagedType.LPWStr)] out String ppwstrAutoConfigUrl
);

VB Signature:

Declare Function WinHttpDetectAutoProxyUrl Lib "winhttp.dll" (TODO) As TODO

User-Defined Types:

None.

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

Values for dwAutoDetectFlags :

    UInt32 WINHTTP_AUTO_DETECT_TYPE_DHCP = 0x00000001;
    UInt32 WINHTTP_AUTO_DETECT_TYPE_DNS_A = 0x00000002;

or both

    WINHTTP_AUTO_DETECT_TYPE_DHCP|WINHTTP_AUTO_DETECT_TYPE_DNS_A

If both the DHCP and DNS auto detect flags are set, DHCP is used first; if no PAC URL is discovered using DHCP, then DNS is used

Tips & Tricks:

Please add some!

Sample Code:

String result;
if ( ! Winhttp.WinHttpDetectAutoProxyConfigUrl(Winhttp.WINHTTP_AUTO_DETECT_TYPE_DHCP|Winhttp.WINHTTP_AUTO_DETECT_TYPE_DNS_A, out result))
    {
    UInt32 error = (uint)Marshal.GetLastWin32Error();
    System.Console.WriteLine("Error "+ error);
    }
System.Console.WriteLine(result);

Documentation