While that example most likely will work fine, it requires .NET and the question was about C++.
If you wouldn't want to use .NET, you could use something like this:
BOOL GetFileName(char *filename,int maxlen)
{ OPENFILENAME ofn = {0};
ofn.lStructSize = sizeof(ofn);
ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
ofn.hInstance = GetModuleHandle(0);
ofn.lpstrFile = filename;
ofn.nMaxFile = maxlen;
ofn.nFilterIndex = 1;
ofn.lpstrFilter = "Any file\0*.*\0\0";
ofn.lpstrDefExt = "*";
return GetOpenFileName(&ofn);
}
char filename[MAX_PATH];
if(!GetFileName(filename,MAX_PATH))
MessageBox(0,"Canceled by user."," ",0);
else{
}
Now to extract the path from
filename
, you could for example use
PathRemoveFileSpec[
^].
If getting a directory is all you want to do, i.e. if you're not interested in the name of the file, you could also select a directory right away with
SHBrowseForFolder[
^].