Creating a Shortcut to a Nonfile Object

Creating a shortcut to a nonfile object, such as a printer, is similar to creating a shortcut to a file. The main difference is that, rather than setting the path to the file, you must set the identifier list to the printer. To set the identifier list, you must call the IShellLink::SetIDList member function, specifying the address of an identifier list.

Each object within the shell's namespace has an item identifier, a variable-length byte stream containing information that identifies the object within its folder. The shell often concatenates item identifiers into null-terminated lists consisting of any number of item identifiers.

In general, if you need to set a shortcut to an item that does not have a filename, such as a printer, you will already have a pointer to the object's IShellFolder interface. The IShellFolder interface is used to create namespace extensions.

Once you have the class identifier for the IShellFolder interface, you can call the CoCreateInstance function to get the address of the interface. Then you can call the interface to enumerate the objects in the folder and retrieve the address of the item identifier for the object that you are searching for. Finally, you can use the address in a call to the IShellLink::SetIDList member function to create a shortcut to the object.