1- namespace DevWinUI ;
1+ using System . Runtime . InteropServices . Marshalling ;
2+
3+ namespace DevWinUI ;
24
35public enum TaskbarStates
46{
@@ -8,12 +10,16 @@ public enum TaskbarStates
810 Error = 0x4 ,
911 Paused = 0x8
1012}
13+
1114public static partial class TaskbarHelper
1215{
13- [ ComImport ( ) ]
16+ private static readonly Guid CLSID_TaskbarList = new ( "56fdf344-fd6d-11d0-958a-006097c9a090" ) ;
17+ private static readonly Guid IID_ITaskbarList3 = new ( "ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf" ) ;
18+
1419 [ Guid ( "ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf" ) ]
1520 [ InterfaceType ( ComInterfaceType . InterfaceIsIUnknown ) ]
16- private interface ITaskbarList3
21+ [ GeneratedComInterface ]
22+ internal partial interface ITaskbarList3
1723 {
1824 // ITaskbarList
1925 [ PreserveSig ]
@@ -33,20 +39,37 @@ private interface ITaskbarList3
3339
3440 // ITaskbarList3
3541 [ PreserveSig ]
36- void SetProgressValue ( IntPtr hwnd , UInt64 ullCompleted , UInt64 ullTotal ) ;
42+ void SetProgressValue ( IntPtr hwnd , ulong ullCompleted , ulong ullTotal ) ;
3743 [ PreserveSig ]
3844 void SetProgressState ( IntPtr hwnd , TaskbarStates state ) ;
3945 }
4046
41- [ ComImport ( ) ]
42- [ Guid ( "56fdf344-fd6d-11d0-958a-006097c9a090" ) ]
43- [ ClassInterface ( ClassInterfaceType . None ) ]
44- private class TaskbarInstance
47+ private static readonly ITaskbarList3 taskbarInstance ;
48+ private static readonly bool taskbarSupported = Environment . OSVersion . Version >= new Version ( 6 , 1 ) ;
49+
50+ static TaskbarHelper ( )
4551 {
46- }
52+ if ( taskbarSupported )
53+ {
54+ unsafe
55+ {
56+ void * ppv ;
57+ HRESULT hr = PInvoke . CoCreateInstance (
58+ in CLSID_TaskbarList ,
59+ null ,
60+ Windows . Win32 . System . Com . CLSCTX . CLSCTX_INPROC_SERVER ,
61+ in IID_ITaskbarList3 ,
62+ out ppv ) ;
4763
48- private static ITaskbarList3 taskbarInstance = ( ITaskbarList3 ) new TaskbarInstance ( ) ;
49- private static bool taskbarSupported = Environment . OSVersion . Version >= new Version ( 6 , 1 ) ;
64+ if ( hr . Succeeded && ppv != null )
65+ {
66+ taskbarInstance = ( ITaskbarList3 ) new StrategyBasedComWrappers ( ) . GetOrCreateObjectForComInstance ( ( IntPtr ) ppv , CreateObjectFlags . None ) ;
67+ Marshal . Release ( ( IntPtr ) ppv ) ;
68+ taskbarInstance . HrInit ( ) ;
69+ }
70+ }
71+ }
72+ }
5073
5174 /// <summary>
5275 /// Sets the progress state of a specified window in the taskbar if supported.
0 commit comments