|
#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;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.