extern外部方法使用C#简单例子
2018-06-21 06:53:37来源:未知 阅读 ()
外部方法使用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 ); } }} |
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- Delphi 调用C# 编写的DLL方法 2019-10-28
- Delphi - 调用外部程序并阻塞到外部程序中 2019-09-23
- PHP保留两位小数的几种方法 2019-08-16
- 委托学习笔记后续:泛型委托及委托中所涉及到匿名方法、Lamb 2018-06-21
- MVC学习一:EF 2018-06-21
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash
