这篇文章主要介绍了C# 编译生成dll文件供程序调用的两种方法,需要的朋友可以参考下
一、使用vs2017 创建动态dll文件
方法一:
1、新建-项目-类库
2、创建一个.cs文件 写入代码,例如:建立一个Windows窗体
略丑,简单明了。。。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ClassLibrary1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("调用成功!");
}
}
}
3、运行文件,就会在Debug目录下生成ClassLibrary1.dll文件
方法二:
或者在已经写好的模块中,选择项目,右键-属性-输出类型处选择类库
最后 右键-重新生成
二、调用ClassLibrary1.dll文件方法
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using ClassLibrary1; //引入命名空间
namespace 调用DLL
{
public partial class Fo : Form
{
public Fo()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form1 f = new Form1(); //实例化对象 调用
f.Show();
}
}
}
总结
以上所述是小编给大家介绍的C# 编译生成dll文件供程序调用的两种方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程学习网网站的支持!