我之前从未这样做过,而且我对如何将数据类型转换为C#感到困惑。这是function I'm trying to import:
BOOL InternetSetOption(
__in HINTERNET hInternet,
__in DWORD dwOption,
__in LPVOID lpBuffer,
__in DWORD dwBufferLength
);
我要做的就是在WebBrowser
控件上设置代理设置。我将这些数据类型映射到C#?
答案 0 :(得分:2)
请查看http://pinvoke.net以获取文档和示例代码。
答案 1 :(得分:0)
尝试以下签名
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) ;
}
答案 2 :(得分:0)
InternetSetOption
函数的PInvoke page指定了如何声明它,以及一些方便的示例代码。
单独的声明如下:
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);