INTERNET_PROXY_INFO ni iru iwọle DWORD ati awọn itọka okun meji. Ibeere abinibi tun nilo aaye buffer to fun data proxy rẹ; Marshal.SizeOf ti ẹya kekere ti a ṣakoso kii ṣe buffer abajade pipe ti ipari oniyipada.

Oluranlọwọ ibaramu desktop le lo ibi iwọle ANSI ki o daakọ awọn okun naa ṣaaju ki o to tu buffer ibeere yẹn silẹ:

static class WinInetProxy
{
    [System.Runtime.InteropServices.StructLayout(
        System.Runtime.InteropServices.LayoutKind.Sequential)]
    struct ProxyInfo
    {
        public uint AccessType;
        public IntPtr Proxy;
        public IntPtr Bypass;
    }

    [System.Runtime.InteropServices.DllImport(
        "wininet.dll", EntryPoint = "InternetQueryOptionA",
        SetLastError = true)]
    [return: System.Runtime.InteropServices.MarshalAs(
        System.Runtime.InteropServices.UnmanagedType.Bool)]
    static extern bool Query(
        IntPtr handle, uint option, IntPtr buffer, ref uint size);

    public static (uint Type, string Proxy, string Bypass) Read()
    {
        uint size = 0;
        Query(IntPtr.Zero, 38, IntPtr.Zero, ref size);
        int error = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
        if (error != 122 || size == 0)
            throw new System.ComponentModel.Win32Exception(error);

        IntPtr buffer = System.Runtime.InteropServices.Marshal
            .AllocHGlobal(checked((int)size));
        try
        {
            if (!Query(IntPtr.Zero, 38, buffer, ref size))
                throw new System.ComponentModel.Win32Exception(
                    System.Runtime.InteropServices.Marshal.GetLastWin32Error());
            var value = System.Runtime.InteropServices.Marshal
                .PtrToStructure<ProxyInfo>(buffer);
            return (value.AccessType,
                System.Runtime.InteropServices.Marshal.PtrToStringAnsi(value.Proxy) ?? "",
                System.Runtime.InteropServices.Marshal.PtrToStringAnsi(value.Bypass) ?? "");
        }
        finally
        {
            System.Runtime.InteropServices.Marshal.FreeHGlobal(buffer);
        }
    }
}

38 ni INTERNET_OPTION_PROXY; 122 ni ERROR_INSUFFICIENT_BUFFER. Ipe akọkọ gba iye baiti ti o nilo, ati pe ekeji kun ipin yẹn. Ti abajade ba dagba laarin awọn ipe, a royin ikuna keji dipo kika buffer ti o kere ju.

Jẹ ki AccessType jẹ uint. Ninu ilana 64-bit o wa ni DWORD 32-bit, nigba ti awọn aaye itọka gbooro pẹlu faaji ilana naa. Eto ilana deede n pese isọdi ti o yẹ.

Apeere yii kan buffer abajade aṣayan 38. Maṣe fi apẹẹrẹ nini rẹ han ni ojú afọju lori INTERNET_OPTION_PER_CONNECTION_OPTION, ti awọn aṣayan okun rẹ ti a da pada nilo mimọ lọtọ ti a ṣe akọsilẹ.

Abajade ṣapejuwe atunto WinINet ni agbegbe mimu ti a yan. Kii ṣe ipinnu PAC fun URL lainidii tabi ijabọ ti ipa ọna gangan ti aṣawakiri kọọkan. Nigbati okun proxy ti a da pada jẹ maapu kan pato fun ilana, tọju ẹya yẹn dipo ki o tọju rẹ bi opin kan. WinINet jẹ API desktop; awọn ohun elo iṣẹ nilo eto WinHTTP ti a ṣe atilẹyin wọn.

Àwọn àpilẹ̀kọ tó jọra