CsActiveX: events cause error in C++ client but work in VB6

Jul 27, 2010 at 12:31 PM
Edited Jul 27, 2010 at 12:35 PM

I am writing an ActiveX in C#, to be used in a legacy C++ application.
It all works ok, apart from event handling.

The problem is that when the event is raised in C# I get the following error:


An unhandled exception of type 'System.InvalidCastException' occurred in AwDotNetPinchOcx.dll
 Additional information: Unable to cast COM object of type 'System.__ComObject' to interface type 'AwDotNetPinchOcx.__AwPinchGrid'. 
 This operation failed because the QueryInterface call on the COM component for the interface with IID '{76F027EC-3D40-449E-B7E6-EFDF7CC63963}' 
 failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

However, the C# ActiveX works fine in a test VB6 app.
And, a native VB6 ActiveX works fine in the C++ application!

My work-around at the moment is therefore a VB6 ActiveX wrapper that contains the C# ActiveX,
and passes data and events across.

I want to get rid of this wrapper though.
Can anyone help?

The C++ app uses the ConnectionPoint event sink method:

DWORD EventSinkHolder::AddEventSink(REFIID iid, IUnknown* pYourEventSink)
   DWORD sinkCookie = 0;
   IUnknown* pEventSource = EventSourceInterface();
   if (SUCCEEDED(pEventSource->QueryInterface(IID_IConnectionPointContainer, (void**)&pConnectionPointContainer)))
      LPCONNECTIONPOINT pConnectionPoint = NULL;
      if (SUCCEEDED(pConnectionPointContainer->FindConnectionPoint(iid, &pConnectionPoint)))
         // connect passed event sink interface to event source
         pConnectionPoint->Advise(pYourEventSink, &sinkCookie);
         // record connection for benefit of RemoveAllEventSinks
         mySinkEntries.Append(new EventSinkEntry(iid, sinkCookie));
   return sinkCookie;


The C# ActiveX follows the standard method used in the Codeplex sample "CSActiveX"