madShell.ShellObj(Path) can't resolve "Libraries \ Pictures"

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

madShell.ShellObj(Path) can't resolve "Libraries \ Pictures"

Post by stebi »

Hi,

I have a problem converting a path to IShellObj. The Path is '::{031E4825-7B94-4DC3-B131-E946B44C8DD5}\::{A5A3563A-5755-4A6F-854E-AFA3230B199F}'. It points to "Libraries \ Pictures". This GUID-Representation is generated by IShellObj, but cannot be resolved from string back to an IShellObj (I want to store the path for next application startup).

Please have a look at following code:

Code: Select all

var 
  ListView: TcxShellListView; // ShellListView from Developer Express
  IDList: IIDList;
  ShellObj: IShellObj;
  Path: string;
...
IDList := madShell.IDList(ListView.AbsolutePIDL, False); // Get Current Path of ShellListeView
ShellObj := madShell.ShellObj(IDList);
Path := ShellObj.Path; // Returns '::{031E4825-7B94-4DC3-B131-E946B44C8DD5}\::{A5A3563A-5755-4A6F-854E-AFA3230B199F}' for "Libraries \ Pictures"

ShellObj := madShell.ShellObj(Path); // Do the reverse, string -> IShellObj
if ShellObj.Path <> Path then
  ErrorReproduced;
Is this a bug in madShell or is my code wrong?

My OS: Win7-64 (32 Bit Application)
madshi
Site Admin
Posts: 10342
Joined: Sun Mar 21, 2004 5:25 pm

Re: madShell.ShellObj(Path) can't resolve "Libraries \ Pictu

Post by madshi »

Hmmmm... It's been quite a while til I looked into madShell. I do remember those weird GUID paths, but I'm not sure why things are not working for you. I don't have the Developer Express components, so I will not be able to reproduce this problem. Maybe you can dig into madShell yourself and find out what's going on?
stebi
Posts: 8
Joined: Mon Nov 12, 2007 5:11 pm

Re: madShell.ShellObj(Path) can't resolve "Libraries \ Pictu

Post by stebi »

This hasn't anything to do with Developer Express (assuming it's a valid PIDL this component returns). If I shorten the path to the first part (only "Libraries") it works, but the combined path doesn't work. It's the function "PathToIDList" which doesn't work as expected. It seems that parsing the string ist OK. It successfully separates both parts, but the call for the second part fails.

Simply try:

Code: Select all

PathToIDList('::{031E4825-7B94-4DC3-B131-E946B44C8DD5}\::{A5A3563A-5755-4A6F-854E-AFA3230B199F}');
madshi
Site Admin
Posts: 10342
Joined: Sun Mar 21, 2004 5:25 pm

Re: madShell.ShellObj(Path) can't resolve "Libraries \ Pictu

Post by madshi »

Well, you could step through madShell, trying to figure out why PathToIDList fails. Maybe IShellFolder.ParseDisplayName fails for whatever reason? I can put this on my to do list, but it might take a while before I find the time for this.

In order to step through the madShell source code, you need to copy madShell.pas and mad.inc to your project folder. Afterwards edit mad.inc, so that "{$D+}{$L+}".
stebi
Posts: 8
Joined: Mon Nov 12, 2007 5:11 pm

Re: madShell.ShellObj(Path) can't resolve "Libraries \ Pictu

Post by stebi »

I found the bug (may I add, the code of this function is horrible). The problem is after all the splitting of the path. It fails on the last part. The Path consts of two parts, but it doesn't stop after that and fails in the third iteration and exists the function.

Before (function PathToIDList(path: UnicodeString) : IIDList; Line

Code: Select all

if       i1 = 0                      then i1 := maxInt
The Fix (this makes possible that "Path" gets cleared completely):

Code: Select all

if i1 = 0 then
begin
  i1 := maxInt;
  i2 := i1;
end
Another addition is useful: I think the c2-Parameter must be initialized (local variables can have any value when not initialized)

Code: Select all

            c2 := 0; // It's an In/Out-Parameter and must be initialized
            b1 := sf1.ParseDisplayName(0, nil, PWideChar(ws1), c1, pidl2, c2) = 0;
madshi
Site Admin
Posts: 10342
Joined: Sun Mar 21, 2004 5:25 pm

Re: madShell.ShellObj(Path) can't resolve "Libraries \ Pictu

Post by madshi »

Thanks, I appreciate the fix, I've already added it to my code. Yeah, that code is hard to understand, due to lack of comments and unnamed local variables. I wrote that more than 10 years ago. I hope my programming style has improved a bit since then... :oops:
Post Reply