【问题标题】:properties of c# class is not visible at visual basic 6.0c# 类的属性在 Visual Basic 6.0 中不可见
【发布时间】:2010-11-10 05:43:04
【问题描述】:

我在 c# 中创建了一个类,并使 com 可见属性为 true。但是,我在 Visual Basic 6.0 中看不到它的属性。可能是什么问题?请帮帮我

【问题讨论】:

  • 有时我忘记包含诸如 public 之类的通用词,每个人都会遇到这种情况,您可能需要重新检查类及其属性访问修饰符。

标签: c# com vb6


【解决方案1】:

定义一个也是 ComVisible 的公共接口,并让你的类实现它。

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

tlbexp ComServer.dll /out:ComServer.tlb

您需要从 VB6 添加对类型库的引用,而不是程序集。那么VB6如何知道你的程序集实际在哪里呢? Regasm 是怎么回事。它相当于 .net 程序集的 regsvr32。

regasm ComServer.dll

【讨论】:

    【解决方案2】:

    你申请ComVisible(true)上课吗?

    【讨论】:

    • 如何将 ComVisible(true) 设置为类?实际上我在 assemblyinfo.cs 中设置为 true
    【解决方案3】:

    只要您在属性(Visual Studio 2005 或 2008 的,或在程序集文件中将 ComVisible 属性设置为 True)中的类 ComVisible,您应该能够在 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; }
            }
        }
    
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-17
      • 1970-01-01
      • 1970-01-01
      • 2012-04-26
      • 2014-10-27
      相关资源
      最近更新 更多