Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to call DestroyIcon if I made it with LoadIconWithScaleDown?

Tags:

windows

winapi

I'm creating icons in my app using LoadIconWithScaleDown(). I also fall back to CreateIconFromResourceEx() if the preferred function is not available.

The documentation for DestroyIcon() states:

It is only necessary to call DestroyIcon for icons and cursors created with the following functions: CreateIconFromResourceEx (if called without the LR_SHARED flag), CreateIconIndirect, and CopyIcon. Do not use this function to destroy a shared icon. A shared icon is valid as long as the module from which it was loaded remains in memory. The following functions obtain a shared icon.

  • LoadIcon
  • LoadImage (if you use the LR_SHARED flag)
  • CopyImage (if you use the LR_COPYRETURNORG flag and the hImage parameter is a shared icon)
  • CreateIconFromResource
  • CreateIconFromResourceEx (if you use the LR_SHARED flag)

Note: I'm not passing LR_SHARED to CreateIconFromResourceEx(); perhaps I should.

What I would like to know is, do I need to call DestroyIcon() for the icons made with LoadIconWithScaleDown()?

like image 636
David Heffernan Avatar asked Mar 11 '11 17:03

David Heffernan


1 Answers

I would say yes, since the HICON you're getting back does not seem to be shared according to the documentation. Windows obviously does not want you to destroy icons whose handles are shared, but that isn't the case here, and if you fallback to another function that takes LR_SHARED but you're not passing the flag, then that means your process owns the icon handle and you should destroy it when you're done using it.

like image 129
kprobst Avatar answered Oct 06 '22 00:10

kprobst