DllImportAttribute 类

来源:互联网 发布:淘宝买车分期付款 编辑:程序博客网 时间:2024/06/07 01:39

原文链接:https://msdn.microsoft.com/zh-cn/library/system.runtime.interopservices.dllimportattribute(v=vs.100).aspx

指示该特性化方法由非托管动态链接库 (DLL) 作为静态入口点公开。

哇,这句话好绕啊,头都大了。

下面的代码示例演示如何使用 DllImportAttribute 属性导入 Win32 MessageBox 函数。然后,代码示例将调用导入的方法。

using System;using System.Runtime.InteropServices;class Example{    // Use DllImport to import the Win32 MessageBox function.    [DllImport("user32.dll", CharSet = CharSet.Auto)]    public static extern int MessageBox(IntPtr hWnd, String text, String caption, uint type);    static void Main()    {        // Call the MessageBox function using platform invoke.        MessageBox(new IntPtr(0), "Hello World!", "Hello Dialog", 0);    }}