`

C#生成dll与调用

    博客分类:
  • VS
阅读更多

生成COM组件

1.打开VS[文件]->[新建]->[项目]->[类库]

2.编辑新生成class代码,EG

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TTT
{
    public interface MyInterface
    {
        int add(int a, int b);
    }

    public class MyClass : MyInterface
    {
        public int add(int a, int b)
        {
            return a + b;
        }
    }
}

 3.编辑AssemblyInfo.cs文件

将assembly:ComVisible(false)改为true

4.在项目上右键——属性

(1.应用程序——程序集信息——选中“使程序集COM可见”

(2.生成——选中“为COM互操作注册”

(3.签名——选中“为程序集签名”,去掉“使用密码保护密钥文件

5.生成

 

 

 

调用COM组件

1.引用刚生成的dll,直接引路径也行

2.引用dll的命名空间,EG:using TTT

3.可以调用ttt里边的类了

完成

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics