extern外部方法使用C#简单样例
2016-02-24 21:18
519 查看
外部方法使用C#简单样例
1、添加引用using System.Runtime.InteropServices;
2、声明和实现的连接[DllImport("kernel32", SetLastError = true)]
3、声明外部方法public static extern int GetCurrentDirectory(int a, StringBuilder b);
4、对外部方法操作 GetCurrentDirectory(300, pathstring);
文件在执行时出现"vshost32.exe停止执行"。发现编译的文件换个文件夹后就能够正常执行了。
此文件由朱朱编写。转载请注明出自朱朱家园http://blog.csdn.net/zhgl7688
1、添加引用using System.Runtime.InteropServices;
2、声明和实现的连接[DllImport("kernel32", SetLastError = true)]
3、声明外部方法public static extern int GetCurrentDirectory(int a, StringBuilder b);
4、对外部方法操作 GetCurrentDirectory(300, pathstring);
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices;//引用外部 namespace extern { public partial class DllImportForm : Form { public DllImportForm() { InitializeComponent(); } [DllImport("kernel32", SetLastError = true)]//声明和实现的连接 public static extern int GetCurrentDirectory(int a, StringBuilder b);//外部方法 private void btnDisplay_Click(object sender, EventArgs e) { StringBuilder pathstring=new StringBuilder ();//返回路径 GetCurrentDirectory(300, pathstring); this.listBox1.Items.Add (pathstring ); } } }
文件在执行时出现"vshost32.exe停止执行"。发现编译的文件换个文件夹后就能够正常执行了。
此文件由朱朱编写。转载请注明出自朱朱家园http://blog.csdn.net/zhgl7688
相关文章推荐
- 海康SDK编程指南(C#二次开发版本)
- C#FileStream文件流(字符)
- C#高级编程(三)
- 如何有效的使用C#读取文件
- 【C#】Color颜色对照表
- C#之构造方法
- C# 结构的特点
- C#-StructLayoutAttribute(结构体布局)
- C#中的IntPtr类型
- C#将一个excel工作表根据指定范围拆分为多个excel文件
- C# DataTable Compute方法的使用
- C#访问openfire服务器之一:服务端的安装、客户端的简介
- C#调用金数据API
- C#访问openfire服务器之三:一次成功的登录
- C#原理
- C# using 三种使用方式
- C#怎么设置子窗体在主窗体中居中显示
- C#进阶系列——WebApi接口测试工具:WebApiTestClient
- C#创建唯一的订单号, 考虑时间因素
- C# 串口通讯