🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #9986

Re: Drive path and drive display name question

#9986
From: Martin C
Date: Fri, 28 May 2004 04:26
129 lines
5056 bytes
Thanks Remy so much for your detailed reply.

"Remy Lebeau (TeamB)" <gambit47.no.spam@no.spam.yahoo.com> wrote in message
news:40b55c7e$1@newsgroups.borland.com...
>
> "Martin C" <martincplus@hotmail.com> wrote in message
> news:40b5228c@newsgroups.borland.com...
>
> > I am using SHGetFileInfo API function to retrieve drives display
> > name, so is it possible (api or code) to retrieve drive path from
> > the drive display name?
>
> There is no guarantee that the display name will contain the drive.  You
> have to obtain it separately.
>
> > In other words is there any API function that I can use to convert for
> > example ( "MASTER(C:)"  to  "C:\")?
>
> There is no single API function for that.  What you can try doing, though,
> is using IShellFolder::ParseDisplayName() or SHParseDisplayName() to
convert
> the display name into an ITEMIDLIST, and then pass that to
> SHGetPathFromIDList().  For example:
>
>     #include <utilcls.h>
>
>     LPITEMIDLIST IL_GetNext(LPCITEMIDLIST pidl)
>     {
>         if( pidl == NULL )
>             return NULL;
>
>         int cb = pidl->mkid.cb;
>
>         if( cb == 0 )
>             return NULL;
>
>         LPITEMIDLIST pidlTemp = (LPITEMIDLIST) (((LPBYTE) pidl) + cb);
>         return (pidlTemp->mkid.cb == 0) ? NULL : pidlTemp;
>     }
>
>     UINT IL_GetSize(LPCITEMIDLIST pidl)
>     {
>         UINT cbTotal = 0;
>         LPITEMIDLIST pidlTemp = (LPITEMIDLIST) pidl;
>         if( pidlTemp )
>         {
>             cbTotal += sizeof(pidlTemp->mkid.cb);
>             while( pidlTemp )
>             {
>                 cbTotal += pidlTemp->mkid.cb;
>                 pidlTemp = IL_GetNext(pidlTemp);
>             }
>         }
>         return cbTotal;
>     }
>
>     LPITEMIDLIST IL_Clone(LPCITEMIDLIST pidl)
>     {
>         UINT cb = IL_GetSize(pidl);
>
>         LPITEMIDLIST pidlRet = (LPITEMIDLIST) CoTaskMemAlloc(cb);
>         if( pidlRet )
>             CopyMemory(pidlRet, pidl, cb);
>
>         return pidlRet;
>     }
>
>     LPITEMIDLIST IL_Append(LPCITEMIDLIST pidlBase, LPCITEMIDLIST pidlAdd)
>     {
>         if( pidlBase == NULL )
>             return NULL;
>
>         if( pidlAdd == NULL )
>             return IL_Clone(pidlBase);
>
>         UINT cb1 = IL_GetSize(pidlBase) - sizeof(pidlBase->mkid.cb);
>         UINT cb2 = IL_GetSize(pidlAdd);
>
>         LPITEMIDLIST pidlNew = (LPITEMIDLIST) CoTaskMemAlloc(cb1 + cb2);
>         if( pidlNew )
>         {
>             CopyMemory(pidlNew, pidlBase, cb1);
>             CopyMemory(((LPBYTE)pidlNew) + cb1, pidlAdd, cb2);
>         }
>         return pidlNew;
>     }
>
>     AnsiString __fastcall GetPathFromDisplayName(const AnsiString
> &DisplayName)
>     {
>         char Path[MAX_PATH+1] = {0};
>
>         TComInterface<IShellFolder> Desktop;
>         if( SUCCEEDED(SHGetDesktopFolder(&Desktop)) )
>         {
>             LPITEMIDLIST DrivesPidl = NULL;
>             if( SUCCEEDED(SHGetSpecialFolderLocation(NULL, CLSID_DRIVES,
> &DrivesPidl)) )
>             {
>                 TComInterface<IShellFolder> Drives;
>                 if( SUCCEEDED(Desktop->BindToObject(DrivesPidl, NULL,
> IID_IShellFolder, (LPVOID*)&Drives)) )
>                 {
>                     ULONG eaten = 0;
>                     LPITEMIDLIST DisplayPidl = NULL;
>                     if( SUCCEEDED(Drives->ParseDisplayName(NULL, NULL,
> WideString(DisplayName), &eaten, &DisplayPidl, NULL)) )
>                     {
>                         LPITEMIDLIST PathPidl = IL_Append(DrivesPidl,
> DisplayPidl);
>                         if( PathPidl )
>                         {
>                             SHGetPathFromIDList(PathPidl, Path);
>                             CoTaskMemFree(PathPidl);
>                         }
>                         CoTaskMemFree(DisplayPidl);
>                     }
>                 }
>                 CoTaskMemFree(DrivesPidl);
>             }
>         }
>
>         return AnsiString(Path);
>     }
>
>
> Gambit
>
>
Technical Details
Message-ID: <40b6a372@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!controlnews3.google.com!news1.google.com!news.glorb.com!news-hog.berkeley.edu!ucberkeley!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <40b5228c@newsgroups.borland.com> <40b55c7e$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,c795424ce368b5ed
X-Google-Attributes: gid10cc67,public
From: "Martin C" <martincplus@hotmail.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <40b5228c@newsgroups.borland.com> <40b55c7e$1@newsgroups.borland.com>
Subject: Re: Drive path and drive display name question
Date: Thu, 27 May 2004 22:26:45 -0600
Lines: 131
Organization: V Safe
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 81.10.4.238
Message-ID: <40b6a372@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1085711218 81.10.4.238 (27 May 2004 19:26:58 -0700)
Path: arc1-ca.pugleaf.net!controlnews3.google.com!news1.google.com!news.glorb.com!news-hog.berkeley.edu!ucberkeley!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail