#include <shlobj.h>
HRESULT GetLinkFilePath(HWND hWnd, LPWSTR lpwsLinkName, LPWSTR lpwsLinkPath)
{
CoInitialize(NULL);
IShellLink *pIShellLink = NULL;
HRESULT hResult = CoCreateInstance((REFIID)CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
(REFIID)IID_IShellLink,(LPVOID *)&pIShellLink);
if (SUCCEEDED(hResult))
{
IPersistFile *pIPersistFile = NULL;
hResult = pIShellLink->QueryInterface((REFIID)IID_IPersistFile,(LPVOID *)&pIPersistFile);
if (SUCCEEDED(hResult))
{
hResult = pIPersistFile->Load(lpwsLinkName, STGM_READ);
if (SUCCEEDED(hResult))
{
hResult = pIShellLink->Resolve(hWnd,SLR_ANY_MATCH | SLR_NO_UI);
if (SUCCEEDED(hResult))
{
WIN32_FIND_DATA wfd;
hResult = pIShellLink->GetPath(lpwsLinkPath, MAX_PATH, &wfd, SLGP_UNCPRIORITY);
}
}
pIPersistFile->Release();
}
pIShellLink->Release();
}
CoUninitialize();
return hResult;
}
bool IsFileLink(const std::wstring& strFileLink)
{
size_t len = strFileLink.length();
if (len > 4)
{
std::wstring wstrFilePox = strFileLink.substr(len - 4, len);
if (wstrFilePox == _T(".lnk") || wstrFilePox == _T(".LNK"))
{
return true;
}
}
return false;
}