.NET Framework 调用Win32 dll函数
示例
using System.Runtime.InteropServices;
class PInvokeExample
{
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern uint MessageBox(IntPtr hWnd, String text, String caption, int options);
public static void test()
{
MessageBox(IntPtr.Zero, "Hello!", "Message", 0);
}
}声明一个功能staticexternsttingDllImportAttribute其Value属性设置为.dll文件的名称。不要忘记使用System.Runtime.InteropServices名称空间。然后将其作为常规静态方法调用。
平台调用服务将负责加载.dll并找到所需的功能。在大多数简单情况下,P/Invoke还将封送参数并与.dll返回值(即从.NET数据类型转换为Win32的数据类型,反之亦然)。
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短