Exemple #1
0
        private static void ExecuteAction(INTERNET_PER_CONN_OPTION[] options, Func <INTERNET_PER_CONN_OPTION_LIST, int, bool> action)
        {
            IntPtr buffer  = Marshal.AllocCoTaskMem(options.Sum(item => Marshal.SizeOf(item)));
            IntPtr current = buffer;

            for (int i = 0; i < options.Length; i++)
            {
                Marshal.StructureToPtr(options[i], current, false);
                current = (IntPtr)((int)current + Marshal.SizeOf(options[i]));
            }

            INTERNET_PER_CONN_OPTION_LIST optionList = new INTERNET_PER_CONN_OPTION_LIST();

            optionList.pOptions   = buffer;
            optionList.Size       = Marshal.SizeOf(optionList);
            optionList.Connection = IntPtr.Zero;

            optionList.OptionCount = options.Length;
            optionList.OptionError = 0;
            int size = Marshal.SizeOf(optionList);

            try
            {
                if (!action(optionList, size))
                {
                    throw new ApplicationException("WinInet: action failed!");
                }
            }
            finally
            {
                Marshal.FreeCoTaskMem(buffer);
            }
        }
Exemple #2
0
        private static void ExecuteAction(INTERNET_PER_CONN_OPTION[] options, Func<INTERNET_PER_CONN_OPTION_LIST, int, bool> action)
        {
            IntPtr buffer = Marshal.AllocCoTaskMem(options.Sum(item => Marshal.SizeOf(item)));
            IntPtr current = buffer;

            for (int i = 0; i < options.Length; i++)
            {
                Marshal.StructureToPtr(options[i], current, false);
                current = (IntPtr)((int)current + Marshal.SizeOf(options[i]));
            }

            INTERNET_PER_CONN_OPTION_LIST optionList = new INTERNET_PER_CONN_OPTION_LIST();

            optionList.pOptions = buffer;
            optionList.Size = Marshal.SizeOf(optionList);
            optionList.Connection = IntPtr.Zero;

            optionList.OptionCount = options.Length;
            optionList.OptionError = 0;
            int size = Marshal.SizeOf(optionList);

            try
            {
                if (!action(optionList, size))
                {
                    throw new ApplicationException("WinInet: action failed!");
                }
            }
            finally
            {
                Marshal.FreeCoTaskMem(buffer);
            }
        }
Exemple #3
0
 internal extern static bool InternetQueryOption(IntPtr handle, INTERNET_OPTION optionFlag, ref INTERNET_PER_CONN_OPTION_LIST optionList, ref int size);
Exemple #4
0
 internal extern static bool InternetQueryOption(IntPtr handle, INTERNET_OPTION optionFlag, ref INTERNET_PER_CONN_OPTION_LIST optionList, ref int size);