extern外部方法使用C#简单样例
外部方法使用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
extern外部方法使用C#简单样例的更多相关文章
- extern外部方法使用C#简单例子
外部方法使用C#简单例子 1.增加引用using System.Runtime.InteropServices; 2.声明和实现的连接[DllImport("kernel32", ...
- spring事务详解(二)简单样例
系列目录 spring事务详解(一)初探事务 spring事务详解(二)简单样例 spring事务详解(三)源码详解 spring事务详解(四)测试验证 spring事务详解(五)总结提高 一.引子 ...
- velocity简单样例
velocity简单样例整体实现须要三个步骤,详细例如以下: 1.创建一个Javaproject 2.导入须要的jar包 3.创建须要的文件 ============================= ...
- 自己定义隐式转换和显式转换c#简单样例
自己定义隐式转换和显式转换c#简单样例 (出自朱朱家园http://blog.csdn.net/zhgl7688) 样例:对用户user中,usernamefirst name和last name进行 ...
- VC6 鼠标钩子 最简单样例
Windows系统是建立在事件驱动的机制上的,说穿了就是整个系统都是通过消息的传递来实现的.而钩子是Windows系统中非常重要的系统接口,用它能够截获并处理送给其它应用程序的消息,来完毕普通应用程序 ...
- Swift - 动画效果的实现方法总结(附样例)
在iOS中,实现动画有两种方法.一个是统一的animateWithDuration,另一个是组合出现的beginAnimations和commitAnimations.这三个方法都是类方法. 一,使用 ...
- gtk+3.0的环境配置及基于gtk+3.0的python简单样例
/********************************************************************* * Author : Samson * Date ...
- ListView中pointToPosition()方法使用具体演示样例
MainActivity例如以下: package cc.testpointtoposition; import java.util.ArrayList; import java.util.HashM ...
- java 使用tess4j实现OCR的最简单样例
网上很多教程没有介绍清楚tessdata的位置,以及怎么配置,并且对中文库的描述也存在问题,这里介绍一个最简单的样例. 1.使用maven,直接引入依赖,确保你的工程JDK是1.8以上 <dep ...
随机推荐
- C#中使用MATLAB
原文 http://www.cnblogs.com/sorex/archive/2012/08/01/2617469.html 闲来无聊写篇文章聊以慰藉. 本文写了Matlab的2种基本调用方式,且同 ...
- Tar打包、压缩与解压缩到指定目录的方法
tar在linux上是常用的打包.压缩.加压缩工具,他的参数很多,折里仅仅列举常用的压缩与解压缩参数 参数: -c :create 建立压缩档案的参数: -x : 解压缩压缩档案的参数: -z : 是 ...
- 链表k个节点反向
问题: 以k个元素为一组,反转单向链表.比如: 输入: 1->2->3->4->5->6->7->8->null and k = 3 输出:3-> ...
- 【HDU】4092 Nice boat(多校第四场1006) ——线段树 懒惰标记
Nice boat Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) To ...
- 函数dirname--返回路径中的目录部分
http://blog.chinaunix.net/uid-122937-id-142880.html dirname() 函数作用 返回路径中的目录部分. 语法 dirname(path) ...
- mysql 1449 : The user specified as a definer ('montor'@'%') does not exist
grant all privileges on *.* to root@"%" identified by "."; flush privileges;
- 位运算 (&|)与--或 一位数组表示多种意思~~ 与--或
var arr:Array = [0,1,2,4,8,16] var gate:int = 0; gate |= arr[1] gate |= arr[2] gate |= arr[3] trace( ...
- Windows下搭建Eclipse+Android4.0开发环境
官方搭建步骤: http://developer.android.com/index.html 搭建好开发环境之前须要下载以下几个文件包: 一.安装Java执行环境JRE(没这个Eclipse执行不起 ...
- linq to sql简单使用
1.新建一个winform项目. 2.添加一个Linq to Sql 类,命名为Northwind 3.打开服务器资源管理器,将表拖动到linq to sql 类,实体类就由Vs生成了 4.实例化Da ...
- UVA 1615 Highway
题意: 有一条沿x轴正方向,长为L的高速公路,n个村庄,要求修建最少的公路出口数目,使得每个村庄到出口的距离不大于D. 分析: 每个村子可建出口的距离是(l-d,r+d).将所有区间按右端点排序,若需 ...