Discussion:
About the action of ParseDisplayName
(too old to reply)
Jetflower
2010-05-04 04:24:07 UTC
Permalink
Dear gurus,
I'm having a problem in using ParseDisplayName.
1) I have a path of USB drive, such as: G:\
2) I pass this driver path into my function, which will call
ParseDisplayName to get PIDL item, as below:
LPITEMIDLIST CTemp::getItemIDList( CString p_strPath )
{
USES_CONVERSION;

if( p_strPath.IsEmpty() )
{
return NULL;
}

LPITEMIDLIST l_pIDL;
LPSHELLFOLDER pDesktopFolder;

if( ::SHGetDesktopFolder( &pDesktopFolder ) != NOERROR )
{
return NULL;
}

OLECHAR ochPath[MAX_PATH];
ULONG chEaten;
ULONG dwAttributes;
HRESULT hRes;
::MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, W2A(p_strPath), -1, ochPath,
MAX_PATH );
hRes = pDesktopFolder->ParseDisplayName( NULL, NULL, ochPath, &chEaten,
&l_pIDL, &dwAttributes);
pDesktopFolder->Release();
return l_pIDL;
}
3) The hRes result is 0x80070003 指定されたパスが見つかりません.
I don't know why it was failed.

I also try another way to solve this bug and I realize that, if i access to
this USB drive before calling ParseDisplayName, this method ParseDisplayName
always return good result, S_OK, such as:
a) Call the function ParseDisplayName at the first time, right after calling
ParseDisplayName again, the hRes result will be S_OK.
b) Declare a file path variable to one file in USB drive.
Call ParseDisplayName with this file path, then call ParseDisplayName with
the USB drive path, the hRes result will be S_OK.
c) Use while loop to browse each drive after using CSIDL_DRIVES, then
calling ParseDisplayName, the hRes result will be S_OK.

So can you help me to explain two issues:
1) Why does the ParseDisplayName method fail in this case ?
2) Why does the ParseDisplayName method success after accessing the USB
drive at first time?

If anybody here had the same situation like mine, please help me to clarify
the mystery surrounding this phenomenon.
I'm looking forward to seeing your responses.

Best regards,
Jetflower
David Lowndes
2010-05-04 08:27:35 UTC
Permalink
Post by Jetflower
::MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, W2A(p_strPath), -1, ochPath,
MAX_PATH );
What are you doing the above for? You're converting from Unicode to
ANSI, then back to Unicode!
Post by Jetflower
hRes = pDesktopFolder->ParseDisplayName( NULL, NULL, ochPath, &chEaten,
&l_pIDL, &dwAttributes);
dwAttributes is an [in.out] parameter, you're apparently passing in
random values. As you don't appear to use it, pass NULL instead.

Dave

Loading...