简体   繁体   中英

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

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);
}

您应该使用Windows API代码包 ,它可以为您处理所有这一切。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM