C#中VB6 COM事件(QUOT;对象或类不支持事件集&QUOT的;) [英] C# to VB6 COM events ("object or class does not support the set of events")

查看:420
本文介绍了C#中VB6 COM事件(QUOT;对象或类不支持事件集&QUOT的;)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

真的拉我的头发与这一个...

Really pulling my hair out with this one...

我有定义为一个接口的C#项目:

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

/* Externally Accessible API */
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface ISerial
{
    [DispId(1)]
    bool Startup();

    [DispId(2)]
    bool Shutdown();

    [DispId(3)]
    bool UserInput_FloorButton(int floor_number);

    [DispId(4)]
    bool Initialize();
}

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

[ComSourceInterfaces(typeof(ISerialEvent), typeof(ISerial))]
[ClassInterface(ClassInterfaceType.None)]
public class SerialIface : ISerial
{
    public delegate void DataEvent();
    public event DataEvent dEvent;

    public bool Initialize()
    {
        //testing the event callback
        if (dEvent != null)
        {
            dEvent();
        }
    }
    ...
}

而VB6的代码如下:

Private WithEvents objSerial As SerialIface

Private Sub objSerial_DataEvent()
    'do something happy'
End Sub

Public Sub Class_Initialize()
    Set objSerial = New SerialIface  '<---this is the line that fails'
    Call objSerial.Initialize  '<--Initialize would trigger DataEvent, if it got this far'
End Sub

好吧,正常的API类型的功能似乎是工作(如果我宣布objSerial没有WithEvents关键字),但我不能为我的生命得到DataEvent工作。它失败,出现对象或类不支持事件集的消息。

Well, the normal API-type functions appear to be working (if I declare objSerial without the WithEvents keyword), but I can't for the life of me get the "DataEvent" to work. It fails with the "object or class does not support the set of events" message.

我想最初的两个接口混为一谈,但随后C#抱怨说DataEvent是在类没有定义。事情是这样的现在,我能够在VB6对象浏览器来查看所有API和一个事件完美 - 一切看起来像它的存在...我只是不能让它实际工作

I'd originally lumped the two interfaces together, but then C# complained that DataEvent was not defined in the class. The way it is currently, I am able to view all of the APIs and the one event perfectly in the VB6 object browser -- everything looks like it's there... I just can't make it actually work!

我敢肯定,我失去了一些东西明显或做一些愚蠢的事 - 但我是新来的整个互操作的业务,所以它只是逃避我完全

I'm sure I'm missing something obvious or doing something stupid -- but I'm new to the whole interop business, so it's just escaping me entirely.

帮助

推荐答案

您的帖子使我不过的解决方案 - !谢谢!

Your post did lead me to the solution however -- thank you!

这并不奇怪,它原来是一个错字。

Not surprisingly, it turned out to be a typo.

/* 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();
}



我用的代表定义接口而不是在活动

再次感谢您的帮助!

这篇关于C#中VB6 COM事件(QUOT;对象或类不支持事件集&QUOT的;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆