tags:

views:

114

answers:

3

I've never done this before, and I'm kind of stumped as to how I would translate the datatypes into C#. Here is the function I'm trying to import:

BOOL InternetSetOption(
  __in  HINTERNET hInternet,
  __in  DWORD dwOption,
  __in  LPVOID lpBuffer,
  __in  DWORD dwBufferLength
);

All I'm trying to do is set the proxy settings on a WebBrowser control. What datatypes would I map these to in C#?

+2  A: 

Have a look at http://pinvoke.net for documentation and sample code.

M4N
This site is awesome, thanks.
ryeguy
A: 

Try the following signature

public partial class NativeMethods {

    /// Return Type: BOOL->int
    ///hInternet: void*
    ///dwOption: DWORD->unsigned int
    ///lpBuffer: LPVOID->void*
    ///dwBufferLength: DWORD->unsigned int
    [System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint="InternetSetOption")]
    [return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]
public static extern  bool InternetSetOption([System.Runtime.InteropServices.InAttribute()] System.IntPtr hInternet, uint dwOption, [System.Runtime.InteropServices.InAttribute()] System.IntPtr lpBuffer, uint dwBufferLength) ;

}
JaredPar
A: 

The PInvoke page for the InternetSetOption function specifies how it can be declared, along with some handy sample code.

The declarations alone would be the following:

public 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);
Noldorin