Re: Getting localized name folder by Bipin
Bipin
Thu Jul 24 20:12:43 CDT 2008
As said earlier, adding code for others reference.
This is working code so if any one have any queries if it dosent work
for you... get back to this thread so as i can revert back.
int GetLocalizedName(char *pFolderPath, char *pFolderName, char
*pDisplayName)
{
LPMALLOC pMalloc;
LPITEMIDLIST pidlPrograms;
LPSHELLFOLDER pFolder = NULL;
LPITEMIDLIST pidl;
LPSHELLFOLDER pDesktopFolder;
char szPath[MAX_PATH];
OLECHAR olePath[MAX_PATH];
ULONG chEaten;
ULONG dwAttributes;
HRESULT hr;
STRRET sName;
LPSHELLFOLDER pSubFolder = NULL;
LPITEMIDLIST pidlCopy = NULL;
// Get the shell's allocator.
if (!SUCCEEDED(SHGetMalloc(&pMalloc)))
return 0;
strcpy(szPath, pFolderPath);
strcat(szPath, "\\");
strcat(szPath, pFolderName);
if (SUCCEEDED(SHGetDesktopFolder(&pDesktopFolder)))
{
MultiByteToWideChar(CP_ACP,
MB_PRECOMPOSED,
szPath,
-1,
olePath,
MAX_PATH);
hr = pDesktopFolder->ParseDisplayName( NULL,
NULL,
(LPOLESTR)olePath,
&chEaten,
&pidl,
&dwAttributes);
if (FAILED(hr))
{
return 0;
// Handle error.
}
}
if (SUCCEEDED(pDesktopFolder->GetDisplayNameOf(
pidl, SHGDN_NORMAL,
&sName))) {
LPSTRRET lpStr = &sName;
LPSTR lpsz;
int cch;
switch (lpStr->uType) {
case STRRET_WSTR:
cch = WideCharToMultiByte(CP_SYMBOL, 0,
lpStr->pOleStr, -1, NULL, 0, NULL, NULL);
lpsz = (LPSTR) pMalloc->Alloc(cch*2);
if (lpsz != NULL) {
WideCharToMultiByte(CP_ACP, 0,
lpStr->pOleStr, -1, lpsz, cch*2, NULL, NULL);
printf("%s\n", lpsz);
}
strcpy(pDisplayName, lpsz);
pMalloc->Free(lpsz);
break;
case STRRET_OFFSET:
strcpy(pDisplayName, ((char *) pidl) + lpStr-
>uOffset);
printf("%s\n", ((char *) pidl) + lpStr->uOffset);
break;
case STRRET_CSTR:
strcpy(pDisplayName, lpStr->cStr);
printf("%s\n", lpStr->cStr);
break;
}
}
pMalloc->Free(pidl);
pMalloc->Release();
return 1;
}
On Jul 22, 9:31 am, Bipin Mistry <bpnmis...@gmail.com> wrote:
> Alex
>
> Thanks for the details, but what you have explained is bit complicated
> to work on... so I have taken following way as received in other group
> post by me.
>
> Use SHGetDesktopFolder() then ::ParseDisplayName() to get the
> LPITEMIDLIST from the path then ::GetDisplayNameOf() &
> SIGDN_NORMALDISPLAY
> (+ SHGetLocalizedName() on Vista)
>
> I am posting this here so as if any one needs to have batter off then
> one can have some options.
>
> Thanks
> Bipin Mistry
>
> On 7月19日, 午後4:10, "Alex Blekhman" <tkfx.REM...@yahoo.com> wrote:
>
>
>
> > "Bipin Mistry" wrote:
> > > My issue is I need to check specific path provided by user, does
> > > this path has any localized name?
> > > If Yes, return the Localized name
> > > In No, return the same folder name back
>
> > You can inistialize a lookup table with `SHGetSpecialFolderPath'
> > calls that go for every possible CSIDL. Then just compare specific
> > path provided by user against these strings. Of course, you will
> > need to update this lookup table for every new release of PSDK.
>
> > Alex- Hide quoted text -
>
> - Show quoted text -