您的位置:首页 > 编程语言 > C#

初步学习“C#接口”(3)

2008-07-24 10:52 274 查看
在 .NET 框架程序中通过DllImport使用 Win32 API

.NET 框架程序可以通过静态 DLL 入口点的方式来访问本机代码库。DllImport 属性用于指定包含外部方法的实现的dll 位置。

DllImport 属性定义如下:

namespace System.Runtime.InteropServices

using System;

using System.Runtime.InteropServices;

class MainApp

{ //通过DllImport引用user32.dll类。MessageBox来自于user32.dll类

 [DllImport("user32.dll", EntryPoint="MessageBox")]

 public static extern int MessageBox(int hWnd, String strMessage, String strCaption, uint uiType);

 public static void Main()

 {

  MessageBox( 0, "您好,这是 PInvoke!", ".NET", 0 );

 }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: