DWM_TIMING_INFO (Structures)
Last changed: RadarNyan@gmail.com-


C# Definition:

    /// <summary>
    /// Used by DWM_TIMING_INFO
    /// </summary>
    public struct UNSIGNED_RATIO
        public UInt32 uiNumerator;
        public UInt32 uiDenominator;

    /// <summary>
    /// Specifies Desktop Window Manager (DWM) composition timing information.
    /// Used by the DwmGetCompositionTimingInfo function.
    /// </summary>
    /// <remark>
    /// It's necessary to get rid of padding (by setting Pack = 1)
    /// The member sbSize must be set to (uint)Marshal.SizeOf(typeof(DWM_TIMING_INFO))
    /// before calling DwmGetCompositionTimingInfo function else it won't work.
    /// </remark>
    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    public struct DWM_TIMING_INFO
        public UInt32 cbSize;
        public UNSIGNED_RATIO rateRefresh;
        public UInt64 qpcRefreshPeriod;
        public UNSIGNED_RATIO rateCompose;
        public UInt64 qpcVBlank;
        public UInt64 cRefresh;
        public UInt32 cDXRefresh;
        public UInt64 qpcCompose;
        public UInt64 cFrame;
        public UInt32 cDXPresent;
        public UInt64 cRefreshFrame;
        public UInt64 cFrameSubmitted;
        public UInt32 cDXPresentSubmitted;
        public UInt64 cFrameConfirmed;
        public UInt32 cDXPresentConfirmed;
        public UInt64 cRefreshConfirmed;
        public UInt32 cDXRefreshConfirmed;
        public UInt64 cFramesLate;
        public UInt32 cFramesOutstanding;
        public UInt64 cFrameDisplayed;
        public UInt64 qpcFrameDisplayed;
        public UInt64 cRefreshFrameDisplayed;
        public UInt64 cFrameComplete;
        public UInt64 qpcFrameComplete;
        public UInt64 cFramePending;
        public UInt64 qpcFramePending;
        public UInt64 cFramesDisplayed;
        public UInt64 cFramesComplete;
        public UInt64 cFramesPending;
        public UInt64 cFramesAvailable;
        public UInt64 cFramesDropped;
        public UInt64 cFramesMissed;
        public UInt64 cRefreshNextDisplayed;
        public UInt64 cRefreshNextPresented;
        public UInt64 cRefreshesDisplayed;
        public UInt64 cRefreshesPresented;
        public UInt64 cRefreshStarted;
        public UInt64 cPixelsReceived;
        public UInt64 cPixelsDrawn;
        public UInt64 cBuffersEmpty;


Member cbSize must be set before calling DwmGetCompositionTimingInfo function.

    cbSize = (uint)Marshal.SizeOf(typeof(DWM_TIMING_INFO));

Member qpcVBlank here is UInt64, this is very strange since it represents a QPC(QueryPerformanceCounter) value which itself is Int64.

For convenience we can use Int64 instead of UInt64 to avoid unnecessary casting, it's pretty safe to do so.

Normally, the frequency of QPC(QueryPerformanceFrequency) is below 10 MHz, a 10 MHz QPC won't exceed Int64.MaxValue in:

    Int64.MaxValue / (10.0 * 1000 * 1000) / 3600 / 24 / 365 = more than 29247 years.

Even if the QPC has a frequency of 10 GHz, it would still take more than 29 years to exceed Int64.MaxValue.