コード例 #1
0
ファイル: RealtimeApiSet.cs プロジェクト: zhuxb711/Vanara
        public static ulong[] QueryIdleProcessorCycleTimeEx(ushort Group)
        {
            var ct = new ulong[Environment.ProcessorCount];

            var sz = (uint)ct.Length * sizeof(ulong);

            if (!QueryIdleProcessorCycleTimeEx(Group, ref sz, ct))
            {
                Win32Error.ThrowLastError();
            }
            return(ct);
        }
コード例 #2
0
ファイル: WinGdi.cs プロジェクト: zuozhu315/Vanara
        public static SafeHGlobalHandle GetObject(HGDIOBJ hgdiobj)
        {
            var sz = GetObject(hgdiobj, 0, IntPtr.Zero);

            var ptr = new SafeHGlobalHandle(sz);
            var ret = GetObject(hgdiobj, ptr.Size, (IntPtr)ptr);

            if (ret == 0)
            {
                Win32Error.ThrowLastError();
            }
            return(ptr);
        }
コード例 #3
0
ファイル: GdiObjExtensions.cs プロジェクト: zhuxb711/Vanara
        /// <summary>Converts the generic GDI object handle to a specific handle.</summary>
        /// <typeparam name="T">The handle type to which to convert.</typeparam>
        /// <param name="hObj">The generic GDI object handle.</param>
        /// <returns>The converted handle of type <typeparamref name="T"/>.</returns>
        /// <exception cref="ArgumentException">The conversion type specified is not valid for the supplied GDI object.</exception>
        public static T ConvertTo <T>(this IGraphicsObjectHandle hObj) where T : IGraphicsObjectHandle
        {
            var ot = GetObjectType(hObj.DangerousGetHandle());

            if (ot == 0)
            {
                Win32Error.ThrowLastError();
            }
            if (!CorrespondingTypeAttribute.CanGet(ot, typeof(T)))
            {
                throw new ArgumentException($"The conversion type specified is not valid for the supplied GDI object.");
            }
            return((T)(object)hObj.DangerousGetHandle());
        }
コード例 #4
0
ファイル: PSID.cs プロジェクト: raystyle/Vanara
            /// <summary>Creates a SID for predefined aliases.</summary>
            /// <param name="WellKnownSidType">Member of the WELL_KNOWN_SID_TYPE enumeration that specifies what the SID will identify.</param>
            /// <param name="DomainSid">
            /// A pointer to a SID that identifies the domain to use when creating the SID. Pass <c>PSID.NULL</c> to use the local computer.
            /// </param>
            /// <returns>A <see cref="SafePSID"/> instance.</returns>
            public static SafePSID CreateWellKnown(WELL_KNOWN_SID_TYPE sidType, PSID domainSid = default)
            {
                var sz = 0U;

                CreateWellKnownSid(sidType, domainSid, Null, ref sz);
                if (sz == 0)
                {
                    Win32Error.ThrowLastError();
                }
                var newSid = new SafePSID((int)sz);

                if (!CreateWellKnownSid(sidType, domainSid, newSid, ref sz))
                {
                    Win32Error.ThrowLastError();
                }
                return(newSid);
            }
コード例 #5
0
 public static void RegisterWaitChainCOMCallback()
 {
     using (var hLib = Kernel32.LoadLibrary(Lib.Ole32))
     {
         if (hLib.IsInvalid)
         {
             Win32Error.ThrowLastError();
         }
         var p1 = Kernel32.GetProcAddress(hLib, "CoGetCallState");
         if (p1 == IntPtr.Zero)
         {
             Win32Error.ThrowLastError();
         }
         var p2 = Kernel32.GetProcAddress(hLib, "CoGetActivationState");
         if (p2 == IntPtr.Zero)
         {
             Win32Error.ThrowLastError();
         }
         RegisterWaitChainCOMCallback(p1, p2);
     }
 }