用C#开发ActiveX控件给VB使用

有的时候找到的资源是only for .net的。 但如果要在vb里使用,又不想翻译代码。可以考虑把资源写出activeX dll,在vb里使用

步骤如下:

1.在解决方案中添加一个类库项目

2.需要设置类库项目属性->程序集信息->使程序集COM可见

3. 设置该项目的一个属性: 为COM互操作注册, 这样就会自动注册了。

例子代码:

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

namespace activeXDemo
{
    public class clsDemo
    {
        public int Add(int a, int b)
        {
            return a + b;
        }
    }
}

 

编译成dll 

vb加引用。

猜你喜欢

转载自www.cnblogs.com/zitjubiz/p/activex_Csharp_for_vb.html