Не в состоянии обрабатывать события com в C#

Как обрабатывать ком события в C#?

Я создал одну библиотеку классов в 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 ничего не происходит. Любая помощь будет оценена.

0 ответов

Другие вопросы по тегам