BROWSEINFO bi = { 0 };
bi.lpszTitle = _T("Pick a Directory");
LPITEMIDLIST pidl = SHBrowseForFolder ( &bi );
if ( pidl != 0 )
{
// get the name of the folder
TCHAR path[MAX_PATH];
if ( SHGetPathFromIDList ( pidl, path ) )
{
_tprintf ( _T("Selected Folder: %s\n"), path );
}
// free memory used
IMalloc * imalloc = 0;
if ( SUCCEEDED( SHGetMalloc ( &imalloc )) )
{
imalloc->Free ( pidl );
imalloc->Release ( );
}
}
(Note that this code is backward compatible with Windows 95/Windows NT 4.0. If you only need to support Windows 2000 and newer, then pidl can be freed using CoTaskMemFree.)
Andy
PS And as SHBrowseForFolder is a COM based function, you need to call CoInitializeEx (with COINIT_APARTMENTTHREADED), CoInitialize, or OleInitialize before you use it. And CoUninititialize/OleUninititialize after you're done with it.