Simplest way to let the user select a directory is with the shell browse for folder dialog. Here is an example with a few bells and whistles to set the start directory (in this case to current directory, but you could pass another directory as a parameter to the callback routine) and to show the currently selected directory as status text. If you don't need this, you can forget the callback routine.
#include "stdafx.h"
#include <shlobj.h>
int CALLBACK cbpbrff(HWND hwnd,UINT uMsg,LPARAM lp,LPARAM pData)
{
char dir[256];
switch(uMsg)
{
case BFFM_INITIALIZED:
{
if (GetCurrentDirectory(256,dir))
{
SendMessage(hwnd,BFFM_SETSELECTION,TRUE,(LPARAM)dir);
}
break;
}
case BFFM_SELCHANGED:
{
if (SHGetPathFromIDList((LPITEMIDLIST)lp,dir))
{
SendMessage(hwnd,BFFM_SETSTATUSTEXT,0,(LPARAM)dir);
}
break;
}
default:
break;
}
return 0;
}
void getFolder(char* title,char* fldrPath,HWND owner = NULL)
{
BROWSEINFO brinfo;
LPITEMIDLIST pidl;
ZeroMemory(&brinfo,sizeof(brinfo));
brinfo.hwndOwner = owner;
brinfo.pidlRoot = NULL;
brinfo.lpszTitle = title;
brinfo.ulFlags = BIF_RETURNONLYFSDIRS|BIF_STATUSTEXT;
brinfo.lpfn = cbpbrff;
pidl = SHBrowseForFolder(&brinfo);
if (pidl) SHGetPathFromIDList(pidl,fldrPath);
IMalloc* im;
SHGetMalloc(&im);
im->Free(pidl);
im->Release();
}
int main(int argc, char* argv[])
{
char path[256];
getFolder("Select folder",path);
return 0;
}
If called from a windows app you should set the owner hwnd.

Click here if this helped!

vvvvvvvvv