If your application needs to create an internet favorite (.url) or desktop shortcut (.lnk), there are a lot of online references. But if:
- an icon must be attached to the file and
- the icon is an online resource that needs to be downloaded first
this article could be a help.
CShortcutNBookmark class encapsulates every job needed: creating a .url or .lnk file, downloading the icon file, and assigning that to a shortcut file. Call the high level functions if you are in a haste. Otherwise look into the low level functions for your study or for more modifications.
Using the code
Just include the .h, and .cpp, then call a function. That's all.
Add "ShortcutNBookmark.h" and "ShortcutNBookmark.cpp" to your project. Add "wininet.lib" in [Project setting]>[Link].
- Adding a Favorite (".url" file) (maybe under a button):
- Creating a Desktop Shortcut (".lnk" file) (maybe under a button):
In some cases, the compilation fails with the following link error message:
fatal error LNK1103: debugging information corrupt; recompile module
One reason could be the new SDK library.
- Go to [Tools]>[Option]>[Directories]>[Library files]
- Place "C:\Program Files\Microsoft Visual Studio\VC98\LIB" (old library) higher than "C:\PROGRAM FILES\MICROSOFT PLATFORM SDK\LIB" (new library)
Note that in Vista, downloading fails due to enhanced security. But there are some folders of low security and the
CShortcutNBookmark class downloads files under that path.