Game Development Reference
By default, a COM interface is exposed as dual, but the interfaces needed for shell
extensions do not require late binding, so their types are all set to InterfaceIsIUnknown .
The [GuidAttribute] is used to assign a GUID to the interface. This GUID must be
the correct one to use for the COM interface you are importing, as defined in the
Win32 registry. This is so COM clients can invoke methods of the interface, regard-
less of how the .NET implementation works.
.NET interfaces and classes do not require an explicit GUID to be set as they are automatically generated.
The [PreserveSig] attribute is used to specify that there is a direct translation
between the managed signature and the unmanaged entry point. More specifically,
most COM interfaces return method success as an HRESULT , and use a memory
buffer pointer to pass this value back to callers. The default behavior of the CLR is
to automatically transform the managed signature, but the [PreserveSig] attribute
is used to ensure that this transformation does happen.
The IShellExtInit interface is called by the shell, and is used to initialize property
sheets, drag-and-drop handlers, and context menu extensions. The parameters for
this method vary depending on the type of extension, but we will focus on content
menu extensions. The pidlFolder is null when dealing with file objects, or it spec-
ifies the folder for which the context menu is being requested. The objectPointer
identifies the selected files, and the keyProgID identifies the file class of the object
public interface IShellExtInit
int Initialize(IntPtr pidlFolder, IntPtr objectPointer, uint keyProgID);
IShellExtInit is only used by property sheet, context menu, and drag-and-drop handler extensions.
Be sure to use the correct interface when building other types of shell extensions.
The IContentMenu interface is used by the shell when creating or merging a context
menu associated with a shell object. This interface can be used to dynamically add
items to a shell object's context menu.