#include <shlobj.h>
#include <comdef.h>
void MyIShellFolder( )
{
HRESULT hr;
LPSHELLFOLDER pDesktop;
LPSHELLFOLDER pTargetFolder;
LPITEMIDLIST pidlTarget;
LPITEMIDLIST pidlItem;
LPENUMIDLIST pEnum;
DWORD dwRetrieved;
STRRET str; // STRRET 構造体
char szName[MAX_PATH];
_bstr_t MyComp( "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" );
_bstr_t Cpanel( "::{21EC2020-3AEA-1069-A2DD-08002B30309D}" );
_bstr_t Sep( "\\" );
_bstr_t Target("");
Target.operator += (MyComp);
Target.operator += (Sep);
Target.operator += (Cpanel);
// デスクトップフォルダの取得
hr = SHGetDesktopFolder( &pDesktop );
if( FAILED( hr ) ) {
return;
}
hr = pDesktop->ParseDisplayName(
NULL,
NULL,
Target,
NULL,
&pidlTarget,
NULL
);
if ( pidlTarget == NULL ) {
pDesktop->Release();
return;
}
// フォルダオブジェクトの取得
hr = pDesktop->BindToObject(
pidlTarget,
NULL,
IID_IShellFolder,
(LPVOID*)&pTargetFolder
);
if( FAILED( hr ) ) {
pDesktop->Release();
return;
}
// 一覧の取得
hr = pTargetFolder->EnumObjects(
NULL,
SHCONTF_FOLDERS | SHCONTF_NONFOLDERS,
&pEnum
);
if( FAILED( hr ) ) {
pTargetFolder->Release();
pDesktop->Release();
return;
}
while( 1 ) {
// pidlItem に一つセットする
hr = pEnum->Next( 1, &pidlItem, &dwRetrieved );
if( FAILED( hr ) ) {
break;
}
if ( dwRetrieved == 0 ) {
break;
}
hr = pTargetFolder->GetDisplayNameOf( pidlItem, SHGDN_NORMAL, &str );
if( FAILED( hr ) ) {
continue;
}
WideCharToMultiByte( CP_ACP,
0,
str.pOleStr,
-1,
szName,
MAX_PATH,
NULL,
NULL
);
MessageBox( NULL, szName, "", MB_OK );
}
// 取得したものは解放
pEnum->Release();
pTargetFolder->Release();
pDesktop->Release();
}