Tracing calls to QueryInterface on a managed object
To date, one difficulty with implementing COM interfaces in managed code is that until now there has been know way to debug into QueryInterface. With CLR v4, its now possible to modify your object to trace calls to QueryInterface using the new ICusomQueryInterface interface (see MSDN).
Example:
[ComVisible(true)]
sealed class MyObject : IMyInterface, ICustomQueryInterface
{
CustomQueryInterfaceResult ICustomQueryInterface.GetInterface(ref Guid iid, out IntPtr ppv)
{
Debugger.Log(1, "MyObject", "MyObject: QI'ed for " + iid.ToString() + "\n");
ppv = IntPtr.Zero;
return CustomQueryInterfaceResult.NotHandled;
}
};