Microsoft Docs

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

InterfaceNamespaceDescription
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

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.

Resources