extern外部方法使用C#的实现方法
本文实例讲述了extern外部方法使用C#的方法。分享给大家供大家参考。具体分析如下:
外部方法使用C#步骤如下:
1、增加引用usingSystem.Runtime.InteropServices;
2、声明和实现的连接[DllImport("kernel32",SetLastError=true)]
3、声明外部方法publicstaticexternintGetCurrentDirectory(inta,StringBuilderb);
4、对外部方法操作GetCurrentDirectory(300,pathstring);
具体实现代码如下:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingSystem.Runtime.InteropServices;//引用外部
namespaceextern
{
publicpartialclassDllImportForm:Form
{
publicDllImportForm()
{
InitializeComponent();
}
[DllImport("kernel32",SetLastError=true)]//声明和实现的连接
publicstaticexternintGetCurrentDirectory(inta,StringBuilderb);//外部方法
privatevoidbtnDisplay_Click(objectsender,EventArgse)
{
StringBuilderpathstring=newStringBuilder();//返回路径
GetCurrentDirectory(300,pathstring);
this.listBox1.Items.Add(pathstring);
}
}
}
希望本文所述对大家的C#程序设计有所帮助。
热门推荐
10 爱情贺卡祝福语简短英语
11 娃娃考试祝福语幽默简短
12 结婚祝福语简短精辟 兄弟
13 表达朋友的祝福语简短
14 春节感恩祝福语简短的
15 结婚祝福语粤语大全简短
16 恭喜朋友升职祝福语简短
17 圣诞饭店祝福语大全简短
18 建工系毕业祝福语简短