博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
extern外部方法使用C#简单例子
阅读量:4549 次
发布时间:2019-06-08

本文共 1051 字,大约阅读时间需要 3 分钟。

外部方法使用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);

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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 );
 
        
}
    
}
}

转载于:https://www.cnblogs.com/gc2013/p/4182306.html

你可能感兴趣的文章
食用指南
查看>>
CSS3圆角详解(border-radius)
查看>>
Python正则表达式指南
查看>>
前端学习之JavaScript中的 NaN 与 isNaN
查看>>
chrome安装json view插件
查看>>
CSS div 高度满屏
查看>>
页面回发速度由 6 秒减少为 0.6 秒的真实案例!
查看>>
一种实现C++反射功能的想法(一)
查看>>
lvs+keepalived+nginx高性能负载均衡集群
查看>>
XXL-Job高可用集群搭建
查看>>
JDBC
查看>>
CodeForces - 123E Maze
查看>>
ZOJ 1709 Oil Deposits(dfs,连通块个数)
查看>>
安卓开源项目周报0308
查看>>
记可敬可佩的老车同志
查看>>
Maven in 5 Minutes(Windows)
查看>>
常用前端开发工具合集
查看>>
T-SQL:SQL Server-数据开发(经典)
查看>>
IOS 截取字符串
查看>>
键盘控制div移动并且解决停顿问题(原生js)
查看>>