Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. Software *ResolveIt(LPTSTR lpszLinkFile) {
  2.     HWND hwnd = nullptr;
  3.     HRESULT hres;
  4.     IShellLink *psl;
  5.     WCHAR appPath[MAX_PATH];
  6.     WCHAR szDescription[MAX_PATH];
  7.     WIN32_FIND_DATA wfd;
  8.     WCHAR pszIconPath[MAX_PATH];
  9.     int idx{};
  10.     Software *sft = nullptr;
  11.  
  12.     // Get a pointer to the IShellLink interface. It is assumed that
  13.     // CoInitialize has already been called.
  14.     hres = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER,
  15.                             IID_IShellLink, (LPVOID *)&psl);
  16.     if (SUCCEEDED(hres)) {
  17.         IPersistFile *ppf;
  18.         hres = psl->QueryInterface(IID_IPersistFile, (LPVOID *)&ppf);
  19.  
  20.         if (SUCCEEDED(hres)) {
  21.             hres = ppf->Load(lpszLinkFile, STGM_READ);
  22.             if (SUCCEEDED(hres)) {
  23.                 hres = psl->Resolve(hwnd, SLR_NO_UI);
  24.                 if (SUCCEEDED(hres)) {
  25.                     // qDebug() << QString::fromWCharArray(lpszLinkFile);
  26.                     hres =
  27.                         psl->GetPath(appPath, MAX_PATH, (WIN32_FIND_DATA *)&wfd,
  28.                                      SLGP_SHORTPATH);
  29.                     if (nullptr == wcsstr(appPath, L".exe"))
  30.                         hres = -1;
  31.                     if (SUCCEEDED(hres)) {
  32.                         psl->GetDescription(szDescription, MAX_PATH);
  33.                     }
  34.                     if (SUCCEEDED(hres)) {
  35.                         psl->GetIconLocation(pszIconPath, MAX_PATH, &idx);
  36.                     }
  37.                     // sft = new Software(szDescription, appPath, pszIconPath,
  38.                     // idx);
  39.                     sft = new Software(lpszLinkFile, appPath, appPath, idx);
  40.                     // if (0 == wcslen(pszIconPath))
  41.                     // sft->Icon = appPath;
  42.                 }
  43.             }
  44.             ppf->Release();
  45.         }
  46.         psl->Release();
  47.     }
  48.     return sft;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement