Click here to Skip to main content
11,934,389 members (31,582 online)
Click here to Skip to main content
Add your own
alternative version


89 bookmarked

CShortcut (Shell links to special folders)

, 13 May 2004
Rate this:
Please Sign up or sign in to vote.
This class enables you to build shortcuts to any File/Folder (like the Startmenu, SendTo-contextmenu...)

Sample Image - CShortcut.gif


This class enables you to build Shell links (shortcuts) easily like you see everywhere in Windows (e.g.: on the Desktop, in the Context menu's "SendTo"-entry, in the Startmenu...). You are also able to give a description or command-line arguments to the link. It is really a snap to make shortcuts with this class. Have a look at the demo project to see how easy it is!

Some words on the Demo project

  • The Icon will change each time a shortcut is written and the programm is running. The Icons are leeched from the shell32.dll.
  • The name of the link that is written by this demo is always "Test Link" no matter in which folder the link is created.
  • When the Program starts, it detects if there is a shortcut. If there is one, the text
    beside the option button will be changed and the textcolor will also be changed to Red. If no, the text will be blue. The same occurs when a link is written or deleted.
  • If you create a link in the "SendTo" menu, you can test it like this:
    • create a shortcut in the SendTo context menu
    • open the explorer, right-click on a file and choose the SendTo menu entry
    • now another menu pop's up and you should choose "Test Link"
    • the CShortcut Demo starts and a Messagebox shows you the path and the filename of the file you "SendTo".

SendTo Messagebox Img

Using the code

1. add the files Shortcut.h and Shortcut.cpp to your project and Include the header

#include "Shortcut.h"

2. create a variable of class CShortcut. ie:

m_pShortcut // a pointer to CShortcut

3.1. Call the function SetCmdArguments in case you need command-line arguments

SetCmdArguments(CString sArg)

the CString is/are the argument(s) you need to call with your file

3.2 Call the function CreateShortCut to create a shortcut (the function name says it Wink | ;-)

CreateShortCut(CString LnkTarget,
               CString LnkName,
               UINT SpecialFolder,
               CString LnkDescription,
               CString IconLocation,
               UINT IconIndex)
  • LnkTarget the File/Folder the link belongs to
  • LnkName the name of the ShortCut
  • SpecialFolder where to put the shortcut to (see below or for more folders see
    MSDN --> SHGetSpecialFolderLocation)
  • LnkDescription an application can use it to store any text information and can
    retrieve it with "IShellLink::GetDescription"
  • IconLocation path to the file where the icon is located that should be used. Can be
    an empty string
  • IconIndex the index of the icon in the file

    Definitions for SpecialFolder's:




SendTo Menu/Folder


Desktop for current User


Desktop for all Users


Autostart for current User


Autostart for all Users


Start-menu for current User


Start-menu for all Users


Programs-menu for current User

and many more...

4. You want to delete a Shortcut? O.K. read on. Just use DeleteShortCut

DeleteShortCut(CString LnkName, UINT SpecialFolder)
  • LnkName the name of the Shortcut
  • SpecialFolder again a define for a special folder (see CreateShortCut)

5. You want to detect a shortcut? Then use isLinkAvailable

isLinkAvailable(CString LnkName, UINT SpecialFolder)
  • LnkName the name of the Shortcut
  • SpecialFolder again a define for a special folder (see CreateShortcut)

6. Now you can resolve and retrieve the description of a shortcut, use:

ResolveLink(CString LnkName,
            UINT SpecialFolder,
            HWND hwnd,
            CString &LnkPath,
            CString &LnkDescription)
  • LnkName the name of the ShortCut
  • SpecialFolder the location of the shortcut
  • hwnd The handle of the parent window for any message boxes that may be displayed by the shell.
  • &LnkPath reference to a string that receives the path to the object
  • &LnkDescription reference to a string that receives the description of the link

7. There are also two private helper routines that are used internal:

  • GetSpecialFolder This routine is a helper that finds the path to the special folder
  • ShortToLongPathName This routine is a helper that builds a long path from 8+3 one. I know that there exists an function called GetLongPathName but I'm using half of my time an "old" NT4 system and there is this function not available!

Now you are ready to build links to everything on your computer. >B-}


I would like to thank the programmer who made this class possible due to his or her good
IShellLink implementation! I really don't remember where I found it. Sorry! And Michael Dunn for his great article Introduction to COM - What It Is and How to Use It

The reason for this:

I was in the need to give the user of a little application of mine an option to send files
through the right-click "SendTo" menu to my Program. After searching for a few hours I've had enough material and information to bring up this class (my first contact with COM Technology).

You can put executables not only in the "SendTo" menu but also folders which can be useful to search and collect some files and Zip them up later (for example). You see there are many useful things todo with links. Another possibility is to link something to the control panel. Or you can...


12.05.2004 - routine to resolve ShellLinks added


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Thomas Latuske
Web Developer
Germany Germany
My name is Thomas, I'm born on January the 11th in
1970, right now I'm working in the Quality department
of a big Pipe mill as a Technician.
My hobbies are my girl friend, my car, RC-Planes and
Computers. I begun with VC++ some time ago and now
Programming is like a drug to me (I'm still a
beginner). I want to learn it all in a blink of an
eye Wink | ;-) but i know that this is not possible. It's
real fun for me and I do small Programms for my own
O.K. enough written..... I need my Time to debug
everything that crosses my way! Wink | ;-)

You may also be interested in...

Comments and Discussions

Questionwhy can't Resolve the IE shortcut? Pin
Member 423260024-Nov-08 1:45
memberMember 423260024-Nov-08 1:45 
GeneralAccessibility Options Shortcut Pin
Dabara4-Aug-08 22:15
memberDabara4-Aug-08 22:15 
QuestionResolveLink?????? Pin
locoone28-Jun-07 18:49
memberlocoone28-Jun-07 18:49 
GeneralGood submission but it is important to point out... Pin
sricard23-Oct-06 7:58
membersricard23-Oct-06 7:58 
In my travels through the internet searching for an answer of how to create a sendto shortcut, this is pretty much the standard of how people suggest to do it. What they do not point out is that if you are trying to submit a large number of files from windows explorer to your application, this method simply is not good enough. I feel that it should be pointed out that the files are posted to the application as an argument, and thus are limited to 256 characters.

Just some information to think about when implementing the sendto shortcut. I am currently in search of a more robust solution to creating a sendto shortcut and desktop shortcut that allows an unlimited amount of files.

The following article provides some good information, but I am a VB.NET programmer, so this will consume a lot of my time doing the translation. If anyone has a solution, please let me know!

QuestionHow to create the office style shortcuts! Pin
Funfound21-Aug-06 1:20
memberFunfound21-Aug-06 1:20 
GeneralC++ Char help Pin
EIFNOBODY19-Jul-05 8:19
memberEIFNOBODY19-Jul-05 8:19 
GeneralRe: C++ Char help Pin
kcselvaraj1-Apr-06 0:55
memberkcselvaraj1-Apr-06 0:55 
GeneralC++ Char help Pin
Anonymous19-Jul-05 8:13
sussAnonymous19-Jul-05 8:13 
GeneralRe: C++ Char help Pin
Anonymous19-Jul-05 8:16
sussAnonymous19-Jul-05 8:16 
GeneralCreate subfolder Pin
Andromeda Shun19-Apr-05 5:31
memberAndromeda Shun19-Apr-05 5:31 
GeneralRe: Create subfolder Pin
Andromeda Shun19-Apr-05 5:43
memberAndromeda Shun19-Apr-05 5:43 
QuestionCreate shortcut in subfolder? Pin
Andromeda Shun18-Apr-05 5:55
memberAndromeda Shun18-Apr-05 5:55 
AnswerRe: Create shortcut in subfolder? Pin
Andromeda Shun19-Apr-05 0:53
memberAndromeda Shun19-Apr-05 0:53 
GeneralCompiler error Pin
Andromeda Shun18-Apr-05 4:10
memberAndromeda Shun18-Apr-05 4:10 
GeneralRe: Compiler error Pin
rootdial5-Jan-06 23:42
memberrootdial5-Jan-06 23:42 
GeneralStart In dir Pin
Alex Carter6-Sep-04 10:22
memberAlex Carter6-Sep-04 10:22 
GeneralRe: Start In dir Pin
Sinople23-May-05 4:47
memberSinople23-May-05 4:47 
GeneralDelete Shortcut with any keyword Pin
Ryan Bohm4-Sep-04 9:10
memberRyan Bohm4-Sep-04 9:10 
QuestionNice, and how to create a new folder? Pin
bendo11-Jul-04 2:19
sussbendo11-Jul-04 2:19 
AnswerRe: Nice, and how to create a new folder? Pin
Avinesh Bangar20-Jul-04 12:00
sussAvinesh Bangar20-Jul-04 12:00 
Generalthanks, regular codes Pin
cxy25-May-04 7:25
membercxy25-May-04 7:25 
GeneralGood solution! Pin
spawn__19-May-04 9:43
memberspawn__19-May-04 9:43 
GeneralRe: Good solution! Pin
Thomas Latuske19-May-04 9:43
memberThomas Latuske19-May-04 9:43 
GeneralVery good !! Pin
WREY14-May-04 13:22
memberWREY14-May-04 13:22 
GeneralRe: Very good !! Pin
Thomas Latuske14-May-04 20:42
memberThomas Latuske14-May-04 20:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.151126.1 | Last Updated 14 May 2004
Article Copyright 2004 by Thomas Latuske
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid