Delphi:从快捷方式取得文件路径

(* -------------------------------------------- 
   Get *real* file path from a shortcut (*.lnk) 
   -- 
   Required units: ShlObj, ActiveX 
-------------------------------------------- *)  
  
function GetExeFromLink(FileName : String) : String;  
var  
   IntfShelllink : IShellLink;  
   intfFile : IPersistFile;  
   fwName : WideString;  
   DirName : String;  
   pDirName : PChar;  
   Data : win32_find_data;  
begin  
      // Get *real* file path from a shortcut (*.lnk)  
  
      fwName := FileName;  
      IntfShelllink := CreateComObject(CLSID_Shelllink) as IShellLink;  
      intfFile := IntfShelllink as IPersistFile;  
      intfFile.Load(pwchar(fwname), STGM_READ);  
      Setlength(DirName, MAX_PATH);  
      pDirName := PChar(DirName);  
      IntfShelllink.GetPath(pDirName, max_path, Data, 0);  
  
      Result := pDirName;  
end;  

转自:http://blog.csdn.net/fengyu09/article/details/8664801

posted @ 2017-04-10 14:37  stma  阅读(502)  评论(0)    收藏  举报