Creating a Shortcut to an Object Other Than a File

The sample code demonstrates how to programmatically create a shortcut to a file, but it does not cover the steps you must take to create a shortcut to an object that does not have a filename, such as Control Panel or a printer. The major difference is that rather than setting the path to the shortcut, you will instead be setting the identification list (ID list) to the object. You do this by calling IShellLink::SetIDList and providing a pointer to an ID list.

You might well be thinking, “What the heck is an ID list?” Within the shell name space, each object that Windows Explorer can browse (such as files, folders, servers, and workgroups) has an identifier that is unique among the objects in its parent folder. These identifiers, referred to as item IDs, are stored as SHITEMID structures (defined in the SHLOBJ.H file). Each parent folder also has its own item ID. Therefore, any object can be uniquely identified by a list of item IDs, corresponding to the way a file can be uniquely identified by its path. Such a list of items, called an ID list, is defined as the ITEMIDLIST structure in SHLOBJ.H. It is important to remember that each item ID in an ID list is meaningful only in the context of the parent folder. (You'll find more information about ID lists in Chapter 14.)

NOTE: If you plan to use the CreateIt function from the SHORTCUT sample in your MFC-based application, you might run into problems with the conversion from multibyte to wide characters. If you do, take a look at “Technical Note 49: MFC/OLE MBCS to Unicode Translation Layer (MFCANS32),” available in the MSDN Development Library under Technical Articles, Visual C++ 2.0 (32-bit) Articles, MFC 3.1 Technical Notes. The MFCANS32 DLL provides ANSI interfaces to 32-bit OLE, which is primarily Unicode. This technical note will show you what you need to do if you experience this problem. You can also find helpful information on this topic in the Microsoft Visual C++ documentation.