外部方法使用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#简单样例的更多相关文章

  1. extern外部方法使用C#简单例子

    外部方法使用C#简单例子 1.增加引用using System.Runtime.InteropServices; 2.声明和实现的连接[DllImport("kernel32", ...

  2. spring事务详解(二)简单样例

    系列目录 spring事务详解(一)初探事务 spring事务详解(二)简单样例 spring事务详解(三)源码详解 spring事务详解(四)测试验证 spring事务详解(五)总结提高 一.引子 ...

  3. velocity简单样例

    velocity简单样例整体实现须要三个步骤,详细例如以下: 1.创建一个Javaproject 2.导入须要的jar包 3.创建须要的文件 ============================= ...

  4. 自己定义隐式转换和显式转换c#简单样例

    自己定义隐式转换和显式转换c#简单样例 (出自朱朱家园http://blog.csdn.net/zhgl7688) 样例:对用户user中,usernamefirst name和last name进行 ...

  5. VC6 鼠标钩子 最简单样例

    Windows系统是建立在事件驱动的机制上的,说穿了就是整个系统都是通过消息的传递来实现的.而钩子是Windows系统中非常重要的系统接口,用它能够截获并处理送给其它应用程序的消息,来完毕普通应用程序 ...

  6. Swift - 动画效果的实现方法总结(附样例)

    在iOS中,实现动画有两种方法.一个是统一的animateWithDuration,另一个是组合出现的beginAnimations和commitAnimations.这三个方法都是类方法. 一,使用 ...

  7. gtk+3.0的环境配置及基于gtk+3.0的python简单样例

    /*********************************************************************  * Author  : Samson  * Date   ...

  8. ListView中pointToPosition()方法使用具体演示样例

    MainActivity例如以下: package cc.testpointtoposition; import java.util.ArrayList; import java.util.HashM ...

  9. java 使用tess4j实现OCR的最简单样例

    网上很多教程没有介绍清楚tessdata的位置,以及怎么配置,并且对中文库的描述也存在问题,这里介绍一个最简单的样例. 1.使用maven,直接引入依赖,确保你的工程JDK是1.8以上 <dep ...

随机推荐

  1. Inno Setup设定只运行一个安装包

    原文 http://zwkufo.blog.163.com/blog/static/25882512010292526944/?suggestedreading&wumii 在安装包中,经常会 ...

  2. 原生应用native、Web应用、混合应用hybrid:3者的优缺点解析

    最近原生应用.Web应用.混合应用的名字让我们听得比较熟悉了,现在我们就通过评析各种应用的优缺点来更进一步看看这三者的区别. 一. 原生应用: 你使用过微软PowerPoint 或者 Word吧?这些 ...

  3. logstash 处理多行

    2.2.2 多行事件编码: zjtest7-frontend:/usr/local/logstash-2.3.4/bin# ./plugin list | grep multi Ignoring ff ...

  4. "NO 3D support is available from the host"

    https://forums.opensuse.org/showthread.php/494522-No-3d-Support-or-graphics-accelleration http://ask ...

  5. Web scraping with Python (part II) « Jean, aka Sig(gg)

    Web scraping with Python (part II) « Jean, aka Sig(gg) Web scraping with Python (part II)

  6. phonegap开发app中踩过的那些坑

    把遇到的问题列出来,假设有解决方式的,偶也会写下来.假设大家有更好解决方法的.欢迎留言噢 phonegap 2.9无法触发deviceready事件 亲们能够看下控制台有木有报错.假设有提示cordo ...

  7. C# 几种退出程序的方式

    C# WinForm程序退出的方法 1.this.Close(); 只是关闭当前窗口,若不是主窗体的话,是无法退出程序的,另外若有托管线程(非主线程),也无法干净地退出: 2.Application. ...

  8. WCF Test Client

    WCF测试客户端(WCF Test Client)是一个用来测试WCF服务程序的调试工具,能够使开发WCF服务更加方便. 在Visual Studio之外打开WCF测试客户端有两种方法:第一种方法是到 ...

  9. Nodejs随笔(三):全局对象之global

    首先,进入node REPL: mesogene@mesogene-team:~$ node > 查看global对象,发现其他全局对象(包括Buffer.require对象)以及全局方法都包含 ...

  10. hdu1004Let the Balloon Rise

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...