C++ Programming
05-05-2009, 01:40 PM
I am using the following code snippet. This is the code which gets executed when I click on a Browse button.
Function call - BrowseDialog( GetParent()->GetSafeHwnd(), csTitle, lpszBuf );
Function Definition -
BrowseDialog(HWND hWndParent,CString pszPath,LPSTR csDialogTitle)
{
_tcsncpy(szInitialDir, pszPath, _MAX_PATH-1);
int nLen = _tcslen(szInitialDir);
if (szInitialDir[nLen-1] == '\\')
szInitialDir[nLen-1] = '\0';
BROWSEINFO bi;
memset((LPVOID)&bi, 0, sizeof(bi));
TCHAR szDisplayName[_MAX_PATH];
szDisplayName[0] = '\0';
bi.hwndOwner = hWndParent;
bi.pidlRoot = NULL;
bi.pszDisplayName = (LPSTR)szDisplayName;
bi.lpszTitle = csDialogTitle;
bi.lpfn = RecipeBrowseCallbackProc;
bi.ulFlags = BIF_RETURNONLYFSDIRS|BIF_EDITBOX|BIF_VALIDATE|BIF_USENEWUI|BIF_STATUSTEXT;
LPITEMIDLIST pIIL = ::SHBrowseForFolder(&bi);
BOOL bRet = ::SHGetPathFromIDList(pIIL, (char*)&szSelectedDir);
}
Some times I am getting crash when clicking on browse button and sometimes after opening the browse button and selecting another directory..
Can I know what is the fault in above code
Function call - BrowseDialog( GetParent()->GetSafeHwnd(), csTitle, lpszBuf );
Function Definition -
BrowseDialog(HWND hWndParent,CString pszPath,LPSTR csDialogTitle)
{
_tcsncpy(szInitialDir, pszPath, _MAX_PATH-1);
int nLen = _tcslen(szInitialDir);
if (szInitialDir[nLen-1] == '\\')
szInitialDir[nLen-1] = '\0';
BROWSEINFO bi;
memset((LPVOID)&bi, 0, sizeof(bi));
TCHAR szDisplayName[_MAX_PATH];
szDisplayName[0] = '\0';
bi.hwndOwner = hWndParent;
bi.pidlRoot = NULL;
bi.pszDisplayName = (LPSTR)szDisplayName;
bi.lpszTitle = csDialogTitle;
bi.lpfn = RecipeBrowseCallbackProc;
bi.ulFlags = BIF_RETURNONLYFSDIRS|BIF_EDITBOX|BIF_VALIDATE|BIF_USENEWUI|BIF_STATUSTEXT;
LPITEMIDLIST pIIL = ::SHBrowseForFolder(&bi);
BOOL bRet = ::SHGetPathFromIDList(pIIL, (char*)&szSelectedDir);
}
Some times I am getting crash when clicking on browse button and sometimes after opening the browse button and selecting another directory..
Can I know what is the fault in above code