Hi all,
I'm developping a C# COM object with event that I must handle in my application.
If I add the COM object in the application's References all work fine but if I use the COM object with late binding I don't receive the event.
The code relative to the interface is:
[Guid("CA2F7751-32F3-4E87-BC88-CC99F4186A09"),
InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface ER755COM_Events
{
[DispId(5)]
void OnReceiveDataEvent(string args);
}
[Guid("94E7D0FD-2627-4D37-90A5-D8F7A01B4D41"),
ClassInterface(ClassInterfaceType.AutoDispatch),
ComSourceInterfaces(typeof(ER755COM_Events))]
public class ER755 : ER755COM_Interface
….
public delegate void OnReceiveDataEventHandler(string args);
public event OnReceiveDataEventHandler OnReceiveDataEvent;
if (OnReceiveDataEvent != null)
Console.WriteLine("OnDataReceive calling OnReceiveDataEvent");
OnReceiveDataEvent(CardID);
And the code in the application is:
[ComImport, Guid("CA2F7751-32F3-4E87-BC88-CC99F4186A09")]
class ER755
System.Type objType;
dynamic comObject;
…..
objType = System.Type.GetTypeFromProgID("ER755.ER755");
comObject = System.Activator.CreateInstance(objType);
comObject.OnReceiveDataEvent += new OnReceiveDataEventHandler(OnMyReceiveDataEventHandler);
Any suggestions?
Thanks in advance