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
{
}
public delegate void OnReceiveDataEventHandler(string args);
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

Luca PoaliniPosted Jan 15, 2015, 3:19 AM
VulpesPosted Jan 13, 2015, 11:59 AM
Luca PoaliniPosted Jan 13, 2015, 3:19 AM
VulpesPosted Jan 12, 2015, 4:33 PM
ER755COM_Events_SinkHelper sink = new ER755COM_Events_SinkHelper();
What is the actual error?
I'd like to try and get this approach to work if we can because it's the only thing I've seen which actually makes sense in the context of events and late binding.
Luca PoaliniPosted Jan 12, 2015, 9:36 AM
Hi,
now the problem is on this row of code:
ER755COM_Events_SinkHelper sink = new ER755COM_Events_SinkHelper();
Meanwhile I created a new project with same characteristics and in this one I can see a right value on Console.WriteLine(comObject.GetType().ToString()); than now is Smurf.Pants.
Now the question is: how do bind the com event?
The code is in the attached files
VulpesPosted Jan 9, 2015, 3:05 PM
After a certain amount of googling I found this CP article which shows how to receive events from late bound COM servers:
http://www.codeproject.com/Articles/10262/Receiving-Events-from-late-bound-COM-servers
I've tried to adapt this code to deal with your event below.
As this is quite an old article some of the interfaces (those beginning with UCOM) are now obsolete, so I've replaced them with the recommended alternatives:
Luca PoaliniPosted Jan 9, 2015, 11:16 AM
VulpesPosted Jan 9, 2015, 11:12 AM
To get at the event, I think you'll therefore need to go through COM's IConnectionPointContainer interface which isn't a particularly straightforward matter.
I'll look into it and get back to you later.
Luca PoaliniPosted Jan 9, 2015, 8:40 AM
VulpesPosted Jan 9, 2015, 8:37 AM
If immediately after executing this line:
comObject = System.Activator.CreateInstance(objType);
you execute this one:
MessageBox.Show(comObject.GetType().ToString());
what do you see?
Luca PoaliniPosted Jan 9, 2015, 7:58 AM
Here you are my registry key:
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\ER755.ER755\CLSID]
@="{94E7D0FD-2627-4D37-90A5-D8F7A01B4D41}"
VulpesPosted Jan 9, 2015, 7:47 AM
"ER755.ER755"
so I was wondering whether you're sure that this is correct - in other words is this the ProgID shown in the registry under HKEY_LOCAL_MACHINE\SOFTWARE\Classes\ ?
Presumably, it is producing an object reference otherwise you'd have received a null reference exception earlier in the code.
I don't think it would help here for me to have the whole project as this is a specific problem related to a COM component installed on your machine.
Luca PoaliniPosted Jan 9, 2015, 7:32 AM
Sorry what does you means with ProgID?
Would you like to have the entire project?
VulpesPosted Jan 9, 2015, 6:21 AM
Luca PoaliniPosted Jan 9, 2015, 3:47 AM
VulpesPosted Jan 8, 2015, 12:11 PM
Luca PoaliniPosted Jan 8, 2015, 11:49 AM
VulpesPosted Jan 8, 2015, 11:32 AM