国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

extern外部方法使用C#的實現方法

2020-01-24 02:13:39
字體:
來源:轉載
供稿:網友

本文實例講述了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 );
 
        }
    }
}

希望本文所述對大家的C#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 德化县| 平和县| 武乡县| 阳高县| 长沙市| 翼城县| 庆城县| 锦州市| 仁布县| 广平县| 龙江县| 张家口市| 乐亭县| 新源县| 简阳市| 张家港市| 杭锦后旗| 晋江市| 简阳市| 二连浩特市| 合肥市| 甘谷县| 固安县| 滕州市| 平远县| 富平县| 吐鲁番市| 肇州县| 江都市| 紫金县| 田林县| 南城县| 嘉定区| 循化| 嫩江县| 和田县| 阿瓦提县| 襄垣县| 镇巴县| 屯昌县| 应城市|