How to get a IShellObj for "Libraries \ Pictures"?

delphi package - easy access to shell apis
Post Reply
stebi
Posts: 8
Joined: Mon Nov 12, 2007 5:11 pm

How to get a IShellObj for "Libraries \ Pictures"?

Post by stebi »

Hi,

I can get the ShellObj for "My Pictures"-Folder with that call:

Code: Select all

madShell.ShellObj(sfMyPictures)
Since Windows 7 introduced shell "libraries" and there is the default library called "pictures" I'd like to reference that. There is no predefined TSpecialFolder for that. On my machine the library has this path "::{031E4825-7B94-4DC3-B131-E946B44C8DD5}\::{A5A3563A-5755-4A6F-854E-AFA3230B199F}". I could use this string constant (if there wouldn't be another problem, see my other post), but is it the same on all computers? Is there a better way to get the library path?
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: How to get a IShellObj for "Libraries \ Pictures"?

Post by madshi »

Microsoft has added a new API set to Vista (?) which madShell does not yet use. The "special folders" supported by madShell are based on the older OS. Don't ask why MS suddenly gives up an old API and creates a new one. Anyway, I'll probably sooner or later add support for the new API to madShell, too, but it might take a while since I'm currently busy working on madExcept 4 and some other stuff.

A GUID path like that has a certain chance of being the same on all machines. If you want to make sure, search for those GUIDs in the registry to find out what they mean.
stebi
Posts: 8
Joined: Mon Nov 12, 2007 5:11 pm

Re: How to get a IShellObj for "Libraries \ Pictures"?

Post by stebi »

I found a solution thanks to this post (Delphi XE2):

Code: Select all

uses
  Winapi, Winapi.KnownFolders;

var
  PIDL: PItemIDList;

Assert(Windows7);

SHGetKnownFolderIDList(FOLDERID_PicturesLibrary, 0, 0, PIDL);
try
  ...
finally
  ILFree(PIDL);
end;
Documentation can be found here: http://msdn.microsoft.com/en-us/library ... s.85).aspx
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: How to get a IShellObj for "Libraries \ Pictures"?

Post by madshi »

Yeah, that's the new API I mentioned earlier. Make sure you don't statically link to it, if you still want to support XP.
stebi
Posts: 8
Joined: Mon Nov 12, 2007 5:11 pm

Re: How to get a IShellObj for "Libraries \ Pictures"?

Post by stebi »

In XE2 (Winapi.ShlObj) SHGetKnownFolderIDList is declared as "delayed", so it should be no problem on older OS.
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: How to get a IShellObj for "Libraries \ Pictures"?

Post by madshi »

Didn't even know that XE2 supports "delayed"... :D I'm supporting all Delphi versions down to Delphi 4, so I couldn't do it this way. But of course dynamic linking is not a problem, so it's easily doable.
stebi
Posts: 8
Joined: Mon Nov 12, 2007 5:11 pm

Re: How to get a IShellObj for "Libraries \ Pictures"?

Post by stebi »

"delayed" came with Delphi 2010.
Post Reply