Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I've been trying to read a process (e.g calculator) memory, and every thing seems ok on the code, but MemoryRegion is always same in the loop!! and
mem_info.State == MEM_COMMIT
will never be true!
I thing there is some thing wrong with 32 and 64bit OS.
I'm running on 64Bit win.

code:

HWND hwin = FindWindow(0,"calculator");
cout<<hwin<<endl;

unsigned long procId;
GetWindowThreadProcessId(hwin, &procId);

HANDLE proc = OpenProcess(PROCESS_ALL_ACCESS,0,procId);

cout<<proc<<endl;

SYSTEM_INFO sys_info;
GetSystemInfo(&sys_info);
long min_address = (long)sys_info.lpMinimumApplicationAddress;
long max_address = (long)sys_info.lpMaximumApplicationAddress;


MEMORY_BASIC_INFORMATION mem_info;

while(min_address < max_address)
{
    VirtualQueryEx(proc, &min_address, &mem_info, sizeof(mem_info));

    if (mem_info.State == MEM_COMMIT)
    {
        cout<<mem_info.RegionSize<<endl;
    }
    min_address = min_address + mem_info.RegionSize;
}



Any help will be appreciated
Posted
Comments
[no name] 5-Jun-14 22:38pm    
Is it working in 32-bit?
mehdi_k 8-Jun-14 3:27am    
I haven't tested it myself, but on the web, it seems to work.
Stefan_Lang 6-Jun-14 2:34am    
This is just a wild guess, but have you tried MEMORY_BASIC_INFORMATION64 ? See at the bottom of this site for more info: http://msdn.microsoft.com/en-us/library/windows/desktop/aa366775%28v=vs.85%29.aspx
mehdi_k 8-Jun-14 3:31am    
I think the link is dead.
yes I have tried to use MEMORY_BASIC_INFORMATION64, but the VirtualQueryEx only accepts MEMORY_BASIC_INFORMATION !

update
Your link is ok
Rage 18-Jun-14 5:13am    
What size is the VirtualQueryEx returning (as a return value) ?
Do you have a GetLastError value ?

1 solution

Your call to VirtualQueryEx looks wrong. Following Rage's advise would help you. Try this:

C++
BOOL bOK = VirtualQueryEx(proc, min_address, &mem_info, sizeof mem_info);
if (!bOK)
{
    DWORD dwErr = GetLastError();
    std::cout << "VirtualQueryEx returns " << dwErr << std::endl;
}


You may need to truncate the min_address to a page boundary. See:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa366907%28v=vs.85%29.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900