extern外部方法使用C#的實(shí)現(xiàn)方法
本文實(shí)例講述了extern外部方法使用C#的方法。分享給大家供大家參考。具體分析如下:
外部方法使用C#步驟如下:
1、增加引用using System.Runtime.InteropServices;
2、聲明和實(shí)現(xiàn)的連接[DllImport("kernel32", SetLastError = true)]
3、聲明外部方法public static extern int GetCurrentDirectory(int a, StringBuilder b);
4、對(duì)外部方法操作 GetCurrentDirectory(300, pathstring);
具體實(shí)現(xiàn)代碼如下:
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)]//聲明和實(shí)現(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 );
}
}
}
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
- C#實(shí)現(xiàn)通過(guò)winmm.dll控制聲音播放的方法
- 基于C#的音樂(lè)播放器主Form實(shí)現(xiàn)代碼
- C# 視頻播放類
- C#通過(guò)熱鍵控制顯示器開關(guān)的方法
- C#動(dòng)態(tài)創(chuàng)建Access數(shù)據(jù)庫(kù)及表的方法
- C#特性 擴(kuò)展方法
- C#實(shí)現(xiàn)遠(yuǎn)程連接ORACLE數(shù)據(jù)庫(kù)的方法
- asp.net中C#實(shí)現(xiàn)手動(dòng)回收內(nèi)存的方法
- C#中WinForm程序退出方法技巧總結(jié)
- C#播放鈴聲最簡(jiǎn)單實(shí)現(xiàn)方法
相關(guān)文章
C#使用隊(duì)列(Queue)解決簡(jiǎn)單的并發(fā)問(wèn)題
這篇文章主要介紹了使用隊(duì)列(Queue)解決簡(jiǎn)單的并發(fā)問(wèn)題,講解的很細(xì)致,喜歡的朋友們可以了解一下2015-07-07C#使用正則表達(dá)式實(shí)現(xiàn)首字母轉(zhuǎn)大寫的方法
這篇文章主要介紹了C#使用正則表達(dá)式實(shí)現(xiàn)首字母轉(zhuǎn)大寫的方法,涉及C#基于正則表達(dá)式操作字符串的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-11-11基于WPF實(shí)現(xiàn)帶蒙版的MessageBox消息提示框
這篇文章主要介紹了如何利用WPF實(shí)現(xiàn)帶蒙版的MessageBox消息提示框,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)或工作有一定幫助,需要的可以參考一下2022-08-08c#數(shù)據(jù)綁定之?dāng)?shù)據(jù)轉(zhuǎn)化為信息的示例
這篇文章主要介紹了c#數(shù)據(jù)綁定中的數(shù)據(jù)轉(zhuǎn)化為信息的示例,需要的朋友可以參考下2014-04-04SQLServer批量插入數(shù)據(jù)的三種方式及性能對(duì)比
本文詳細(xì)講解了SQLServer批量插入數(shù)據(jù)的三種方式及性能對(duì)比,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-12-12