StickysoftDESIGNS
Skip Navigation Links : Articles : Shell Programming : How to create and resolve a shortcut

How to create and resolve a shortcut

Shortcut is a file with an extension .lnk. Each of these files contain a special COM object that points to another file. Usually, when you try to open a .lnk file, the system opens a file which this shortcut points to.

Let's do the following experiment. Create a text file (file with an extension .txt) somewhere. Then create a shortcut pointing to this file (send me a private e-mail if you do not know how to create a shortcut manually). Then try to open the shortcut with Microsoft Word, using File->Open command and select just created shortcut. MS Word will do it correctly: it will open the text file that is pointed by this shortcut.

Point is: in Windows a program should have a built-in support for shortcuts in order to handle them correctly.

How to use it

LPCTSTR lpszFileName = _T("C:\\Work\\Window.exe");
LPCTSTR lpszShortcutDesc = _T("Anything can go here");
LPCTSTR lpszShortcutPath = 
_T("C:\\Documents and Settings\\Administrator\\Desktop\\Sample Shortcut.lnk");

CreateShortcut(lpszFileName, lpszShortcutDesc, lpszShortcutPath);

LPCTSTR lpszShortcutPath = 
_T("C:\\Documents and Settings\\Administrator\\Desktop\\Sample Shortcut.lnk");
TCHAR szFilePath[MAX_PATH];

ResolveShortcut(lpszShortcutPath, szFilePath);
    

The download file contains 2 functions showing how to create and resolve the shortcut.

Download the source code