Shell32 Shortcut Management Functions
CreateShortcut()
Creates a new shortcut file (.lnk) or a URL shortcut (.url).
This function allows developers to programmatically create shortcut files, essential for user navigation and application launching.
LPCTSTR pszShortcutFile
- The path to the shortcut file to be created.
LPCTSTR pszTargetFile
- The path to the file or application that the shortcut points to.
LPCTSTR pszArguments
- Optional command-line arguments for the target application.
LPCTSTR pszWorkingDirectory
- Optional working directory for the target application.
int iShowCmd
- Specifies how the shortcut's window should be displayed when it is invoked (e.g.,
SW_SHOWNORMAL
,SW_MAXIMIZE
). LPCTSTR pszIconLocation
- Optional path to the icon file and index for the shortcut.
Return Value
Returns TRUE
on success or FALSE
on failure.
Remarks
Uses the COM interfaces IShellLink
and IPersistFile
internally to create the shortcut.
BOOL CreateShortcut(
LPCTSTR pszShortcutFile,
LPCTSTR pszTargetFile,
LPCTSTR pszArguments,
LPCTSTR pszWorkingDirectory,
int iShowCmd,
LPCTSTR pszIconLocation
);
ResolveShortcut()
Resolves a shortcut file to its original target.
This function is useful for finding the actual location of a file or application that a shortcut points to, especially when the shortcut might have been moved or renamed.
HWND hwnd
- Handle to the owner window. Used for displaying dialog boxes if the target cannot be found.
LPCTSTR pszShortcutFile
- The path to the shortcut file to resolve.
LPTSTR pszTargetFile
- A buffer to receive the resolved target file path.
int cchMax
- The size of the
pszTargetFile
buffer. DWORD fFlags
- Flags that control how the shortcut is resolved. See
SLR_
constants.
Return Value
Returns TRUE
if the shortcut was resolved successfully, FALSE
otherwise.
Remarks
This function can prompt the user for assistance if the shortcut's target cannot be found automatically.
BOOL ResolveShortcut(
HWND hwnd,
LPCTSTR pszShortcutFile,
LPTSTR pszTargetFile,
int cchMax,
DWORD fFlags
);
GetShortcutTarget()
Retrieves the target path of a shortcut.
A simpler alternative to ResolveShortcut
when no user interaction is desired or needed.
LPCTSTR pszShortcutFile
- The path to the shortcut file.
LPTSTR pszTargetPath
- A buffer to receive the target path.
int cchMax
- The size of the
pszTargetPath
buffer.
Return Value
Returns TRUE
if the target path was retrieved successfully, FALSE
otherwise.
Remarks
Does not prompt the user if the target is invalid.
BOOL GetShortcutTarget(
LPCTSTR pszShortcutFile,
LPTSTR pszTargetPath,
int cchMax
);
DeleteShortcut()
Deletes a shortcut file.
Provides a straightforward way to remove shortcut files from the file system.
LPCTSTR pszShortcutFile
- The path to the shortcut file to delete.
Return Value
Returns TRUE
on success, FALSE
on failure.
Remarks
This function simply deletes the shortcut file. It does not affect the target of the shortcut.
BOOL DeleteShortcut(
LPCTSTR pszShortcutFile
);