C# to VB6 COM events (“object or class does not support the set of events”)

前端 未结 2 1367
北荒
北荒 2021-01-05 23:54

Really pulling my hair out with this one...

I have a C# project with an interface defined as:

/* Externally Accessible API */
[InterfaceType(ComInter         


        
相关标签:
2条回答
  • 2021-01-05 23:59

    I was defining the interface using the delegate instead of the event:

    /* Externally Accesssible Event API */
    [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    public interface ISerialEvent
    {
        [DispId(5)]
        void DataEvent();
    }
    

    should be

    /* Externally Accesssible Event API */
    [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    public interface ISerialEvent
    {
        [DispId(5)]
        void dEvent();
    }
    
    0 讨论(0)
  • 2021-01-06 00:10

    Look at this article here.

    Specifically it looks like you missing a declaration that looks something like this.

    [Guid("9E5E5FB2-219D-4ee7-AB27-E4DBED8E123E"),
        ClassInterface(ClassInterfaceType.None),
        ComSourceInterfaces(typeof(DBCOM_Events))]
        public class DBCOM_Class : DBCOM_Interface
        {
    

    You have this part

    // // Events interface Database_COMObjectEvents 
    [Guid("47C976E0-C208-4740-AC42-41212D3C34F0"), 
    InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    public interface DBCOM_Events 
    {
    }
    

    But without the second the vtable and typelib of the COM object doesn't have the Event Maps needed to work with VB6 (or other COM Consumers).

    You can use the Google search terms "com event" c# and get a bunch of other good results.

    0 讨论(0)
提交回复
热议问题