点点滴滴访问量:
外部方法
    
C#引入了extern修饰符来表示外部方法,外部方法是用C#以外的语言实现的方法,例如win32 API 函数。
    
API(Application Programming Interface)Windows应用编程的接口

例:using System;

using System.Runtime.InteropServices; //C#中调用API函数,首先必须导入一个Namespace,这条语句就是实现这个功能

 

namespace waibufangfa

{

    class Class1

    {

    [DllImport ("user32.dll")]   //接着声明一个API

    static extern int MessageBoxA(int hWnd,string msg,string caption,int type); // 其中DllImport属性被用来导入dll,这个dll中包括调用的外部方法。关键安extern表示这个方法将在工程外部执行,使用DllImport导入的方法必须使用extern修饰符。

        [STAThread]

        static void Main(string[] args)

        {

        MessageBoxA(0,"Hello, World!","This is called from a C# app!",0);

        }

    }

}

posted on 2006-04-12 16:43  sopper  阅读(420)  评论(0编辑  收藏  举报