您的位置:首页 > 编程语言 > C#

C#调用Dll文件中方法的简单应用

2015-01-29 14:21 906 查看

参考:http://www.cnblogs.com/Asuphy/p/4206623.html


直接看代码,最简单的引入,只需要3步:

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;
//第一部,开启引入的功能
//这个命名空间必须引入,否则使用不了DllImport
using System.Runtime.InteropServices;

namespace ImportDllFile
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
//第三步,使用方法
MsgBox(0,"C#调用DLL文件","这是标题",0x30);
}

//第二步,引入所要使用的dll文件,及要调用的函数
//中括号,直接使用user32.dll即可,EntryPoint说明引用Dll中的函数名,
//这里MsgBox是它的别名
[DllImport("user32.dll", EntryPoint = "MessageBoxA")]
public static extern int MsgBox(int hWnd, string msg, string caption, int type);
}
}


View Code

DLL中部分的参数类型所对应C#中的参数类型如下:
http://www.cnblogs.com/ysharp/archive/2012/05/25/2517803.html
附:常用的Dll集合,介绍与例子
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: