SHBrowseForFolder set initial folder and return LPSTR of path

  • Thread starter Thread starter Minieggs1999
  • Start date Start date
M

Minieggs1999

Guest
Hi All

Not being a C++ developer I am trying to wrap SHBrowseForFolder into a DLL so that it takes an initial path and returns the selected path as an LPSTR as that is what is calling it needs

I'm only part way there but I can't seem to get it to select the folder I pass to it

Non working code so far

INT CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData)
{
if (uMsg == BFFM_INITIALIZED) {
SendMessage(hwnd, BFFM_SETSELECTION, TRUE, pData);
SendMessage(hwnd, BFFM_SETEXPANDED, TRUE, pData);
}
return 0;
}


Obviously buffer.c_str() is not correct but I've not got that far yet I'm just trying to get it to display my initial folder first

LPSTR BrowseForFolder(HWND hwnd, LPSTR folder)
{
LPSTR ret;
BROWSEINFO br;
ZeroMemory(&br, sizeof(BROWSEINFO));
br.lpfn = BrowseCallbackProc;
br.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
br.hwndOwner = hwnd;
br.lParam = (long)folder;
SHBrowseForFolder(&br);
// LPITEMIDLIST pidl = NULL;
// if ((pidl = SHBrowseForFolder(&br)) != NULL)
// {
// wchar_t buffer[MAX_PATH];
// if (SHGetPathFromIDList(pidl, buffer)) {
// const int size = ::WideCharToMultiByte(CP_UTF8, 0, buffer.c_str(), -1, NULL, 0, 0, NULL);
// std::vector<char> buf(size);
// ::WideCharToMultiByte(CP_UTF8, 0, buffer.c_str(), -1, &buf[0], size, 0, NULL);
// }
// }
return 0;
}

Thanks in advance

Continue reading...
 
Back
Top