VC代码是实现 获得 目标T:后面的文件

解决方案 »

  1.   

    直接用外壳命令调用*.lnk文件,Windows会自动指向目标文件。
    换句话说,一般情况下你无法获知*.lnk文件中的内容。
      

  2.   


    void   GetLinkPath(char*   lpszLink,   char*   szPath)   
      {   
              HRESULT   hres;     
              IShellLink*   psl;     
              char   szGotPath[MAX_PATH];   
              WIN32_FIND_DATA   wfd;   
        
              *szPath   =   0;   //   assume   failure   
              CoInitialize(0);   
              //   Get   a   pointer   to   the   IShellLink   interface.   
              hres   =   CoCreateInstance(CLSID_ShellLink,   NULL,   
                      CLSCTX_INPROC_SERVER,   IID_IShellLink,   (LPVOID   *)   &psl);   
              if   (SUCCEEDED(hres))   {   
                      IPersistFile*   ppf;   
        
                      //   Get   a   pointer   to   the   IPersistFile   interface.   
                      hres   =   psl->QueryInterface(IID_IPersistFile,   
                              (void**)&ppf);   
                      if   (SUCCEEDED(hres))   {   
                              WCHAR   wsz[MAX_PATH];   
        
                              //   Ensure   that   the   string   is   Unicode.   
                              MultiByteToWideChar(CP_ACP,   0,   lpszLink,   -1,   wsz,   
                                      MAX_PATH);   
        
                              //   Load   the   shortcut.   
                              hres   =   ppf->Load(wsz,   STGM_READ);   
                              if   (SUCCEEDED(hres))   {   
        
                                      //   Resolve   the   link.   
                                      hres   =   psl->Resolve(0,   0);   
                                      if   (SUCCEEDED(hres))   {   
        
                                              //   Get   the   path   to   the   link   target.   
                                              hres   =   psl->GetPath(szGotPath,   
                                                      MAX_PATH,   (WIN32_FIND_DATA   *)&wfd,   
                                                      SLGP_SHORTPATH   );   
                                              if   (SUCCEEDED(hres))   
                                                      lstrcpy(szPath,   szGotPath);   
                                      }   
                              }   
                      //   Release   the   pointer   to   the   IPersistFile   interface.   
                      ppf->Release();   
                      }   
              //   Release   the   pointer   to   the   IShellLink   interface.   
              psl->Release();   
              }   
              if(hres)   
                      strcpy(szPath,   lpszLink);   
              CoUninitialize();   
      }