How do I use InternetSetOption?
Asked Answered
T

1

2

This question:

Using Proxy with web browser control

Told me to use "InternetSetOption". How do I use it? How might I implement it in code (example?)?

Thanks!

Tamqrah answered 15/6, 2011 at 6:8 Comment(6)
For god's sake, @Jacob. You don't ask a new question every time you don't get the answer you want, you edit your question and make it BETTER. You've asked variants of this particular question at least 5 times now.Enunciate
Possible duplicate: #6353280Enunciate
Possible duplicate: #6247868Enunciate
Possible duplicate: #6247720Enunciate
Possible duplicate: #6246998Enunciate
Possible duplicate: #6245142Enunciate
S
6
public struct Struct_INTERNET_PROXY_INFO
{
    public int dwAccessType;
    public IntPtr proxy;
    public IntPtr proxyBypass;
}

[DllImport("wininet.dll", SetLastError = true)]
private static extern bool InternetSetOption(
    IntPtr hInternet,
    int dwOption,
    IntPtr lpBuffer,
    int lpdwBufferLength);

private void RefreshIESettings(string strProxy)
{
    const int INTERNET_OPTION_PROXY = 38;
    const int INTERNET_OPEN_TYPE_PROXY = 3;

    Struct_INTERNET_PROXY_INFO struct_IPI;

    struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
    struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy);
    struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local");

    IntPtr intptrStruct = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI));

    // Converting structure to IntPtr
    Marshal.StructureToPtr(struct_IPI, intptrStruct, true);

    bool iReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, Marshal.SizeOf(struct_IPI));
}

private void Usage()
{
    RefreshIESettings("1.2.3.4:8080");
    object nullObject = 0;
    string strTemp = "";
    object nullObjStr = strTemp;
    axWebBrowser1.Navigate("http://test.com", ref nullObject, ref nullObjStr, ref nullObjStr, ref nullObjStr);
}
Suint answered 15/6, 2011 at 6:12 Comment(4)
It says that 'axWebBrowser1' does not exist in current context. Marshal does not exist in current context. DllImport could not be found. -- What's wrong? What am I missing?Tamqrah
@Jacob - of course axWebBrowser1 does not exist, because it is an example. You need to replace with the reference to your WebBrowswer control.Suint
Well, what about 'Marshal' and 'DllImport' - won't work without those?Tamqrah
@Jacob - for DllImport add 'using System.Runtime.InteropServices'Suint

© 2022 - 2024 — McMap. All rights reserved.