// Copyright © 2015 The CefSharp Authors. All rights reserved. // // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. using System; using System.ComponentModel; using System.Runtime.InteropServices; namespace CefSharp.Example.Proxy { public class ProxyConfig { [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern bool InternetQueryOption(IntPtr hInternet, uint dwOption, IntPtr lpBuffer, ref int lpdwBufferLength); private const uint InternetOptionProxy = 38; public static InternetProxyInfo GetProxyInformation() { var bufferLength = 0; InternetQueryOption(IntPtr.Zero, InternetOptionProxy, IntPtr.Zero, ref bufferLength); var buffer = IntPtr.Zero; try { buffer = Marshal.AllocHGlobal(bufferLength); if (InternetQueryOption(IntPtr.Zero, InternetOptionProxy, buffer, ref bufferLength)) { var ipi = (InternetProxyInfo)Marshal.PtrToStructure(buffer, typeof(InternetProxyInfo)); return ipi; } { throw new Win32Exception(); } } finally { if (buffer != IntPtr.Zero) { Marshal.FreeHGlobal(buffer); } } } } }