Hello, I'm trying to get a Browse Directory dialog to update a text box with the path selected. I had it working fine in Unicode build but now using TCHAR - I see the variable contains the correct path, but the textbox only gets updated with a single weird character. Any help would be great, thanks.
setting the text checking WM_COMMAND vars-
Code:
SetWindowText(textBox2,&buttonPush(hWnd));
browse function when Browse button is pressed -
Code:
TCHAR& buttonPush(HWND hWnd) {
BROWSEINFO bi;
TCHAR szDir[MAX_PATH];
LPITEMIDLIST pidl;
LPMALLOC pMalloc;
if (SUCCEEDED(SHGetMalloc(&pMalloc)))
{
ZeroMemory(&bi,sizeof(bi));
bi.hwndOwner = hWnd;
bi.pszDisplayName = 0;
bi.pidlRoot = 0;
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT | BIF_USENEWUI | BIF_NONEWFOLDERBUTTON;
bi.pszDisplayName = szDir; // Address of a buffer to receive the display name of the folder selected by the user
bi.lpszTitle = _T("Select a folder "); // Title of the dialog
bi.lpfn = BrowseCallbackProc;
pidl = SHBrowseForFolder(&bi);
if (pidl)
{
// Folder selected in dialog
TCHAR szReturnedDir[_MAX_PATH];
BOOL bRet = ::SHGetPathFromIDList(pidl, szReturnedDir);
if(bRet) return *szReturnedDir; // szReturnedDir holds the correct selected dir
pMalloc->Free(pidl);
}
pMalloc->Release();
}
return *szDir;
}