Programming

Some programming notes and source code.

  • Templates for deriving C++ COM classes from IDropSource and IDropTarget are generally available on the web. Here's how to obtain a COM object using IShellFolder::GetUIObjectOf() without much PIDL-ing around, the only drawback is being restricted to file and folder objects.

  • UIObjectFromPath() — Obtains an interface pointer to a COM shell object given a path. Relatively simple function illustrating the basic moves. Suitable for a single folder. Useful for getting a basic drop target. Used as follows:
    #include <shlobj.h>
    
    LPDROPTARGET droptarget;
    bool ok = UIObjectFromPath (targetpath, IID_IDropTarget, (void**)&droptarget);
    ...
    droptarget->Release();
    
  • UIObjectFromPaths() — Obtains an interface pointer to a COM shell object given a vector of paths. Suitable for single or multiple files and folders. Useful for getting a drop source, drop target or context menu. Example usage:
    #include <vector>
    #include <string>
    typedef std::basic_string<wchar_t> wstring;
    
    LPDATAOBJECT dataobject;
    if (UIObjectFromPaths (paths, IID_IDataObject, (void**)&dataobject))
    {
            ...
            dataobject->Release();
    }
    
  • For invaluable background on shell programming, see here.