I three together the follow. The ComImportAttribute changes the metadata such that an instance is marked as imported and created from the attributed GUID. By casting, I am effectively QI'ing for the two interfaces. In both cases, "False" is printed to the console, showing that the object does implement both interfaces. Sorry I don't have time to throw together a better sample (and keep in mind that when using interfaces not every method has to be defined (so long as they're in the correct VTBL order):
using System;
using System.Runtime.InteropServices;
[
GuidAttribute("4657278A-411B-11d2-839A-00C04FD918D0"),
ClassInterface(ClassInterfaceType.None),
ComImport
]
public class DragDropHelper : IDropTargetHelper, IDragSourceHelper
{
}
[
GuidAttribute("4657278B-411B-11d2-839A-00C04FD918D0"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
ComImport
]
public interface IDropTargetHelper
{
}
[
GuidAttribute("DE5BF786-477A-11d2-839D-00C04FD918D0"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
ComImport
]
public interface IDragSourceHelper
{
}
class Test
{
static void Main()
{
DragDropHelper helper = new DragDropHelper();
IDropTargetHelper dropHelper = (IDropTargetHelper)helper;
IDragSourceHelper dragHelper = (IDragSourceHelper)helper;
Console.WriteLine(dropHelper == null);
Console.WriteLine(dragHelper == null);
}
}
Microsoft MVP, Visual C# My Articles