[StructLayout(LayoutKind.Sequential)]

    public struct PPROCESS_MEMORY_COUNTERS
    {
        ///


        /// 结构体大小
        ///

        public UInt32 cb;

        ///
        /// 缺页中断次数
        ///

        public UInt32 PageFaultCount;

        ///
        /// 使用内存高峰
        ///

        public UInt32 PeakWorkingSetSize;

        ///
        /// 当前使用的内存
        ///

        public UInt32 WorkingSetSize;

        ///
        /// 使用页面缓存池高峰
        ///

        public UInt32 QuotaPeakPagedPoolUsage;

        ///
        /// 使用页面缓存池
        ///

        public UInt32 QuotaPagedPoolUsage;

        ///
        /// 使用非分页缓存池高峰
        ///

        public UInt32 QuotaPeakNonPagedPoolUsage;

        ///
        /// 使用非分页缓存池
        ///

        public UInt32 QuotaNonPagedPoolUsage;

        ///
        /// 使用分页文件
        ///

        public UInt32 PagefileUsage;

        ///
        /// 使用分页文件的高峰
        ///

        public UInt32 PeakPagefileUsage;
    }

 

        ///


        /// Retrieves the calling thread's last-error code value.
        ///

        /// The return value is the calling thread's last-error code.
        [System.Runtime.InteropServices.DllImport("Kernel32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
        internal static extern Int32 GetLastError();

               ///


        /// Retrieves information about the memory usage of the specified process.
        ///

        /// A handle to the process. The handle must have the PROCESS_QUERY_INFORMATION or PROCESS_QUERY_LIMITED_INFORMATION access right and the PROCESS_VM_READ access right.
        /// A pointer to the PROCESS_MEMORY_COUNTERS or PROCESS_MEMORY_COUNTERS_EX structure that receives information about the memory usage of the process.
        /// The size of the ppsmemCounters structure, in bytes.
        /// If the function succeeds, the return value is nonzero.
        [System.Runtime.InteropServices.DllImport("Psapi.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true, EntryPoint = "GetProcessMemoryInfo")]
        internal static extern int GetProcessMemoryInfo(IntPtr hProcess, out PPROCESS_MEMORY_COUNTERS ppsmemCounters, Int32 cb);

 

 

        ///


        /// Gets the memory information.
        ///

        /// The error code.
        ///
        public static PPROCESS_MEMORY_COUNTERS GetMemoryInformation(out int errorCode)
        {
            errorCode = 0;
            PPROCESS_MEMORY_COUNTERS memoryInfo;
            if (NativeMethods.GetProcessMemoryInfo(HelpViewerProcess.Handle, out memoryInfo, System.Runtime.InteropServices.Marshal.SizeOf(typeof(PPROCESS_MEMORY_COUNTERS))) != 1)
            {
                errorCode = NativeMethods.GetLastError();
            }
            return memoryInfo;
        }