Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Unhandled exeption when using shell functions

Unhandled exeption when using shell functions

Scheduled Pinned Locked Moved C / C++ / MFC
helplinuxannouncement
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    redeemer
    wrote on last edited by
    #1

    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.

    S J 2 Replies Last reply
    0
    • R redeemer

      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.

      S Offline
      S Offline
      Srini Kella
      wrote on last edited by
      #2

      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();
      }

      1 Reply Last reply
      0
      • R redeemer

        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.

        J Offline
        J Offline
        Joaquin M Lopez Munoz
        wrote on last edited by
        #3

        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

        R 1 Reply Last reply
        0
        • J Joaquin M Lopez Munoz

          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

          R Offline
          R Offline
          redeemer
          wrote on last edited by
          #4

          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

          J 1 Reply Last reply
          0
          • R redeemer

            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

            J Offline
            J Offline
            Joaquin M Lopez Munoz
            wrote on last edited by
            #5

            I might be totally wrong, but I think there's still a mismatch problem: if pBrowse is now an IShellFolder *, you should retrieve it using IID_IShellFolder; if you make it a IEnumIDList *, use IID_IEnumIDList. Just keep types straight. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups