tags:

views:

45

answers:

1

I'm querying an MFC implemented COM object that is implemented as follows:

class CA :
   public MfcComLib::IA
{
   ...
};

class CB :
   public MfcComLib::IB
{
   ...
};

class ATL_NO_VTABLE CExposedCoClass : 
   public CComObjectRootEx<CComSingleThreadModel>,
   public CA,
   public CB

{
public:

BEGIN_COM_MAP(CExposedCoClass )
   COM_INTERFACE_ENTRY(MfcComLib::IA)
   COM_INTERFACE_ENTRY(MfcComLib::IB)
END_COM_MAP()

On the C# side I'm receiving an IUnknown ptr which comes through as an object. I've imported the TypeLib and have gotten the interface MfcComLibLib.IA but when I cast I get a failure because of the interface not being implemented.

Is there a way to query the IUnknown pointer to discover what interfaces are actually implemented on the object?

A: 

Same way as you do with managed interfaces. You use the C# is or as operators. The CLR will under the hood map that to QueryInterface calls.

Mattias S
The point is that I don't know what interfaces the object has, so is or as won't work because they require me to have an interface to assign to the cast. The COM wrapper is not behaving correctly and I'm trying to explore the data to find out what is actually there.
Steve Mitcham
A COM object doesn't have to expose which interfaces it implements. But if it implements IDispatch, you can try calling IDispatch::GetITypeInfo and get implemented interfaces that way.
Mattias S
Ok, I'm going to close this out by accepting your comment along with the answer to say that in general what I'm asking for can't be done. In the actual case, the issue was related to a threading issue and I resolved it another way.
Steve Mitcham