Platform SDK: Memory

VirtualQueryEx

The VirtualQueryEx function provides information about a range of pages within the virtual address space of a specified process.

DWORD VirtualQueryEx(
  HANDLE hProcess,                     // handle to process
  LPCVOID lpAddress,                   // address of region
  PMEMORY_BASIC_INFORMATION lpBuffer,  // information buffer
  DWORD dwLength                       // size of buffer
);

Parameters

hProcess
[in] Handle to the process whose memory information is queried. The handle must have been opened with PROCESS_QUERY_INFORMATION, which enables using the handle to read information from the process object.
lpAddress
[in] Pointer to the base address of the region of pages to be queried. This value is rounded down to the next page boundary. To determine the size of a page on the host computer, use the GetSystemInfo function.
lpBuffer
[out] Pointer to a MEMORY_BASIC_INFORMATION structure in which information about the specified page range is returned.
dwLength
[in] Specifies the size, in bytes, of the buffer pointed to by the lpBuffer parameter.

Return Values

The return value is the actual number of bytes returned in the information buffer.

Remarks

VirtualQueryEx provides information about a region of consecutive pages beginning at a specified address that share the following attributes:

The VirtualQueryEx function determines the attributes of the first page in the region and then scans subsequent pages until it scans the entire range of pages, or until it encounters a page with a nonmatching set of attributes. The function returns the attributes and the size, in bytes, of the region of pages with matching attributes. For example, if there is a 40 megabyte (MB) region of free memory, and VirtualQueryEx is called on a page that is 10 MB into the region, the function will obtain a state of MEM_FREE and a size of 30 MB.

Requirements

  Windows NT/2000: Requires Windows NT 3.1 or later.
  Windows 95/98: Requires Windows 95 or later.
  Header: Declared in Winbase.h; include Windows.h.
  Library: Use Kernel32.lib.

See Also

Memory Management Overview, Memory Management Functions, GetSystemInfo, MEMORY_BASIC_INFORMATION, VirtualAllocEx, VirtualProtectEx