C# 无法在c中处理com事件#

C# 无法在c中处理com事件#,c#,multithreading,com,apartments,C#,Multithreading,Com,Apartments,如何在c#中处理com事件 我在c#中创建了一个类库,并使用无注册表com技术作为com组件公开 [ComVisible(true)] [Guid("SOME GUID")] [InterfaceType(InterfaceType.InterfaceIsIDispatch)] public interface ICameraEvents //Event Source Interface { void OnImageCaptured(object sender, EventArgs e)

如何在c#中处理com事件

我在c#中创建了一个类库,并使用无注册表com技术作为com组件公开

[ComVisible(true)]
[Guid("SOME GUID")]
[InterfaceType(InterfaceType.InterfaceIsIDispatch)]
public interface ICameraEvents //Event Source Interface
{
    void OnImageCaptured(object sender, EventArgs e);
}

[Guid("SOME GUID")]
[ComVisible(true)]
public interface IService
{
    void RaiseEvent();
}

[Guid("SOME GUID")]
[ComVisible(true)]
[ComSourceInterface(typeof(ICameraEvents))]
[ClassInterface(ClassInterfaceType.None)]
public class Service : IService
{
    event EventHandler OnImageCaptured;

    public void RaiseEvent()
    { 
        if(OnImageCaptured != null)  
            OnImageCaptured(null,null);
    }
}
这是我的客户端windows应用程序表单

public class MyForm : Form
{
    void Form_Load()
    {
        Type type = Type.GetTypeFromProgID("someid")//Create com object
        IService instance = (IService)Activator.CreateInstance(type);
        instance.RaiseEvent();
    }

    void OnImageCaptured(object sender, EventArgs e)
    {
       MessageBox.Show("Event Fired");
    }
}


//Re declare the interface in client application
[Guid("SOME GUID")]
[ComVisible(true)]
public interface IService
{
    void RaiseEvent();
}
当我呼叫service.RaiseEvent时,什么也没发生。
如果您有任何帮助,我们将不胜感激。

在修复了代码段中大量的拼写错误后,效果很好。很难猜出哪一个是关键的。可能忘了把ICameraEvents公之于众。谢谢你的回复。我忘了公开接口。即使在公开之后,它也不起作用。如果您没有收到原始问题,请不要发表评论。我已经解释了我面临的问题。我只想在客户端应用程序中处理com事件。在修复了代码段中数量多得可笑的打字错误后,效果很好。很难猜出哪一个是关键的。可能忘了把ICameraEvents公之于众。谢谢你的回复。我忘了公开接口。即使在公开之后,它也不起作用。如果您没有收到原始问题,请不要发表评论。我已经解释了我面临的问题。我只想在客户端应用程序中处理com事件。