I have created a .NET component in C# that has 2 interfaces. One is an
incoming interface with methods being exposed to COM-aware clients. The
other is an outgoing event interface that the unmanaged C++ sink
implements. Here is the C# code:
using System;
using System.Runtime. InteropServices ;
using System.Runtime. CompilerService s;
using System.Reflecti on;
using System.Diagnost ics;
// Outgoing events
[InterfaceType(C omInterfaceType .InterfaceIsIDi spatch)]
public interface IEvents
{
void OnMyEvent(int MyCode);
}
// Incoming methods
public interface INotify
{
int Code { get; set; }
}
public delegate void MyDelegate(int nCode);
// Notify class
[ComSourceInterf aces("IEvents")]
[ClassInterface( ClassInterfaceT ype.None)]
public class Notify : INotify
{
private int m_Code = 5;
public event MyDelegate OnMyEvent;
public Notify()
{
}
public int Code
{
get { return m_Code; }
set
{
m_Code = value;
if (value >= 10)
{
try
{
if (null != OnMyEvent)
{
OnMyEvent(m_Cod e);
}
}
catch (Exception ex)
{
Trace.WriteLine (ex.Message);
}
}
}
}
}
In my unmanaged C++ client, I can access the INotify interface just
fine. But I want to access the event interface too. How do I do that?
Currently, I define the C++ pointer as:
ClassLibrary1:: INotifyPtr pNotify;
And then my C++ class constructor's initializer has:
pNotify(__uuido f(ClassLibrary1 ::Notify))
Any suggestions would be appreciated.
Thanks!