Click here to Skip to main content
12,557,951 members (50,288 online)
Click here to Skip to main content
Add your own
alternative version


8 bookmarked

A wrapper class for creating a shortcut (.lnk) and a bookmark (.url) and attaching an online icon to it

, 6 Jul 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
A ready-to-use wrapper class for creating a shortcut (.lnk file) and a bookmark (.url file) and finally attaching an online icon resource to it.


If your application needs to create an internet favorite (.url) or desktop shortcut (.lnk), there are a lot of online references. But if:

  1. an icon must be attached to the file and
  2. the icon is an online resource that needs to be downloaded first

this article could be a help.

The 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].

  1. Adding a Favorite (".url" file) (maybe under a button):
  2. CShortcutNBookmark csnb;
    csnb.AddFavoriteNAttachIcon("GrooveDive"/*title or file name*/, 
             ""/*target url*/, 
             ""/*icon url*/);
    // csnb.AddFavorite("GrooveDive", "");
    // is also available. this function will use the icon of your application
  3. Creating a Desktop Shortcut (".lnk" file) (maybe under a button):
  4. CShortcutNBookmark csnb;
    csnb.CreateDesktopShortcutNAttachIcon("GrooveDive"/*title or file name*/,
            ""/*target url*/, 
            ""/*icon url*/);
    // csnb.CreateDesktopShortcut("GrooveDive", "");
    // is also available. this function will use the icon of your application


In some cases, the compilation fails with the following link error message:

shell32.lib(shguid.obj) : 
      fatal error LNK1103: debugging information corrupt; recompile module

One reason could be the new SDK library.

  1. Go to [Tools]>[Option]>[Directories]>[Library files]
  2. 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.


  • 2008.06.28: Created.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Team Leader An Online Market
Korea (Republic of) Korea (Republic of)
Software engineer having worked 8 years.
The main skill would be C++, ATL, COM
But for the past three years I have been digging on Web service related skill - .Net MS-SQL etc in current company.
My other interest is business, playing traditional music, dealing with people and evolutionary biology.

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161026.1 | Last Updated 6 Jul 2008
Article Copyright 2008 by jangtimjang
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid