Unhandled exeption when using shell functions
-
I'm getting an "Unhandled exeption" when running this function. I get it when it comes to the pBrowse->Next line. I have already tested if pBrowse is null and it isn't, neihter is pIdl. Here's the code
void OnOpenFolder()
{
BROWSEINFO bi = {0};
IShellFolder *pSf;
LPMALLOC pMalloc;
DWORD pActual = 0;bi.hwndOwner = ghWnd; bi.pidlRoot = NULL; bi.lpszTitle = "Locate MP3 Folder"; bi.ulFlags = BIF\_DONTGOBELOWDOMAIN; bi.lpfn = NULL; SHGetDesktopFolder (&pSf); if (pSf) { LPITEMIDLIST pIdl; pIdl = SHBrowseForFolder(&bi); if (pIdl) { IEnumIDList \*pBrowse; SHGetMalloc(&pMalloc); pSf->BindToObject(pIdl, NULL, IID\_IShellFolder, (LPVOID\*)&pBrowse); pBrowse->AddRef(); if (pBrowse) { while (pBrowse->Next(1, &pIdl, &pActual) == S\_OK) { LVITEM Lvi = {0}; char szPath\[MAX\_PATH+1\]; SHGetPathFromIDList(pIdl, szPath); Lvi.mask = LVIF\_TEXT; Lvi.pszText = szPath; Lvi.iItem = SendMessage(DlgItems\[7\], LVM\_GETITEMCOUNT, 0, 0); ListView\_InsertItem(DlgItems\[7\], &Lvi); } } pBrowse->Release(); } pMalloc->Free(pIdl); pMalloc->Release(); } pSf->Release();
}
ghWnd is the hanlde to my window (yes, it's valid) DlgItems[7] is the handle to a listview control, also valid. Here's the exact error: "Unhandled exeption in app.exe (SHELL32.DLL): 0xC0000005: Access Violation." Any help greatly appreciated Thanks.
-
I'm getting an "Unhandled exeption" when running this function. I get it when it comes to the pBrowse->Next line. I have already tested if pBrowse is null and it isn't, neihter is pIdl. Here's the code
void OnOpenFolder()
{
BROWSEINFO bi = {0};
IShellFolder *pSf;
LPMALLOC pMalloc;
DWORD pActual = 0;bi.hwndOwner = ghWnd; bi.pidlRoot = NULL; bi.lpszTitle = "Locate MP3 Folder"; bi.ulFlags = BIF\_DONTGOBELOWDOMAIN; bi.lpfn = NULL; SHGetDesktopFolder (&pSf); if (pSf) { LPITEMIDLIST pIdl; pIdl = SHBrowseForFolder(&bi); if (pIdl) { IEnumIDList \*pBrowse; SHGetMalloc(&pMalloc); pSf->BindToObject(pIdl, NULL, IID\_IShellFolder, (LPVOID\*)&pBrowse); pBrowse->AddRef(); if (pBrowse) { while (pBrowse->Next(1, &pIdl, &pActual) == S\_OK) { LVITEM Lvi = {0}; char szPath\[MAX\_PATH+1\]; SHGetPathFromIDList(pIdl, szPath); Lvi.mask = LVIF\_TEXT; Lvi.pszText = szPath; Lvi.iItem = SendMessage(DlgItems\[7\], LVM\_GETITEMCOUNT, 0, 0); ListView\_InsertItem(DlgItems\[7\], &Lvi); } } pBrowse->Release(); } pMalloc->Free(pIdl); pMalloc->Release(); } pSf->Release();
}
ghWnd is the hanlde to my window (yes, it's valid) DlgItems[7] is the handle to a listview control, also valid. Here's the exact error: "Unhandled exeption in app.exe (SHELL32.DLL): 0xC0000005: Access Violation." Any help greatly appreciated Thanks.
Just a clue: There are some mistakes in your code. For example you have:
if(pBrowe)
{
...
...
}
pBrowse->Release();Where as it should be:
if(pBrowse)
{
...
pBrowse->Release();
} -
I'm getting an "Unhandled exeption" when running this function. I get it when it comes to the pBrowse->Next line. I have already tested if pBrowse is null and it isn't, neihter is pIdl. Here's the code
void OnOpenFolder()
{
BROWSEINFO bi = {0};
IShellFolder *pSf;
LPMALLOC pMalloc;
DWORD pActual = 0;bi.hwndOwner = ghWnd; bi.pidlRoot = NULL; bi.lpszTitle = "Locate MP3 Folder"; bi.ulFlags = BIF\_DONTGOBELOWDOMAIN; bi.lpfn = NULL; SHGetDesktopFolder (&pSf); if (pSf) { LPITEMIDLIST pIdl; pIdl = SHBrowseForFolder(&bi); if (pIdl) { IEnumIDList \*pBrowse; SHGetMalloc(&pMalloc); pSf->BindToObject(pIdl, NULL, IID\_IShellFolder, (LPVOID\*)&pBrowse); pBrowse->AddRef(); if (pBrowse) { while (pBrowse->Next(1, &pIdl, &pActual) == S\_OK) { LVITEM Lvi = {0}; char szPath\[MAX\_PATH+1\]; SHGetPathFromIDList(pIdl, szPath); Lvi.mask = LVIF\_TEXT; Lvi.pszText = szPath; Lvi.iItem = SendMessage(DlgItems\[7\], LVM\_GETITEMCOUNT, 0, 0); ListView\_InsertItem(DlgItems\[7\], &Lvi); } } pBrowse->Release(); } pMalloc->Free(pIdl); pMalloc->Release(); } pSf->Release();
}
ghWnd is the hanlde to my window (yes, it's valid) DlgItems[7] is the handle to a listview control, also valid. Here's the exact error: "Unhandled exeption in app.exe (SHELL32.DLL): 0xC0000005: Access Violation." Any help greatly appreciated Thanks.
pSf->BindToObject(pIdl, NULL, IID_IShellFolder, (LPVOID*)&pBrowse);
Shouldn't you be asking for a
IID_IEnumIDList
? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo -
pSf->BindToObject(pIdl, NULL, IID_IShellFolder, (LPVOID*)&pBrowse);
Shouldn't you be asking for a
IID_IEnumIDList
? Joaquín M López Muñoz Telefónica, Investigación y DesarrolloI'm not quite sure, but here's my code now, with the IID_IShellFolder parameter in BindToObjet it works, but with the IID_IEnumIDList i get that unhandled exception.
void OnOpenFolder()
{
BROWSEINFO bi = {0};
IShellFolder *pSf;
LPMALLOC pMalloc;
LPENUMIDLIST pFolder = NULL;
DWORD pActual = 0;
LVITEM Lvi = {0};
char szFolderPath[MAX_PATH+1];bi.hwndOwner = ghWnd; bi.pidlRoot = NULL; bi.lpszTitle = "Locate MP3 Folder"; bi.ulFlags = BIF\_DONTGOBELOWDOMAIN; bi.lpfn = NULL; SHGetDesktopFolder (&pSf); if (pSf) { LPITEMIDLIST pIdl; pIdl = SHBrowseForFolder(&bi); SHGetPathFromIDList(pIdl, szFolderPath); Lvi.mask = LVIF\_TEXT; Lvi.pszText = szFolderPath; Lvi.iItem = SendMessage(DlgItems\[7\], LVM\_GETITEMCOUNT, 0, 0); ListView\_InsertItem(DlgItems\[7\], &Lvi); if (pIdl) { IShellFolder \*pBrowse = NULL; SHGetMalloc(&pMalloc); pSf->BindToObject(pIdl, NULL, IID\_IEnumIDList, (LPVOID\*)&pBrowse); pSf->Release(); pBrowse->EnumObjects(NULL, SHCONTF\_FOLDERS | SHCONTF\_NONFOLDERS | SHCONTF\_INCLUDEHIDDEN, &pFolder); if (pBrowse) { while (pFolder->Next(1, &pIdl, &pActual) == S\_OK) { SHGetPathFromIDList(pIdl, szFolderPath); Lvi.pszText = szFolderPath; Lvi.iItem = SendMessage(DlgItems\[7\], LVM\_GETITEMCOUNT, 0, 0); ListView\_InsertItem(DlgItems\[7\], &Lvi); } } pBrowse->Release(); } pMalloc->Free(pIdl); pMalloc->Release(); } pSf->Release();
}
Although there still is a problem. The SHGetPathFromIDList(pIdl, szFolderPath); sets the szFolderPath to \ Thanks
-
I'm not quite sure, but here's my code now, with the IID_IShellFolder parameter in BindToObjet it works, but with the IID_IEnumIDList i get that unhandled exception.
void OnOpenFolder()
{
BROWSEINFO bi = {0};
IShellFolder *pSf;
LPMALLOC pMalloc;
LPENUMIDLIST pFolder = NULL;
DWORD pActual = 0;
LVITEM Lvi = {0};
char szFolderPath[MAX_PATH+1];bi.hwndOwner = ghWnd; bi.pidlRoot = NULL; bi.lpszTitle = "Locate MP3 Folder"; bi.ulFlags = BIF\_DONTGOBELOWDOMAIN; bi.lpfn = NULL; SHGetDesktopFolder (&pSf); if (pSf) { LPITEMIDLIST pIdl; pIdl = SHBrowseForFolder(&bi); SHGetPathFromIDList(pIdl, szFolderPath); Lvi.mask = LVIF\_TEXT; Lvi.pszText = szFolderPath; Lvi.iItem = SendMessage(DlgItems\[7\], LVM\_GETITEMCOUNT, 0, 0); ListView\_InsertItem(DlgItems\[7\], &Lvi); if (pIdl) { IShellFolder \*pBrowse = NULL; SHGetMalloc(&pMalloc); pSf->BindToObject(pIdl, NULL, IID\_IEnumIDList, (LPVOID\*)&pBrowse); pSf->Release(); pBrowse->EnumObjects(NULL, SHCONTF\_FOLDERS | SHCONTF\_NONFOLDERS | SHCONTF\_INCLUDEHIDDEN, &pFolder); if (pBrowse) { while (pFolder->Next(1, &pIdl, &pActual) == S\_OK) { SHGetPathFromIDList(pIdl, szFolderPath); Lvi.pszText = szFolderPath; Lvi.iItem = SendMessage(DlgItems\[7\], LVM\_GETITEMCOUNT, 0, 0); ListView\_InsertItem(DlgItems\[7\], &Lvi); } } pBrowse->Release(); } pMalloc->Free(pIdl); pMalloc->Release(); } pSf->Release();
}
Although there still is a problem. The SHGetPathFromIDList(pIdl, szFolderPath); sets the szFolderPath to \ Thanks
I might be totally wrong, but I think there's still a mismatch problem: if
pBrowse
is now anIShellFolder *
, you should retrieve it usingIID_IShellFolder
; if you make it aIEnumIDList *
, useIID_IEnumIDList
. Just keep types straight. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo