extern外部方法使用C#的实现方法
2023-06-13 09:15:37 时间
本文实例讲述了extern外部方法使用C#的方法。分享给大家供大家参考。具体分析如下:
外部方法使用C#步骤如下:
1、增加引用usingSystem.Runtime.InteropServices;
2、声明和实现的连接[DllImport("kernel32",SetLastError=true)]
3、声明外部方法publicstaticexternintGetCurrentDirectory(inta,StringBuilderb);
4、对外部方法操作GetCurrentDirectory(300,pathstring);
具体实现代码如下:
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#程序设计有所帮助。
相关文章
- C# 调用js库的方法
- C程序操作MySQL数据库的锁表实现方法(c# mysql 锁表)
- C#文件上传默认最大为4M的解决方法
- C#中隐式运行CMD命令行窗口的方法
- c#实现隐藏与显示任务栏的方法详解
- C#运用params修饰符来实现变长参数传递的方法
- C#窗体间通讯处理的几种方法总结
- C#串口通信实现方法
- asp.net中c#自定义事件的实现方法详解
- VisualC#类的定义及实现方法实例解析
- C#实现农历日历的方法
- C#检测是否有危险字符的SQL字符串过滤方法
- C#获得文件属性信息的实现方法
- C#打印绘图的实现方法
- C#实现根据指定容器和控件名字获得控件的方法
- C#实现中英文混合字符串截取的方法
- C#生成互不相同随机数的实现方法