M
MLM450
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.CompilerServices;
using System.Reflection;
using System.Diagnostics;
// Outgoing events
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IEvents
{
void OnMyEvent(int MyCode);
}
// Incoming methods
public interface INotify
{
int Code { get; set; }
}
public delegate void MyDelegate(int nCode);
// Notify class
[ComSourceInterfaces("IEvents")]
[ClassInterface(ClassInterfaceType.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_Code);
}
}
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(__uuidof(ClassLibrary1::Notify))
Any suggestions would be appreciated.
Thanks!
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.CompilerServices;
using System.Reflection;
using System.Diagnostics;
// Outgoing events
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IEvents
{
void OnMyEvent(int MyCode);
}
// Incoming methods
public interface INotify
{
int Code { get; set; }
}
public delegate void MyDelegate(int nCode);
// Notify class
[ComSourceInterfaces("IEvents")]
[ClassInterface(ClassInterfaceType.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_Code);
}
}
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(__uuidof(ClassLibrary1::Notify))
Any suggestions would be appreciated.
Thanks!