title: Display Real path of (.lnk) shortcut file using C++
body: <p>I'm trying to display real Path (target ) of shortcut (.lnk) file .So i copy and paste (test.lnk)in corrent folder of project and I'm trying to display its target </p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  #include &lt;objidl.h&gt;   /* For IPersistFile */
  #include &lt;shlobj.h&gt;   /* For IShellLink */
  #include "objbase.h"
  
  using namespace std;
  
  
  /*********************************************************************
  * Function......: ResolveShortcut
  * Parameters....: lpszShortcutPath - string that specifies a path
                                       and file name of a shortcut
  *          lpszFilePath - string that will contain a file name
  * Returns.......: S_OK on success, error code on failure
  * Description...: Resolves a Shell link object (shortcut)
  *********************************************************************/
  HRESULT ResolveShortcut(/*in*/ LPCTSTR lpszShortcutPath,
                          /*out*/ LPTSTR lpszFilePath)
  {
      HRESULT hRes = E_FAIL;
      IShellLink*    psl     = NULL;
  
          // buffer that receives the null-terminated string
          // for the drive and path
      TCHAR szPath[MAX_PATH];
          // buffer that receives the null-terminated
          // string for the description
      TCHAR szDesc[MAX_PATH];
          // structure that receives the information about the shortcut
      WIN32_FIND_DATA wfd;
      WCHAR wszTemp[MAX_PATH];
  
      lpszFilePath[0] = '\0';
  
      // Get a pointer to the IShellLink interface
      hRes = CoCreateInstance(CLSID_ShellLink,
                              NULL,
                              CLSCTX_INPROC_SERVER,
                              IID_IShellLink,
                              (void**)&amp;psl);
  
      if (SUCCEEDED(hRes))
      {
          // Get a pointer to the IPersistFile interface
          IPersistFile*  ppf     = NULL;
          psl-&gt;QueryInterface(IID_IPersistFile, (void **) &amp;ppf);
  
  
          // IPersistFile is using LPCOLESTR,
                  // so make sure that the string is Unicode
  #if !defined _UNICODE
          MultiByteToWideChar(CP_ACP, 0, lpszShortcutPath,
                                         -1, wszTemp, MAX_PATH);
  #else
          wcsncpy(wszTemp, lpszShortcutPath, MAX_PATH);
  #endif
  
          // Open the shortcut file and initialize it from its contents
          hRes = ppf-&gt;Load(wszTemp, STGM_READ);
          if (SUCCEEDED(hRes))
          {
              // Try to find the target of a shortcut,
                          // even if it has been moved or renamed
              hRes = psl-&gt;Resolve(NULL, SLR_UPDATE);
              if (SUCCEEDED(hRes))
              {
                  // Get the path to the shortcut target
                  hRes = psl-&gt;GetPath(szPath,
                                       MAX_PATH, &amp;wfd, SLGP_RAWPATH);
                  if (FAILED(hRes))
                      return hRes;
  
                  // Get the description of the target
                  hRes = psl-&gt;GetDescription(szDesc,
                                               MAX_PATH);
                  if (FAILED(hRes))
                      return hRes;
  
                  lstrcpyn(lpszFilePath, szPath, MAX_PATH);
  
              }
          }
      }
  
      return hRes;
  }
  
  int main(void)
  {
  
      LPCTSTR lpszShortcutPath =("test.lnk");
      TCHAR szFilePath[MAX_PATH];
  
      HRESULT hRes =ResolveShortcut(lpszShortcutPath, szFilePath);
       cout &lt;&lt; TEXT("Succeeded: path = ") &lt;&lt;hRes ;
      return 0;
  }
  </code></pre>
  
  <p>it displays Succeeded: path = -2134343</p>
  
  <p>Can someone help me to display real target of .lnk file and its  Description.</p>