// Get a pointer to the IShellLink interface. hres = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, &psl); if (SUCCEEDED(hres)) { IPersistFile* ppf;
// Get a pointer to the IPersistFile interface. hres = psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile, &ppf); if (SUCCEEDED(hres)) { WORD wsz[MAX_PATH];
// Ensure that the string is Unicode. MultiByteToWideChar(CP_ACP, 0, lpszLinkFile, -1, wsz, MAX_PATH);
// Load the shortcut. hres = ppf->lpVtbl->Load(ppf, wsz, STGM_READ); if (SUCCEEDED(hres)) {
// Resolve the link. hres = psl->lpVtbl->Resolve(psl, hwnd, SLR_ANY_MATCH); if (SUCCEEDED(hres)) {
// Get the path to the link target. hres = psl->lpVtbl->GetPath(psl, szGotPath, MAX_PATH, (WIN32_FIND_DATA *)&wfd, SLGP_SHORTPATH ); if (!SUCCEEDED(hres) HandleErr(hres); // application-defined function
// Get the description of the target. hres = psl->lpVtbl->GetDescription(psl, szDescription, MAX_PATH); if (!SUCCEEDED(hres)) HandleErr(hres); lstrcpy(lpszPath, szGotPath); } } // Release the pointer to the IPersistFile interface. ppf->lpVtbl->Release(ppf); } // Release the pointer to the IShellLink interface. psl->lpVtbl->Release(psl); } return hres; }
HRESULT ResolveIt(HWND hwnd, LPCSTR lpszLinkFile, LPSTR lpszPath)
{
HRESULT hres;
IShellLink* psl;
char szGotPath[MAX_PATH];
char szDescription[MAX_PATH];
WIN32_FIND_DATA wfd;
*lpszPath = 0; // assume failure
// Get a pointer to the IShellLink interface.
hres = CoCreateInstance(&CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER, &IID_IShellLink, &psl);
if (SUCCEEDED(hres)) {
IPersistFile* ppf;
// Get a pointer to the IPersistFile interface.
hres = psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile,
&ppf);
if (SUCCEEDED(hres)) {
WORD wsz[MAX_PATH];
// Ensure that the string is Unicode.
MultiByteToWideChar(CP_ACP, 0, lpszLinkFile, -1, wsz,
MAX_PATH);
// Load the shortcut.
hres = ppf->lpVtbl->Load(ppf, wsz, STGM_READ);
if (SUCCEEDED(hres)) {
// Resolve the link.
hres = psl->lpVtbl->Resolve(psl, hwnd, SLR_ANY_MATCH);
if (SUCCEEDED(hres)) {
// Get the path to the link target.
hres = psl->lpVtbl->GetPath(psl, szGotPath,
MAX_PATH, (WIN32_FIND_DATA *)&wfd,
SLGP_SHORTPATH );
if (!SUCCEEDED(hres)
HandleErr(hres); // application-defined function
// Get the description of the target.
hres = psl->lpVtbl->GetDescription(psl,
szDescription, MAX_PATH);
if (!SUCCEEDED(hres))
HandleErr(hres);
lstrcpy(lpszPath, szGotPath);
}
}
// Release the pointer to the IPersistFile interface.
ppf->lpVtbl->Release(ppf);
}
// Release the pointer to the IShellLink interface.
psl->lpVtbl->Release(psl);
}
return hres;
}