首页 > Windows开发 > 详细

extern外部方法使用C#简单例子

时间:2017-03-06 12:16:45      阅读:222      评论:0      收藏:0      [点我收藏+]

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

 

        }

    }

}

 

 

extern外部方法使用C#简单例子

原文:http://www.cnblogs.com/gyc19920704/p/6508663.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!