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#
  4. SHGetFileInfo icon and dispose

SHGetFileInfo icon and dispose

Scheduled Pinned Locked Moved C#
graphicsquestion
3 Posts 2 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.
  • C Offline
    C Offline
    CiNN
    wrote on last edited by
    #1

    I am using a dllimport of SHGetFileInfo to retrieve a file icon, and then add it to an image list. is there something i need to disposse ? this line this.iconsListSmall.Images.Add( FileGetIcon( fi.FullName, true ) ); and this function public static Icon FileGetIcon( string strPath, bool bSmall ) { SHFILEINFO info = new SHFILEINFO( true ); uint cbFileInfo = ( uint )Marshal.SizeOf( info ); SHGFI flags; if ( bSmall ) flags = SHGFI.Icon | SHGFI.SmallIcon | SHGFI.UseFileAttributes; else flags = SHGFI.Icon | SHGFI.LargeIcon | SHGFI.UseFileAttributes; SHGetFileInfo( strPath, 256, out info, cbFileInfo, flags ); return System.Drawing.Icon.FromHandle( info.hIcon ); }

    A 1 Reply Last reply
    0
    • C CiNN

      I am using a dllimport of SHGetFileInfo to retrieve a file icon, and then add it to an image list. is there something i need to disposse ? this line this.iconsListSmall.Images.Add( FileGetIcon( fi.FullName, true ) ); and this function public static Icon FileGetIcon( string strPath, bool bSmall ) { SHFILEINFO info = new SHFILEINFO( true ); uint cbFileInfo = ( uint )Marshal.SizeOf( info ); SHGFI flags; if ( bSmall ) flags = SHGFI.Icon | SHGFI.SmallIcon | SHGFI.UseFileAttributes; else flags = SHGFI.Icon | SHGFI.LargeIcon | SHGFI.UseFileAttributes; SHGetFileInfo( strPath, 256, out info, cbFileInfo, flags ); return System.Drawing.Icon.FromHandle( info.hIcon ); }

      A Offline
      A Offline
      Alex Korchemniy
      wrote on last edited by
      #2

      Well if you search google: "SHGetFileInfo site:msdn.microsoft.com" You will see towards the bottom of the page: If SHGetFileInfo returns an icon handle in the hIcon member of the SHFILEINFO structure pointed to by psfi, you are responsible for freeing it with DestroyIcon when you no longer need it. Alex Korchemniy

      C 1 Reply Last reply
      0
      • A Alex Korchemniy

        Well if you search google: "SHGetFileInfo site:msdn.microsoft.com" You will see towards the bottom of the page: If SHGetFileInfo returns an icon handle in the hIcon member of the SHFILEINFO structure pointed to by psfi, you are responsible for freeing it with DestroyIcon when you no longer need it. Alex Korchemniy

        C Offline
        C Offline
        CiNN
        wrote on last edited by
        #3

        so should i icotmp = FileGetIcon( fi.FullName, true ); this.iconsListSmall.Images.Add( icotmp ); DestroyIcon( icotmp.Handle ); or icotmp.Dispose(); or should i free it in FileGetIcon() before returning the copied icon in a system.drawing.icon FileGetIcon() .. DestroyIcon( info.hIcon ); Icon ico = System.Drawing.Icon.FromHandle( info.hIcon ); return ico;

        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