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();
HASSERT(pEventSource);
LPCONNECTIONPOINTCONTAINER pConnectionPointContainer = NULL;
if (SUCCEEDED(pEventSource->QueryInterface(IID_IConnectionPointContainer, (void**)&pConnectionPointContainer)))
{
HASSERT(pConnectionPointContainer);
LPCONNECTIONPOINT pConnectionPoint = NULL;
if (SUCCEEDED(pConnectionPointContainer->FindConnectionPoint(iid, &pConnectionPoint)))
{
HASSERT(pConnectionPoint);
pConnectionPoint->Advise(pYourEventSink, &sinkCookie);
pConnectionPoint->Release();
mySinkEntries.Append(new EventSinkEntry(iid, sinkCookie));
}
pConnectionPointContainer->Release();
}
return sinkCookie;
}
=====================================
=====================================
The C# ActiveX follows the standard method used in the Codeplex sample "CSActiveX"
http://1code.codeplex.com/SourceControl/changeset/view/45838#394692