#include <comdef.h>
#include <shlobj.h>
#ifdef _UNICODE
#define IShellLink IShellLinkW
#define IShellLinkPtr IShellLinkWPtr
#else
#define IShellLink IShellLinkA
#define IShellLinkPtr IShellLinkAPtr
#endif
BOOL _SHGetShortcutTarget(LPTSTR szShortcut, LPTSTR szTarget, int cbMax)
{
USES_CONVERSION;
if (szShortcut == NULL || szTarget == NULL)
{
return FALSE;
}
HRESULT hr = S_OK;
try
{
IShellLinkPtr spShellLink;
hr = spShellLink.CreateInstance(CLSID_ShellLink);
if (FAILED(hr))
{
return FALSE;
}
IPersistFilePtr spPersistFile = spShellLink;
if (spPersistFile == NULL)
{
return FALSE;
}
hr = spPersistFile->Load(T2OLE(szShortcut), 0x00000020); // Read & Deny Write
if (FAILED(hr))
{
return FALSE;
}
WIN32_FIND_DATA wfd;
hr = spShellLink->GetPath(szTarget, cbMax, &wfd, 0);
if (FAILED(hr))
{
return FALSE;
}
}
catch (...)
{
return FALSE;
}
return TRUE;
}