2018-09-10 02:41:13 +02:00
|
|
|
// Copyright © 2015 The CefSharp Authors. All rights reserved.
|
2015-04-14 13:29:47 +10:00
|
|
|
//
|
|
|
|
|
// 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
|
|
|
|
|
{
|
2015-04-14 13:31:06 +10:00
|
|
|
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);
|
2015-04-14 13:29:47 +10:00
|
|
|
|
2015-04-14 13:31:06 +10:00
|
|
|
private const uint InternetOptionProxy = 38;
|
2015-04-14 13:29:47 +10:00
|
|
|
|
2015-04-14 13:31:06 +10:00
|
|
|
public static InternetProxyInfo GetProxyInformation()
|
|
|
|
|
{
|
|
|
|
|
var bufferLength = 0;
|
|
|
|
|
InternetQueryOption(IntPtr.Zero, InternetOptionProxy, IntPtr.Zero, ref bufferLength);
|
|
|
|
|
var buffer = IntPtr.Zero;
|
2015-04-14 13:29:47 +10:00
|
|
|
|
2015-04-14 13:31:06 +10:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
buffer = Marshal.AllocHGlobal(bufferLength);
|
2015-04-14 13:29:47 +10:00
|
|
|
|
2015-04-14 13:31:06 +10:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-04-14 13:29:47 +10:00
|
|
|
}
|