Win32.DestroyIcon vs. Icon.Dispose

I have this line of code:

System.Drawing.Icon icon = System.Drawing.Icon.FromHandle(shinfo.hIcon);

A few lines later, after using the icon, I have a line:

Win32.DestroyIcon(shinfo.hIcon);

However, when running static analysis in my code, it says that there is potential for Resource_Leak from the icon. I am wondering if this will make a difference if I call the dispose method:

icon.Dispose();

not Win32.DestroyIcon (), which is being used right now. Is there any difference between the two? I just support this code, so I'm not sure if the original developer used the special Winnet.DestroyIcon.

+5
source share
2 answers

Static analysis starts because you are not deleting the "IDisposable resource".

icon.Dispose(). () DestroyIcon , API.

Win32.DestroyIcon , IntPtr, Icon, .

+8

. (, , , ), .

( MSDN), , "DestroyIcon", . .

API:

[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = CharSet.Auto)]
extern static bool DestroyIcon(IntPtr handle);

, :

IntPtr iconHandle = dynamicBitmap.GetHicon();
Icon tempManagedRes = Icon.FromHandle(iconHandle);
this.Icon = (Icon)tempManagedRes.Clone();
tempManagedRes.Dispose();
DestroyIcon(iconHandle);

: Icon.FromHandle: DestroyIcon?

+1

All Articles