extern外部方法使用C#简单例子
来源:互联网 发布:格罗姆地狱咆哮知乎 编辑:程序博客网 时间:2024/04/29 01:39
外部方法使用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);
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
0 0
- extern外部方法使用C#简单例子
- extern外部方法使用
- 外部表创建简单例子
- C# 使用app.config文件方法 读取外部配置信息
- C#直接使用DllImport外部Dll的方法
- C#直接使用DllImport外部Dll的方法
- extern 的一个简单使用
- 模板方法模式(Template Method)c#简单例子
- C# 简单的例子
- C#简单代理例子
- C# 简单event例子
- C# POST简单例子
- C#简单异步例子
- C#反射简单例子
- C# webservice简单例子
- C语言外部变量(extern)的使用
- C# 快速使用protobuf的简单方法
- C语言extern关键字定义外部变量--Redis源码extern使用
- POJ1094 - Sorting It All Out
- ASP.NET环境下配置FCKEditor并上传图片及其它文件
- NSNumber, NSValue, NSData
- microlog4android和android-logging-log4j比较
- JNI/NDK开发指南(四)——字符串处理
- extern外部方法使用C#简单例子
- ZendStudio安装学习笔记
- uva11549 老式计算器 (Floyd判圈 )
- 编写高质量和可维护的代码方法
- 第十七周项目4——生日差几天
- Linux一些学习资源
- Mac下下载android4.2源码,进行源码调试
- 使用Intellij Idea 搭建tomcat 6源码分析环境
- JAVA知识点总结(三)成员变量和局部变量的区别