C#类的属性是不是在Visual Basic 6.0中可见(properties of c# cla

2019-06-25 17:23发布

我已经创建了C#中的类,并取得了COM可见属性为true。 不过,我看不出它的属性在Visual Basic 6.0中。 这可能是一个问题吗? 请帮我

Answer 1:

定义一个公共接口,这也是标记有ComVisible特性,和你的类实现这一点。

然后使用tlbexp.exe生成从C#程序集的类型libary:

tlbexp ComServer.dll /out:ComServer.tlb

您需要添加一个引用从VB6类型库,没有装配。 VB6如何知道你的组件实际上是呢? Regasm是如何。 这是REGSVR32的.NET程序集的等价物。

regasm ComServer.dll


Answer 2:

你申请ComVisible(true)上课吗?



Answer 3:

只要您在属性类标记有ComVisible特性(Visual Studio 2005或2008年,或在大会文件中的标记有ComVisible特性的属性设置为True),你应该能够看到在VB6类。 为了得到智能,你需要声明一个接口,给它一个GUID,并执行它如下图所示(请注意,示例代码:你必须创建自己的独特的GUID的两个接口和具体类。

using System.Runtime.InteropServices;
using System.Drawing;

namespace example_namespace
{

    [Guid("1F436D05-1111-3340-8050-E70166C7FC86")]    
    public interface Circle_interface
    {

        [DispId(1)]
        int Radius
        {
            get;
            set;
        }

        [DispId(2)]
        int X
        {
            get;
            set;
        }

        [DispId(3)]
        int Y
        {
            get;
            set;
        }

    }


    [Guid("4EDA5D35-1111-4cd8-9EE8-C543163D4F75"),
        ProgId("example_namespace.Circle_interface"),
        ClassInterface(ClassInterfaceType.None)]
    public class Circle : Circle_interface
    {

        private int _radius;
        private Point _position;
        private bool _autoRedeye;

        public int Radius
        {
            get { return _radius; }
            set { _radius = value; }
        }


        public int X
        {
            get { return _position.X; }
            set { _position.X = value; }
        }


        public int Y
        {
            get { return _position.Y; }
            set { _position.Y = value; }
        }
    }


}


文章来源: properties of c# class is not visible at visual basic 6.0
标签: c# com vb6