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

首頁 > 編程 > C# > 正文

extern外部方法使用C#的實現(xiàn)方法

2019-10-29 21:47:37
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了extern外部方法使用C#的實現(xiàn)方法,較為詳細的分析了外部方法使用C#的具體步驟與實現(xiàn)技巧,具有一定的參考借鑒價值,需要的朋友可以參考下
 

本文實例講述了extern外部方法使用C#的方法。分享給大家供大家參考。具體分析如下:

外部方法使用C#步驟如下:

1、增加引用using System.Runtime.InteropServices;

2、聲明和實現(xiàn)的連接[DllImport("kernel32", SetLastError = true)]

3、聲明外部方法public static extern int GetCurrentDirectory(int a, StringBuilder b);

4、對外部方法操作 GetCurrentDirectory(300, pathstring);

具體實現(xiàn)代碼如下:

復制代碼代碼如下:
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)]//聲明和實現(xiàn)的連接
        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#程序設計有所幫助。


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 富裕县| 新安县| 日照市| 灵川县| 金华市| 紫阳县| 名山县| 扬州市| 潢川县| 曲靖市| 循化| 建阳市| 微博| 明水县| 娄底市| 陕西省| 迭部县| 九龙城区| 古交市| 虎林市| 南投市| 海安县| 通渭县| 东明县| 河北省| 淄博市| 寻甸| 邳州市| 大丰市| 津市市| 佛坪县| 外汇| 逊克县| 长乐市| 灵璧县| 山东| 嘉鱼县| 肇东市| 黄山市| 金沙县| 英吉沙县|