虚位以待(AD)
虚位以待(AD)
首页 > 软件编程 > C#编程 > C# 编译生成dll文件供程序调用的两种方法

C# 编译生成dll文件供程序调用的两种方法
类别:C#编程   作者:码皇   来源:互联网   点击:

这篇文章主要介绍了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文件供程序调用的两种方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!

您可能感兴趣的文章:

  • c# 动态加载dll文件,并实现调用其中的方法(推荐)
  • C#中调用DLL时未能加载文件或程序集错误的处理方法(详解)
  • C#生成DLL文件的方法小结
  • C#生成DLL文件的方法
  • C#中实现在32位、64位系统下自动切换不同的SQLite dll文件
  • 将ocx文件转换成C#程序引用的DLL文件的办法
  • mssql 存储过程调用C#编写的DLL文件
  • c#下将.cs文件编译成dll
相关热词搜索: C dll文件 编译生成dll