How do I import this function from inet.dll into .NET?
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#?
Have a look at http://pinvoke.net for documentation and sample code.
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) ;
}
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);
精彩评论