Hi,
One thing to note. When you use FromHandle, the new Icon instance does not
take ownership of the
handle. This means that when the Icon instance is disposed the handle is not
released, resulting in a resource leak.
You need to call DestroyIcon on the original handle, this will of course
invalidate the icon handle referenced by the Icon instance, so what you need
to do is first clone the icon which will create a new Icon instance which
owns the new Icon handle, allowing you to free the original handle.
ico = Icon.FromHandle(hIcon).Clone();
DestroyIcon(hIcon); // You need to pinvoke DestroyIcon.
Hope this helps
--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
"Pieter" <pi****************@hotmail.comwrote in message
news:%2******************@TK2MSFTNGP05.phx.gbl...
Ok thanks!
This worked for me:
Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal
hInst As Integer, ByVal lpszExeFileName As String, ByVal nIconIndex As
Integer) As IntPtr
Dim ico As Icon
Dim hIcon As IntPtr ' handle to the icon once it is extracted
hIcon =
ExtractIcon(Microsoft.VisualBasic.Compatibility.VB 6.GetHInstance.ToInt32,
ConfigParentAssembly.Location, 0)
ico = Icon.FromHandle(hIcon)
m_ConfigIcon = New Icon(ico, New Size(16, 16))
(ConfigParentAssembly is the System.Reflection.assembly which is calling
the dll, and m_ConfigIcon an Icon-variable.)