예제 #1
0
        private static string GetSchemeName(SafeHeapHandle <Guid> guid)
        {
            IntPtr schemeNameGuidPtr = guid.DangerousGetHandle();

            int buffSize = 0;

            if (PowrProf.PowerReadFriendlyName(IntPtr.Zero, schemeNameGuidPtr, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, ref buffSize) != ReturnCodes.ERROR_SUCCESS)
            {
                return(string.Empty);
            }

            if (buffSize == 0)
            {
                return(string.Empty);
            }

            IntPtr schemeNamePtr = Marshal.AllocHGlobal(buffSize);

            if (PowrProf.PowerReadFriendlyName(IntPtr.Zero, schemeNameGuidPtr, IntPtr.Zero, IntPtr.Zero, schemeNamePtr, ref buffSize) != ReturnCodes.ERROR_SUCCESS)
            {
                Marshal.FreeHGlobal(schemeNamePtr);
                return(string.Empty);
            }

            string schemeName = Marshal.PtrToStringUni(schemeNamePtr);

            Marshal.FreeHGlobal(schemeNamePtr);
            return(schemeName);
        }
예제 #2
0
            public LargeBuffer(int size, int firstSegmentGlobalIndex)
            {
                FirstSegmentGlobalIndex = firstSegmentGlobalIndex;

                _bufferHandle  = new SafeHeapHandle(size);
                _bufferPointer = (byte *)_bufferHandle.DangerousGetHandle();
            }
예제 #3
0
 /// <summary>
 /// Get the handle to the buffer. Prefer using SafeHandle instead of IntPtr for interop (there is an implicit converter).
 /// </summary>
 public override IntPtr DangerousGetHandle()
 {
     return(_handle?.DangerousGetHandle() ?? IntPtr.Zero);
 }