[DllImport("wininet.dll", SetLastError = true)]
private static extern bool InternetQueryOption(
IntPtr hInternet, //Handle on which to query information.
int dwOption, //Internet option to be queried.
IntPtr lpBuffer, //Pointer to a buffer that receives the option setting.
ref int lpdwBufferLength//Pointer to a variable that contains the size of lpBuffer, in bytes.
);
Declare Function InternetQueryOption Lib "wininet.dll" (TODO) As TODO
public struct Struct_INTERNET_PROXY_INFO
{
public int dwAccessType;//Access type.
public IntPtr proxy;//Pointer to a string that contains the proxy server list
public IntPtr proxyBypass;//Pointer to a string that contains the proxy bypass list.
};
None.
Please add some!!
const int ERROR_INSUFFICIENT_BUFFER = 122;
Struct_INTERNET_PROXY_INFO struct_IPI;
IntPtr intptrStruct = IntPtr.Zero;
int bufferLength = 0;
try
{
//Retrive Buffer Size
bool iReturn = InternetQueryOption(IntPtr.Zero, INTERNET_OPTION_PROXY, IntPtr.Zero, ref bufferLength);
if ((Marshal.GetLastWin32Error() == ERROR_INSUFFICIENT_BUFFER) || iReturn )
{
// Allocating memory
intptrStruct = Marshal.AllocCoTaskMem(bufferLength);
if (intptrStruct != IntPtr.Zero)
{
iReturn = InternetQueryOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, ref bufferLength);
if (iReturn)
{
struct_IPI = (Struct_INTERNET_PROXY_INFO)Marshal.PtrToStructure(intptrStruct , typeof(Struct_INTERNET_PROXY_INFO));
Console.WriteLine("*****Proxy Server Config*****");
foreach(string proxy in Marshal.PtrToStringAnsi(struct_IPI.proxy).Split(' '))
Console.WriteLine(proxy);
Console.WriteLine("\n*****Proxy Server Bypass List *****");
foreach(string proxyBypass in Marshal.PtrToStringAnsi(struct_IPI.proxyBypass).Split(' '))
Console.WriteLine(proxyBypass);
}
}
}else{
Console.WriteLine("ErrorCode={0}", Marshal.GetLastWin32Error());
}
}catch(Exception exp){
Console.WriteLine( exp.ToString());
}finally{
if (intptrStruct != IntPtr.Zero)
Marshal.FreeCoTaskMem(intptrStruct);
}
Do you know one? Please contribute it!