/* The original version of this program can be found at http://damb.dk */
#include <windows.h>
#include <shlobj.h>
#include <string>

std::string GetFolder(HWND aHwndOwner, const std::string aTitle)
{
   BROWSEINFO BrowseInfo;
   char temp[MAX_PATH];
   BrowseInfo.hwndOwner = aHwndOwner;
   BrowseInfo.pidlRoot = 0;
   BrowseInfo.pszDisplayName = temp;
   BrowseInfo.lpszTitle = aTitle.c_str();
   BrowseInfo.ulFlags = BIF_USENEWUI;
   BrowseInfo.lpfn = 0;
   BrowseInfo.lParam = 0;
   BrowseInfo.iImage = 0;
   ITEMIDLIST *ItemList = SHBrowseForFolder(&BrowseInfo);

   if(ItemList)
   {
      SHGetPathFromIDList(ItemList, temp);
      LPMALLOC Malloc;
      SHGetMalloc(&Malloc);
      Malloc->Free(ItemList);
      Malloc->Release();
      return std::string(temp);
   }
   return std::string("");
}

int main()
{
   std::string Path = GetFolder(0, "Select install path");
   MessageBox(0, Path.c_str(), "You selected:", MB_OK);
}