Windows Shell Programming Interfaces
The Windows Shell provides a rich set of COM interfaces that enable developers to extend, customize, and interact with the Windows desktop, File Explorer, and related components. Below is a curated list of the most commonly used interfaces, their purpose, and example usage.
Core Interfaces
| Interface | Namespace | Description |
|---|---|---|
IShellFolder |
shlobj.h |
Represents a Shell folder and provides methods to enumerate items, bind to subfolders, and retrieve attributes. |
IShellView |
shobjidl.h |
Manages the visual representation of a folder's contents within a window. |
IContextMenu |
shobjidl.h |
Enables custom context‑menu extensions for items in the Shell. |
IDataObject |
objidl.h |
Used for drag‑and‑drop and clipboard operations. |
IShellLink |
shobjidl.h |
Creates, modifies, and resolves shortcut (.lnk) files. |
IPersistFile |
objidl.h |
Persists an object to or from a file; commonly used with IShellLink. |
Advanced Interfaces
IShellItem– Represents a single item in the Shell namespace. Provides path, display name, and attribute information.IShellItemArray– A collection ofIShellItemobjects, used in batch operations.IFileOperation– Simplifies file copy/move/delete with progress UI and error handling.IBindCtx– Holds context information for moniker binding operations.IThumbnailProvider– Generates thumbnails for custom file types.ICustomDestinationList– Manages Jump List tasks and destinations for an application.
Quick Example: Creating a Shortcut
#include <windows.h>
#include <shobjidl.h>
#include <propkey.h>
int CreateShortcut(LPCWSTR targetPath, LPCWSTR shortcutPath, LPCWSTR description) {
IShellLinkW *pLink = nullptr;
HRESULT hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&pLink));
if (SUCCEEDED(hr)) {
pLink->SetPath(targetPath);
pLink->SetDescription(description);
IPersistFile *pPersist = nullptr;
hr = pLink->QueryInterface(IID_PPV_ARGS(&pPersist));
if (SUCCEEDED(hr)) {
hr = pPersist->Save(shortcutPath, TRUE);
pPersist->Release();
}
pLink->Release();
}
return SUCCEEDED(hr) ? 0 : -1;
}
This snippet demonstrates how to create a .lnk file using IShellLink and IPersistFile. Remember to call CoInitializeEx before invoking COM methods.