Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
ComInterfaces.cs272 linesDownload Raw Back to WindowsTaskbarJumpList
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System;5using System.Runtime.InteropServices;6using System.Text;7 8namespace Microsoft.PowerShell9{10    internal static class ComInterfaces11    {12        [DllImport("kernel32.dll", SetLastError = false, EntryPoint = "GetStartupInfoW")]13        internal static extern void GetStartupInfo(out StartUpInfo lpStartupInfo);14 15        /// <remarks>16        /// IntPtr is being used for the string fields to make the marshaller faster and17        /// simpler. With IntPtr, all fields are blittable, and since we don't use the18        /// string fields at all, nothing is lost.19        /// </remarks>20        [StructLayout(LayoutKind.Sequential)]21        internal readonly struct StartUpInfo22        {23            public readonly uint cb;24            private readonly IntPtr lpReserved;25            public readonly IntPtr lpDesktop;26            public readonly IntPtr lpTitle;27            public readonly uint dwX;28            public readonly uint dwY;29            public readonly uint dwXSize;30            public readonly uint dwYSize;31            public readonly uint dwXCountChars;32            public readonly uint dwYCountChars;33            public readonly uint dwFillAttribute;34            public readonly uint dwFlags;35            public readonly ushort wShowWindow;36            private readonly ushort cbReserved2;37            private readonly IntPtr lpReserved2;38            public readonly IntPtr hStdInput;39            public readonly IntPtr hStdOutput;40            public readonly IntPtr hStdError;41        }42 43        [ComImport]44        [Guid("00021401-0000-0000-C000-000000000046")]45        [ClassInterface(ClassInterfaceType.None)]46        internal class CShellLink { }47 48        [ComImport]49        [Guid("000214F9-0000-0000-C000-000000000046")]50        [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]51        internal interface IShellLinkW52        {53            void GetPath(54                [Out(), MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFile,55                int cchMaxPath,56                IntPtr pfd,57                uint fFlags);58 59            void GetIDList(out IntPtr ppidl);60 61            void SetIDList(IntPtr pidl);62 63            void GetDescription(64                [Out(), MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFile,65                int cchMaxName);66 67            void SetDescription(68                [MarshalAs(UnmanagedType.LPWStr)] string pszName);69 70            void GetWorkingDirectory(71                [Out(), MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszDir,72                int cchMaxPath73                );74 75            void SetWorkingDirectory(76                [MarshalAs(UnmanagedType.LPWStr)] string pszDir);77 78            void GetArguments(79                [Out(), MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszArgs,80                int cchMaxPath);81 82            void SetArguments(83                [MarshalAs(UnmanagedType.LPWStr)] string pszArgs);84 85            void GetHotKey(out short wHotKey);86 87            void SetHotKey(short wHotKey);88 89            void GetShowCmd(out uint iShowCmd);90 91            void SetShowCmd(uint iShowCmd);92 93            void GetIconLocation(94                [Out(), MarshalAs(UnmanagedType.LPWStr)] out StringBuilder pszIconPath,95                int cchIconPath,96                out int iIcon);97 98            void SetIconLocation(99                [MarshalAs(UnmanagedType.LPWStr)] string pszIconPath,100                int iIcon);101 102            void SetRelativePath(103                [MarshalAs(UnmanagedType.LPWStr)] string pszPathRel,104                uint dwReserved);105 106            void Resolve(IntPtr hwnd, uint fFlags);107 108            void SetPath(109                [MarshalAs(UnmanagedType.LPWStr)] string pszFile);110        }111 112        /// <summary>113        /// A property store.114        /// </summary>115        [ComImport]116        [Guid("886D8EEB-8CF2-4446-8D02-CDBA1DBDCF99")]117        [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]118        internal interface IPropertyStore119        {120            /// <summary>121            /// Gets the number of properties contained in the property store.122            /// </summary>123            /// <param name="propertyCount"></param>124            /// <returns></returns>125            [PreserveSig]126            HResult GetCount([Out] out uint propertyCount);127 128            /// <summary>129            /// Get a property key located at a specific index.130            /// </summary>131            /// <param name="propertyIndex"></param>132            /// <param name="key"></param>133            /// <returns></returns>134            [PreserveSig]135            HResult GetAt([In] uint propertyIndex, out PropertyKey key);136 137            /// <summary>138            /// Gets the value of a property from the store.139            /// </summary>140            /// <param name="key"></param>141            /// <param name="pv"></param>142            /// <returns></returns>143            [PreserveSig]144            HResult GetValue([In] in PropertyKey key, [Out] PropVariant pv);145 146            /// <summary>147            /// Sets the value of a property in the store.148            /// </summary>149            /// <param name="key"></param>150            /// <param name="pv"></param>151            /// <returns></returns>152            [PreserveSig]153            HResult SetValue([In] in PropertyKey key, [In] PropVariant pv);154 155            /// <summary>156            /// Commits the changes.157            /// </summary>158            /// <returns></returns>159            [PreserveSig]160            HResult Commit();161        }162 163        [ComImport]164        [Guid("6332DEBF-87B5-4670-90C0-5E57B408A49E")]165        [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]166        internal interface ICustomDestinationList167        {168            void SetAppID(169                [MarshalAs(UnmanagedType.LPWStr)] string pszAppID);170 171            [PreserveSig]172            HResult BeginList(173                out uint cMaxSlots,174                ref Guid riid,175                [Out(), MarshalAs(UnmanagedType.Interface)] out object ppvObject);176 177            [PreserveSig]178            HResult AppendCategory(179                [MarshalAs(UnmanagedType.LPWStr)] string pszCategory,180                [MarshalAs(UnmanagedType.Interface)] IObjectArray poa);181 182            void AppendKnownCategory(183                [MarshalAs(UnmanagedType.I4)] KnownDestinationCategory category);184 185            [PreserveSig]186            HResult AddUserTasks(187                [MarshalAs(UnmanagedType.Interface)] IObjectArray poa);188 189            void CommitList();190 191            void GetRemovedDestinations(192                ref Guid riid,193                [Out(), MarshalAs(UnmanagedType.Interface)] out object ppvObject);194 195            void DeleteList(196                [MarshalAs(UnmanagedType.LPWStr)] string pszAppID);197 198            void AbortList();199        }200 201        internal enum KnownDestinationCategory202        {203            Frequent = 1,204            Recent205        }206 207        [ComImport]208        [Guid("92CA9DCD-5622-4BBA-A805-5E9F541BD8C9")]209        [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]210        internal interface IObjectArray211        {212            void GetCount(out uint cObjects);213 214            void GetAt(215                uint iIndex,216                ref Guid riid,217                [Out(), MarshalAs(UnmanagedType.Interface)] out object ppvObject);218        }219 220        [ComImport]221        [Guid("5632B1A4-E38A-400A-928A-D4CD63230295")]222        [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]223        internal interface IObjectCollection224        {225            // IObjectArray226            void GetCount(out uint cObjects);227 228            void GetAt(229                uint iIndex,230                ref Guid riid,231                [Out(), MarshalAs(UnmanagedType.Interface)] out object ppvObject);232 233            // IObjectCollection234            void AddObject(235                [MarshalAs(UnmanagedType.Interface)] object pvObject);236 237            void AddFromArray(238                [MarshalAs(UnmanagedType.Interface)] IObjectArray poaSource);239 240            void RemoveObject(uint uiIndex);241 242            void Clear();243        }244 245        [ComImport]246        [Guid("45e2b4ae-b1c3-11d0-b92f-00a0c90312e1"),247        InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]248        internal interface IShellLinkDataListW249        {250            [PreserveSig]251            int AddDataBlock(IntPtr pDataBlock);252 253            [PreserveSig]254            int CopyDataBlock(uint dwSig, out IntPtr ppDataBlock);255 256            [PreserveSig]257            int RemoveDataBlock(uint dwSig);258 259            void GetFlags(out uint pdwFlags);260 261            void SetFlags(uint dwFlags);262        }263 264        [DllImport("ole32.Dll")]265        internal static extern HResult CoCreateInstance(ref Guid clsid,266           [MarshalAs(UnmanagedType.IUnknown)] object inner,267           uint context,268           ref Guid uuid,269           [MarshalAs(UnmanagedType.IUnknown)] out object rReturnedComObject);270    }271}272