我要调用SHBrowseForFolder来弹出特殊的文件夹窗体;
编译时没问题; 但程序运行到
SHGetPathFromIDList(idBrowse,tmp);
时DELPHI一直报错,请教一下错在哪里了*_*?
但是我在VB中都没有这种问题的!uses shlobj;procedure TForm1.Button1Click(Sender: TObject);
var
  BrowseInfo: TBrowseInfo;
  DisplayName: array[0..MAX_PATH] of char;
  idBrowse,idl : PItemIDList;
  tmp : PChar;
  tmp1:string;
begin
SHGetSpecialFolderLocation(form1.Handle,17, idl);
  with BrowseInfo do begin
    hWndOwner:=form1.Handle;
    pidlRoot:=idl;
    pszDisplayName:=DisplayName;
    lpszTitle:='Please choose a folder!';
    ulFlags:=BIF_RETURNONLYFSDIRS;
    lpfn:=nil;
    lParam:=0;
  end;
  idBrowse:=SHBrowseForFolder(BrowseInfo);
  if assigned(idBrowse) then
  Begin
     SHGetPathFromIDList(idBrowse,tmp); // SHELL32。DLL错误?
     edit1.Text :=strpas(tmp);
  end;
end;

解决方案 »

  1.   

    FillChar(idl,0,sizeof(idl))
    function GetFolder;
    var
      lpbi: TBrowseInfo;
      folderName: array[1..MAX_PATH] of char;
    begin
      Result := '';
      FillChar(lpbi, SizeOf(BrowseInfo), 0);
      if SHGetPathFromIDList(SHBrowseForFolder(lpbi), @folderName) then
        Result := strpas(@folderName);
    end;
      

  2.   

    {***************************************************************
     * 方 法 名  : GetPath
     * 编写目的   : 选择目录
     * 作    者  : 黄仁光
     * 参    数  : Handle:HWnd
     * 结    果  : string
     * 编写日期   :2002年10月08日
     ****************************************************************}
    function GetPath(Handle:HWnd): string;
    var
      bInfo: ^BROWSEINFO;
      FolderName: array[0..MAX_PATH] of char;
      DirPath: array[0..MAX_PATH] of char;
      ItemID: PITEMIDLIST;
    begin
      DirPath := '';
      bInfo := AllocMem(sizeof(BROWSEINFOA));
      bInfo.hwndOwner := Handle;
      bInfo.pszDisplayName := FolderName;
      bInfo.lpszTitle := '请选择文件夹';
      ItemID := SHBrowseForFolder(bInfo^);
      if ItemID <> nil then
      begin
        SHGetPathFromIDList(ItemID, DirPath);
        FreeMem(bInfo, sizeof(BROWSEINFOA));
      end;
      result := DirPath;
    end;