Exemplo n.º 1
0
 private static extern bool InternetQueryOption(
     IntPtr hInternet,
     int dwOption,
     ref InternetPerConnectionOptionList optionsList,
     ref int bufferLength
     //IntPtr lpBuffer,		//Pointer to a buffer that contains the option setting.
     //int lpdwBufferLength	//size of lpBuffer, in bytes.
     );
Exemplo n.º 2
0
        private static InternetPerConnectionOption GetInternetConnectionOption(PerConnectionOption pco)
        {
            //Allocate the list and option.
            InternetPerConnectionOptionList perConnOptList = new InternetPerConnectionOptionList();
            InternetPerConnectionOption     ico            = new InternetPerConnectionOption();
            //pin the option structure
            GCHandle gch = GCHandle.Alloc(ico, GCHandleType.Pinned);

            //initialize the option for the data we want
            ico.option = pco;
            //Initialize the option list for the default connection or LAN.
            int listSize = Marshal.SizeOf(perConnOptList);

            perConnOptList.size        = listSize;
            perConnOptList.connection  = IntPtr.Zero;
            perConnOptList.optionCount = 1;
            perConnOptList.optionError = 0;
            // figure out sizes & offsets
            int icoSize         = Marshal.SizeOf(ico);
            int optionTotalSize = icoSize;

            // alloc enough memory for the option
            perConnOptList.options =
                Marshal.AllocCoTaskMem(icoSize);

            long icoOffset = (long)perConnOptList.options + (long)icoSize;
            // Make pointer from the structure
            IntPtr optionListPtr = perConnOptList.options;

            Marshal.StructureToPtr(ico, optionListPtr, false);

            //Make the query
            if (InternetQueryOption(
                    IntPtr.Zero,
                    (int)InternetOption.INTERNET_OPTION_PER_CONNECTION_OPTION, //75
                    ref perConnOptList,
                    ref listSize) == true)
            {
                //retrieve the value
                ico =
                    (InternetPerConnectionOption)Marshal.PtrToStructure(perConnOptList.options,
                                                                        typeof(InternetPerConnectionOption));
            }
            // free the COM memory
            Marshal.FreeCoTaskMem(perConnOptList.options);
            //unpin the structs
            gch.Free();

            return(ico);
        }
Exemplo n.º 3
0
        private static bool CallInternetSetOption(InternetPerConnectionOption[] options)
        {
            InternetPerConnectionOptionList optionList = new InternetPerConnectionOptionList();

            optionList.size        = Marshal.SizeOf(optionList);
            optionList.connection  = IntPtr.Zero; //Default Connection
            optionList.optionCount = options.Length;
            optionList.optionError = 0;
            optionList.options     = VarPtr(options);


            int    optionListSize = Marshal.SizeOf(optionList);
            IntPtr optionListPtr  = Marshal.AllocCoTaskMem(optionListSize);

            Marshal.StructureToPtr(optionList, optionListPtr, true);

            bool iReturn;

            iReturn = InternetSetOption(IntPtr.Zero, (int)InternetOption.INTERNET_OPTION_PER_CONNECTION_OPTION, optionListPtr, Marshal.SizeOf(optionList));
            if (iReturn == false)
            {
                Win32Exception exception = new Win32Exception(Marshal.GetLastWin32Error());
                throw exception;
            }
            else
            {
                iReturn = InternetOptionSettingsChanged();
                //if (iReturn == true)
                //{
                //    iReturn = InternetOptionRefresh();
                //}
            }

            // free the COM memory
            Marshal.FreeCoTaskMem(optionListPtr);

            return(iReturn);
        }
Exemplo n.º 4
0
 public extern static bool InternetQueryOptionList(IntPtr Handle, InternetOption OptionFlag, ref InternetPerConnectionOptionList OptionList, ref int size);
Exemplo n.º 5
0
 private static extern bool InternetQueryOption(
     IntPtr hInternet,
     int dwOption,
     ref InternetPerConnectionOptionList optionsList,
     ref int bufferLength
     //IntPtr lpBuffer,		//Pointer to a buffer that contains the option setting.
     //int lpdwBufferLength	//size of lpBuffer, in bytes.
     );
Exemplo n.º 6
0
        private static InternetPerConnectionOption GetInternetConnectionOption(PerConnectionOption pco)
        {
            //Allocate the list and option.
            InternetPerConnectionOptionList perConnOptList = new InternetPerConnectionOptionList();
            InternetPerConnectionOption ico = new InternetPerConnectionOption();
            //pin the option structure
            GCHandle gch = GCHandle.Alloc(ico, GCHandleType.Pinned);
            //initialize the option for the data we want
            ico.option = pco;
            //Initialize the option list for the default connection or LAN.
            int listSize = Marshal.SizeOf(perConnOptList);
            perConnOptList.size = listSize;
            perConnOptList.connection = IntPtr.Zero;
            perConnOptList.optionCount = 1;
            perConnOptList.optionError = 0;
            // figure out sizes & offsets
            int icoSize = Marshal.SizeOf(ico);
            int optionTotalSize = icoSize;
            // alloc enough memory for the option
            perConnOptList.options =
                Marshal.AllocCoTaskMem(icoSize);

            long icoOffset = (long)perConnOptList.options + (long)icoSize;
            // Make pointer from the structure
            IntPtr optionListPtr = perConnOptList.options;
            Marshal.StructureToPtr(ico, optionListPtr, false);

            //Make the query
            if (InternetQueryOption(
                IntPtr.Zero,
                (int)InternetOption.INTERNET_OPTION_PER_CONNECTION_OPTION,  //75
                ref perConnOptList,
                ref listSize) == true)
            {
                //retrieve the value
                ico =
                    (InternetPerConnectionOption)Marshal.PtrToStructure(perConnOptList.options,
                                            typeof(InternetPerConnectionOption));
            }
            // free the COM memory
            Marshal.FreeCoTaskMem(perConnOptList.options);
            //unpin the structs
            gch.Free();

            return ico;
        }
Exemplo n.º 7
0
        private static bool CallInternetSetOption(InternetPerConnectionOption[] options)
        {
            InternetPerConnectionOptionList optionList = new InternetPerConnectionOptionList();
            optionList.size = Marshal.SizeOf(optionList);
            optionList.connection = IntPtr.Zero;  //Default Connection
            optionList.optionCount = options.Length;
            optionList.optionError = 0;
            optionList.options = VarPtr(options);

            int optionListSize = Marshal.SizeOf(optionList);
            IntPtr optionListPtr = Marshal.AllocCoTaskMem(optionListSize);
            Marshal.StructureToPtr(optionList, optionListPtr, true);

            bool iReturn;
            iReturn = InternetSetOption(IntPtr.Zero, (int)InternetOption.INTERNET_OPTION_PER_CONNECTION_OPTION, optionListPtr, Marshal.SizeOf(optionList));
            if (iReturn == false)
            {
                Win32Exception exception = new Win32Exception(Marshal.GetLastWin32Error());
                throw exception;
            }
            else
            {
                iReturn = InternetOptionSettingsChanged();
                //if (iReturn == true)
                //{
                //    iReturn = InternetOptionRefresh();
                //}
            }

            // free the COM memory
            Marshal.FreeCoTaskMem(optionListPtr);

            return iReturn;
        }