⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 virtualmemory.cpp

📁 wince6.0平台上的任务管理器,功能类似于windows的任务管理器. In order to develop applications for Windows Mobile 6.x from
💻 CPP
字号:

#include "stdafx.h"
#include "VirtualMemory.h"
#include "Windows\Handle.h"

VirtualMemory::VirtualMemory(DWORD processId, DWORD baseAddress) :
    m_baseAddress(baseAddress),
    m_committedMemory(0),
    m_reservedMemory(0),
    m_totalMemory(0)
{
    GetMemoryInfo(processId);
}

void VirtualMemory::GetMemoryInfo(DWORD processId)
{
    DWORD startAddress = m_baseAddress;
    DWORD endAddress = startAddress + 0x40000000;
    DWORD address = startAddress;
#if (_WIN32_WCE < 0x600) && defined(UNDER_CE)
#else
    Windows::Handle handle = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, processId);
#endif

    while (address < endAddress)
    {
        MEMORY_BASIC_INFORMATION memoryInfo;
#if (_WIN32_WCE < 0x600) && defined(UNDER_CE)
        SIZE_T rv = ::VirtualQuery((LPVOID)address, &memoryInfo, sizeof(memoryInfo));
#else
        SIZE_T rv = ::VirtualQueryEx(handle, (LPVOID)address, &memoryInfo, sizeof(memoryInfo));
#endif
        if (rv != 0)
        {
            if (memoryInfo.State == MEM_COMMIT)
                m_committedMemory += memoryInfo.RegionSize;
            if (memoryInfo.State == MEM_RESERVE)
                m_reservedMemory += memoryInfo.RegionSize;
            if (memoryInfo.State != MEM_FREE)
                m_totalMemory += memoryInfo.RegionSize;

            address += memoryInfo.RegionSize;
        }
        else
            break;
    }
}

DWORD VirtualMemory::GetCommittedMemory() const
{
    return m_committedMemory;
}

DWORD VirtualMemory::GetReservedMemory() const
{
    return m_reservedMemory;
}

DWORD VirtualMemory::GetTotalMemory() const
{
    return m_totalMemory;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -