This code should do what you are asking for:
Code:
#define _WIN32_DCOM
#include <windows.h>
#include <shlobj.h>
#include <tchar.h>
#include <stdio.h>
int main()
{
BROWSEINFO bi;
char pszBuffer[MAX_PATH];
LPITEMIDLIST pidl;
LPMALLOC lpMalloc;
// Initialize COM
if(CoInitializeEx(0,COINIT_APARTMENTTHREADED) != S_OK)
{
MessageBox(NULL,_T("Error opening browse window"),_T("ERROR"),MB_OK);
CoUninitialize();
return 0;
}
// Get a pointer to the shell memory allocator
if(SHGetMalloc(&lpMalloc) != S_OK)
{
MessageBox(NULL,_T("Error opening browse window"),_T("ERROR"),MB_OK);
CoUninitialize();
return 0;
}
bi.hwndOwner = NULL;
bi.pidlRoot = NULL;
bi.pszDisplayName = pszBuffer;
bi.lpszTitle = _T("Select a install Directory");
bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam = 0;
if(pidl = SHBrowseForFolder(&bi))
{
// Copy the path directory to the buffer
if(SHGetPathFromIDList(pidl,pszBuffer))
{
// pszBuffer now holds the directory path
printf(_T("You selected the directory: %s\n"),pszBuffer);
}
lpMalloc->Free(pidl);
}
lpMalloc->Release();
CoUninitialize();
return 0;
}