Article View: borland.public.cppbuilder.nativeapi
Article #10074Re: Drive path and drive display name question
From: Remy Lebeau (TeamB)
Date: Thu, 27 May 2004 03:07
Date: Thu, 27 May 2004 03:07
122 lines
4580 bytes
4580 bytes
"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:
<40b55c7e$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!controlnews3.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<40b5228c@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: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <40b5228c@newsgroups.borland.com> Subject: Re: Drive path and drive display name question Date: Wed, 26 May 2004 20:07:19 -0700 Lines: 124 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: 67.22.135.163 Message-ID: <40b55c7e$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1085627518 67.22.135.163 (26 May 2004 20:11:58 -0700) Path: arc1-ca.pugleaf.net!controlnews3.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail