We have a 32-bit COM component written with ATL in C++. When there's a need to use it from 64-bit .NET, we create a COM+ application and everything works allright.
Recently we noticed strange behaviour on Win2k8. The COM object in our component fires an event and we process it in .NET code. The event has a parameter also passed from the unmanaged code.
Here's partial definition for clarification (IDL notation):
interface IOurCollectionInterface : IDispatch
{
[propget, restricted, id(DISPID_NEWENUM)]]
HRESULT _NewEnum( [out, retval] IUnknown** result );
}
interface IOurObjectInterface : IDispatch
{
[propget]
HRESULT Collection( [out, retval] IOurCollectionInterface** result );
}
The event handler is passed a IOurObjectInterface instance. Inside we try to run a foreach() loop.
void onEvent( IOurObjectInterface ourObject )
{
foreach( object element in ourObject.Collection ) {
//do stuff
}
}
The code crashes on the line with foreach with the following message: QI for IEnumVARIANT failed on the unmanaged server
IEnumVARIANT is for sure implemented by the object which is returned by the IOurCollectionInterface::get__NewEnum() implementation. The code above works allright on WinXP and Win2k3 but not on Win2k8.
What's the reason for such behaviour?