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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. IShellFolder pointers, how to copy them safely... (COM)

IShellFolder pointers, how to copy them safely... (COM)

Scheduled Pinned Locked Moved C / C++ / MFC
questioncomhelptutorialannouncement
2 Posts 2 Posters 1 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.
  • H Offline
    H Offline
    Henrik
    wrote on last edited by
    #1

    Hello, I got a small problem (or rather question)... global: ------- SHGetDesktopFolder(&m_pShellFolder) // the nFolde value can be diffrent,, also CSIDL_DESKTOP.. depends what button user press SHGetSpecialFolderLocation(NULL, nFolder, &m_ppidl); func: ----- IShellFolder* pFolder; IEnumIDList* pEnumIds; if (::GetSize(m_ppidl) == 2) { // if the user is in the root path (desktop folder) do this... m_pShellFolder->EnumObjects(NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &pEnumIds); pFolder = m_pShellFolder; pFolder->AddRef(); } else { // if the user is in a folder that is BELOW the desktop do this.... the pidl is // a full path list in both cases (ie it holds the desktop id as first entry) m_pShellFolder->BindToObject(m_ppidl, NULL, IID_IShellFolder, (LPVOID *)&pFolder); pFolder->EnumObjects(NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &pEnumIds); } // after this the enumaration process starts and I use pFolder->GetAttributesOf // and pFolder->GetDisplayNameOf... . . . pFolder->Release(); I got this code. Anyway as you might notice I do pFolder = m_pShellFolder. My question is, can this be dangerous when I do pFolder->Release(); since both pointers point at the same memloc...? (SIDENOTE) If GetSize returns 2 I assume that the pidl tells you that your in the root (DESKTOP) else your in a subfolder to the root , my code is supposed to add to the pidl list as the user goes down in the folder structure.. (THE QUESTOIN :)) So my question is, as I said, is it safe to do pFolder = m_pShellFolder; and then release pFolder later with pFolder->Release()?.. Will this destroy m_pShellFolder (or make it unusable) (it worked tough i dunno if its safe?)? What im trying to accomplish is basicly to get a copy of the m_pShellFolder structure(the one it points at) to a new IShellFolder object.. I hope someone understood this :) Cheers, Henrik

    M 1 Reply Last reply
    0
    • H Henrik

      Hello, I got a small problem (or rather question)... global: ------- SHGetDesktopFolder(&m_pShellFolder) // the nFolde value can be diffrent,, also CSIDL_DESKTOP.. depends what button user press SHGetSpecialFolderLocation(NULL, nFolder, &m_ppidl); func: ----- IShellFolder* pFolder; IEnumIDList* pEnumIds; if (::GetSize(m_ppidl) == 2) { // if the user is in the root path (desktop folder) do this... m_pShellFolder->EnumObjects(NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &pEnumIds); pFolder = m_pShellFolder; pFolder->AddRef(); } else { // if the user is in a folder that is BELOW the desktop do this.... the pidl is // a full path list in both cases (ie it holds the desktop id as first entry) m_pShellFolder->BindToObject(m_ppidl, NULL, IID_IShellFolder, (LPVOID *)&pFolder); pFolder->EnumObjects(NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &pEnumIds); } // after this the enumaration process starts and I use pFolder->GetAttributesOf // and pFolder->GetDisplayNameOf... . . . pFolder->Release(); I got this code. Anyway as you might notice I do pFolder = m_pShellFolder. My question is, can this be dangerous when I do pFolder->Release(); since both pointers point at the same memloc...? (SIDENOTE) If GetSize returns 2 I assume that the pidl tells you that your in the root (DESKTOP) else your in a subfolder to the root , my code is supposed to add to the pidl list as the user goes down in the folder structure.. (THE QUESTOIN :)) So my question is, as I said, is it safe to do pFolder = m_pShellFolder; and then release pFolder later with pFolder->Release()?.. Will this destroy m_pShellFolder (or make it unusable) (it worked tough i dunno if its safe?)? What im trying to accomplish is basicly to get a copy of the m_pShellFolder structure(the one it points at) to a new IShellFolder object.. I hope someone understood this :) Cheers, Henrik

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      You're doing exactly what you should be doing. Calling AddRef() tells the underlying COM object that there is a new reference to it. Just remember to call Release() through both pointers to properly clean up. --Mike-- http://home.inreach.com/mdunn/ The Signature, back by popular demand: Buffy. Pajamas.

      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