Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

InternetQueryOption (wininet)
 
.
Summary
Queries an Internet option on the specified handle

C# Signature:

    [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.
    );

VB Signature:

Declare Function  InternetQueryOption Lib "wininet.dll" (TODO) As TODO

User-Defined Types:

    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.
    };

Notes:

None.

Tips & Tricks:

Please add some!!

Sample Code: Inquiry Proxy Option Sample

        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);
        }

Alternative Managed API:

Do you know one? Please contribute it!

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions