简体   繁体   English

在Visual Basic 6.0中看不到C#类的属性

[英]properties of c# class is not visible at visual basic 6.0

I have created a class in c# and made the com visible property is true. 我在c#中创建了一个类,并将com可见属性设置为true。 But, i could not see the its properties at visual basic 6.0. 但是,我在Visual Basic 6.0中看不到它的属性。 what could be a problem? 可能是什么问题? please help me 请帮我

Define a public interface that is also ComVisible, and have your class implement that. 定义一个也是ComVisible的公共接口,并让您的类实现该接口。

Then use tlbexp.exe to generate a type libary from your C# assembly: 然后使用tlbexp.exe从C#程序集生成类型库:

tlbexp ComServer.dll /out:ComServer.tlb

You need to add a reference to the type library from VB6, not the assembly. 您需要添加对VB6中类型库的引用,而不是程序集。 How does VB6 know where your assembly actually is then? VB6如何知道装配体实际在哪里? Regasm is how. 高潮是怎么回事。 It is the equivalent of regsvr32 for .net assemblies. 对于.net程序集,它相当于regsvr32。

regasm ComServer.dll

您是否将ComVisible(true)应用于课程?

As long as you make your class ComVisible in Properties (of Visual Studio 2005 or 2008, or set the ComVisible attribute to True in the Assembly file), you should be able to see your class in VB6. 只要使您的类在Properties(Visual Studio 2005或2008的Properties)中成为ComVisible,或在Assembly文件中将ComVisible属性设置为True,您就应该能够在VB6中看到您的类。 To get intellisense you need to declare an interface, give it a GUID, and implement it as shown in the example code below (Note: you have to create your own unique GUID's for both the interface and the concrete class. 要获得智能感知,您需要声明一个接口,为其提供一个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; }
        }
    }


}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM