Beispiel #1
0
        private static string GetProxyString(PerConnectionOption optionToCheck)
        {
            InternetPerConnectionOption returnOption = GetInternetConnectionOption(optionToCheck);
            string proxyInfo = Marshal.PtrToStringAuto(returnOption.value.valuePtr);

            return(proxyInfo);
        }
Beispiel #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);
        }
Beispiel #3
0
 private static string GetProxyString(PerConnectionOption optionToCheck)
 {
     InternetPerConnectionOption returnOption = GetInternetConnectionOption(optionToCheck);
     string proxyInfo = Marshal.PtrToStringAuto(returnOption.value.valuePtr);
     return proxyInfo;
 }
Beispiel #4
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;
        }