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 ...
随机推荐
- javascript闭包特性
http://www.cnblogs.com/rubylouvre/archive/2009/07/24/1530074.html var name = "The Window"; ...
- BCB的博客,以及例子(好多传输文件的例子)
http://blog.csdn.net/keyu1711/ http://download.csdn.net/user/keyu1711 http://download.csdn.net/user/ ...
- Unix/Linux环境C编程入门教程(34) 编程管理系统中的用户
1.用户管理相关函数介绍 geteuid(取得有效的用户识别码) 相关函数 getuid,setreuid,setuid 表头文件 #include<unistd.h> #include& ...
- 搭讪培训班 - 名品试用 - YOKA时尚论坛 - YOKA社区
搭讪培训班 - 名品试用 - YOKA时尚论坛 - YOKA社区 搭讪培训班 发贴回复 发新话题 发布投票 搭讪培训班 1330 1 阅读 回复 跳转到指定楼层 加为好友 时尚懒洋洋 工作:无业游 ...
- rpm包下载网站
摘自http://blog.sina.com.cn/s/blog_4942055d0100031a.html rpm包下载网站 http://www.rpmfind.net http://www.rp ...
- TimeSpan类【转】
TimeSpan ts1 = new TimeSpan(DateTime.Now.Ticks); //获取当前时间的刻度数 //执行某操作 ............................ . ...
- 使用Kotlin开发Android应用(I):简单介绍
使用Kotlin开发Android应用(I):简单介绍 @author ASCE1885的 Github 简书 微博 CSDN 原文链接 Kotlin是一门基于JVM的编程语言.它正成长为Androi ...
- IOS中的几中观察监听模式
本文介绍Objective C中实现观察者模式(也被称为广播者/监听者.发布/注册或者通知)的五种方法以及每种方法的价值所在. 该文章将包括: 1 手动广播者和监听者(Broadcaster and ...
- DevExpress.GridControl.gridView的一些注意
1.DevExpress控件组中的GridControl控件不能使横向滚动条有效.现象:控件中的好多列都挤在一起,列宽都变的很小,根本无法正常浏览控件单元格中的内容. 解决: gridView1.Op ...
- 阻止JS事件冒泡传递(cancelBubble 、stopPropagation)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx. ...