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

℡╲_俬逩灬. 提交于 2020-01-21 09:01:27

问题


I have created a class in c# and made the com visible property is true. But, i could not see the its properties at visual basic 6.0. what could be a problem? please help me


回答1:


Define a public interface that is also ComVisible, and have your class implement that.

Then use tlbexp.exe to generate a type libary from your C# assembly:

tlbexp ComServer.dll /out:ComServer.tlb

You need to add a reference to the type library from VB6, not the assembly. How does VB6 know where your assembly actually is then? Regasm is how. It is the equivalent of regsvr32 for .net assemblies.

regasm ComServer.dll



回答2:


Do you apply ComVisible(true) to class?




回答3:


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. 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.

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; }
        }
    }


}


来源:https://stackoverflow.com/questions/1118309/properties-of-c-sharp-class-is-not-visible-at-visual-basic-6-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!