Why does SetOverlayIcon throw an 'Invalid cursor handle' COMException occasionally?

1

In my C# Winforms application I'm using the ITaskbarList3::SetOverlayIcon interface to set status overlays on the application's taskbar button (under Windows 7). This all seems to work fine for me, with the icons being shown and removed correctly.

From the form load event, one of my functions makes the call

SetOverlayIcon(parentForm.Handle, IntPtr.Zero, String.Empty)

(where parentForm is the form which the load event has fired for) which very occasionally (on other people's machines) throws the following exception:

System.Runtime.InteropServices.COMException (0x8007057A): Invalid cursor handle. (Exception from HRESULT: 0x8007057A)
   at MyNamespace.TaskbarNotify.ITaskbarList3.SetOverlayIcon(IntPtr hwnd, IntPtr hIcon, String pszDescription)

Out of a user base of a thousand or so users (of various Windows versions) this has been reported around 100 times over a couple of months.

I know that IntPtr.Zero isn't a valid cursor handle, but MSDN says that NULL is a valid value to pass for hIcon. Any suggestions as to what Windows is telling me?

I'm using .NET 2 in case this makes a difference.

Here is the definition I'm using within my application for ITaskbarList3:

[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("EA1AFB91-9E28-4B86-90E9-9E9F8A5EEFAF")]
public interface ITaskbarList3
{
    void HrInit();
    void AddTab(IntPtr hwnd);
    void DeleteTab(IntPtr hwnd);
    void ActivateTab(IntPtr hwnd);
    void SetActivateAlt(IntPtr hwnd);
    void MarkFullscreenWindow(IntPtr hwnd, bool fFullscreen);
    void SetProgressValue(IntPtr hwnd, ulong ullCompleted, ulong ullTotal);
    void SetProgressState(IntPtr hwnd, TBPFLAG tbpFlags);
    void RegisterTab(IntPtr hwndTab, IntPtr hwndMDI);
    void UnregisterTab(IntPtr hwndTab);
    void SetTabOrder(IntPtr hwndTab, int hwndInsertBefore);
    void SetTabActive(IntPtr hwndTab, int hwndMDI, TBATFLAG tbatFlags);
    void ThumbBarAddButtons(IntPtr hwnd, uint cButtons, THUMBBUTTON[] pButton);
    void ThumbBarUpdateButtons(IntPtr hwnd, uint cButtons, THUMBBUTTON[] pButton);
    void ThumbBarSetImageList(IntPtr hwnd, IntPtr himl);
    void SetOverlayIcon(IntPtr hwnd, IntPtr hIcon, [MarshalAs(UnmanagedType.LPWStr)] string pszDescription);
    void SetThumbnailTooltip(IntPtr hwnd, [MarshalAs(UnmanagedType.LPWStr)] string pszTip);
    void SetThumbnailClip(IntPtr hwnd, NativeMethods.RECT prcClip);
}
c#
.net
windows-7
asked on Stack Overflow Jul 18, 2010 by ribbons • edited Aug 22, 2012 by ribbons

1 Answer

0

You should use the Windows API Code Pack, which handles all of this for you.

answered on Stack Overflow Jul 18, 2010 by SLaks

User contributions licensed under CC BY-SA 3.0