网上找的获取快捷方式信息的代码{获取快捷方式信息}
function TForm1.LinkFileInfo(const lnkFileName:string;var info:LINK_FILE_INFO;const bSet:boolean):boolean;
var
 hr:hresult;
 psl:IShelllink;
 wfd:win32_find_data;
 ppf:IPersistFile;
 lpw:pwidechar;
 buf:pwidechar;
begin
 result:=false;
 getmem(buf,MAX_PATH);
 try
 if SUCCEEDED(CoInitialize(nil)) then
 if (succeeded(cocreateinstance(clsid_shelllink,nil,clsctx_inproc_server,IID_IShellLinkA,psl))) then
 begin
   hr:=psl.QueryInterface(iPersistFile,ppf);
   if succeeded(hr) then
   begin
     lpw:=stringtowidechar(lnkfilename,buf,MAX_PATH);
     hr := ppf.Load(lpw, STGM_READ);
     if succeeded(hr) then
     begin
       hr := psl.Resolve(0, SLR_NO_UI);
       if succeeded(hr) then
       begin
         if bSet then
         begin
           psl.SetArguments(info.Arguments);
           psl.SetDescription(info.Description);
           psl.SetHotkey(info.HotKey);
           psl.SetIconLocation(info.IconLocation,info.IconIndex);
           //psl.SetIDList(info.ItemIDList);      注意这个别修改,不然图标就不好更换了,嘿嘿
           psl.SetPath(info.FileName);
           psl.SetShowCmd(info.ShowState);
           psl.SetRelativePath(info.RelativePath,0);
           psl.SetWorkingDirectory(info.WorkDirectory);
           result:=succeeded(psl.Resolve(0,SLR_UPDATE));
         end
         else
         begin
           psl.GetPath(info.FileName,MAX_PATH, wfd,SLGP_SHORTPATH );
           psl.GetIconLocation(info.IconLocation,MAX_PATH,info.IconIndex);
           psl.GetWorkingDirectory(info.WorkDirectory,MAX_PATH);
           psl.GetDescription(info.Description,CCH_MAXNAME);
           psl.GetArguments(info.Arguments,MAX_PATH);
           psl.GetHotkey(info.HotKey);
           psl.GetIDList(info.ItemIDList);
           psl.GetShowCmd(info.ShowState);
           result:=true;
         end;
       end;
     end;
   end;
end;
 finally
 freemem(buf);
 end;
end;
这是调用的代码function TForm1.url_search():boolean;//搜索快捷方式
var
  files: TStringDynArray;
  str: string;
  str1:string;
  info:LINK_FILE_INFO;
begin
  str1:='';
  if LinkFileInfo('C:\Documents and Settings\Administrator\桌面\2345智能浏览器.lnk',info,false) then
  begin
      //Move(info.FileName[9],str1[1],2);
      //linkfileinfo('C:\Documents and Settings\Administrator\桌面\2345智能浏览器.lnk',info,true);
      showmessage(inttostr(info.FileName));
  end;
 result:=false;
end;
显示出来只要是pchar数组的,showmessage出来都是乱码,是什么原因,求解谢谢

解决方案 »

  1.   

    试试楼上的,为什么要把地址直接inttostr转换,直接转为文本就可以了。
      

  2.   


    不好意思,上面这段我写错了,就直接Info.filename还是乱码的,很无语。。
      

  3.   


    使用楼上的还是乱码,只要是pchar数组的,输出来都是乱码的
      

  4.   

    是char数组啊,array[0..MAXPATH] of Char;
      

  5.   


    但是那样showmessage出来是乱码,s11ss能不能帮忙试一下,很奇怪。。,谢谢。。
      

  6.   

    调用的代码就是下面的方法
    function TForm1.url_search():boolean;//搜索快捷方式
    var
      files: TStringDynArray;
      str: string;
      str1:string;
      info:LINK_FILE_INFO;
    begin
      str1:='';
      if LinkFileInfo('C:\Documents and Settings\Administrator\桌面\2345智能浏览器.lnk',info,false) then
      begin
          //Move(info.FileName[9],str1[1],2);
          //linkfileinfo('C:\Documents and Settings\Administrator\桌面\2345智能浏览器.lnk',info,true);
          showmessage(info.FileName);
      end;
     result:=false;
    end;直接指定的一个lnk对象,然后show出来,就是乱码了