Why can't get control panel name?

282 Views Asked by At

I use Shell to get control panel

Code:

procedure TForm1.FormCreate(Sender: TObject);
var
  psfDeskTop: IShellFolder;
  psfWork: IShellFolder; 
  pidworkDir: PITEMIDLIST;
  pidChild: PITEMIDLIST;
  pEnumList: IEnumIDList;
  celtFetched: ULONG;
  FileInfo: SHFILEINFOW;

begin

  Memo1.Clear;
  SHGetDesktopFolder(psfDeskTop);
  //control panel
  SHGetSpecialFolderLocation(0, CSIDL_CONTROLS, pidworkDir);  
  psfDeskTop.BindToObject(pidworkDir, nil, IID_IShellFolder, psfWork);
  psfWork.EnumObjects(0, SHCONTF_NONFOLDERS or SHCONTF_FOLDERS or SHCONTF_INCLUDEHIDDEN, pEnumList);
  while pEnumList.Next(1, pidChild, celtFetched) = 0 do
  begin

    SHGetFileInfo(LPCTSTR(pidChild), 0, FileInfo, SizeOf(FileInfo), SHGFI_PIDL
      or SHGFI_TYPENAME or SHGFI_DISPLAYNAME or SHGFI_USEFILEATTRIBUTES);

    Memo1.Lines.Add(FileInfo.szDisplayName + '   +');

  end;  
end;

it can't get FileInfo.szDisplayName , i just use ' +' to make Memo1 dispaly. Why can't get control panel name ?

enter image description here

1

There are 1 best solutions below

0
On BEST ANSWER

I'm not an expert on the shell. In fact I know practically nothing. But by reading the documentation I can glean the following:

  1. SHGetFileInfo expects an absolute PIDL.
  2. IEnumIDList enumerates relative PIDLs.

So you code is bound to fail because of that. Perhaps there are other errors too. I can't tell.

Anyway, I think the easy way to solve the problem is to use IShellFolder.GetDisplayNameOf to obtain the name you need:

uses
  ..., ShLwApi, ...
....
var
  StrRetName: TStrRet;
  Name: PChar;
....  
while pEnumList.Next(1, pidChild, celtFetched) = 0 do
begin
  OleCheck(psfWork.GetDisplayNameOf(pidChild, SHGDN_NORMAL, StrRetName));
  OleCheck(StrRetToStr(@StrRetName, nil, Name));
  Memo1.Lines.Add(Name);
  CoTaskMemFree(Name);
  CoTaskMemFree(pidChild);
end;