Click here to Skip to main content
15,890,982 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
sometimes when using the VirtualQuery function the return value is 0, it depends on the
VB
dwLength
paramter.

1. i used VirtualAlloc function to alloc 1 mbyte of memory

MIDL
pMem = VirtualAlloc(NULL, nAllocatedSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);


nAllocatedSize size is 1024*1024 (1MB)

2. i just what to view the status of the memory by

MEMORY_BASIC_INFORMATION meminfo;
DWORD size = VirtualQuery(pMem2,&meminfo,m_param1);


when i call that function with m_param1>8192 the return value is 0
and m_param1<8192 the value is 48, i did'nt used any of the memory i think it should return 1048576 becuase the attributes of all pages should be the some? no?

Thanks
Posted
Comments
Eugen Podsypalnikov 19-Aug-10 5:58am    
The returned value =sizeof(MEMORY_BASIC_INFORMATION)
or 0 (may be due to Windows >= 6.0 security checks) :)
Have you an XP platform to test it also there ?

The VirtualQuery function doesn't return the size of the memory you are querying. It returns the size of the buffer it has populated (meminfo in your case).

A return code of 0 indicates an error, and you'll need to call GetLastError() to find out more information.
 
Share this answer
 
Maybe you're misunderstanding the role of dwLength.
dwLength is the size of the buffer for MEMORY_BASIC_INFORMATION.
So you shouldn't let it greater than sizeof(MEMORY_BASIC_INFORMATION).

You'd better do like this.
C++
MEMORY_BASIC_INFORMATION meminfo;
SIZE_T size = VirtualQuery(pMem2, &meminfo, sizeof(MEMORY_BASIC_INFORMATION));
 
Share this answer
 
Comments
pascal.schwartz 22-Aug-10 2:35am    
Thank , you are right i was confused about the dwLength.
now it works

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