QueryWorkingSet function (psapi.h)

Retrieves information about the pages currently added to the working set of the specified process.

To retrieve working set information for a subset of virtual addresses, or to retrieve information about pages that are not part of the working set (such as AWE or large pages), use the QueryWorkingSetEx function.

Syntax

BOOL QueryWorkingSet(
  [in]  HANDLE hProcess,
  [out] PVOID  pv,
  [in]  DWORD  cb
);

Parameters

[in] hProcess

A handle to the process. The handle must have the PROCESS_QUERY_INFORMATION and PROCESS_VM_READ access rights. For more information, see Process Security and Access Rights.

[out] pv

A pointer to the buffer that receives the information. For more information, see PSAPI_WORKING_SET_INFORMATION.

If the buffer pointed to by the pv parameter is not large enough to contain all working set entries for the target process, the function fails with ERROR_BAD_LENGTH. In this case, the NumberOfEntries member of the PSAPI_WORKING_SET_INFORMATION structure is set to the required number of entries, but the function does not return information about the working set entries.

[in] cb

The size of the pv buffer, in bytes.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

Starting with Windows 7 and Windows Server 2008 R2, Psapi.h establishes version numbers for the PSAPI functions. The PSAPI version number affects the name used to call the function and the library that a program must load.

If PSAPI_VERSION is 2 or greater, this function is defined as K32QueryWorkingSet in Psapi.h and exported in Kernel32.lib and Kernel32.dll. If PSAPI_VERSION is 1, this function is defined as QueryWorkingSet in Psapi.h and exported in Psapi.lib and Psapi.dll as a wrapper that calls K32QueryWorkingSet.

Programs that must run on earlier versions of Windows as well as Windows 7 and later versions should always call this function as QueryWorkingSet. To ensure correct resolution of symbols, add Psapi.lib to the TARGETLIBS macro and compile the program with -DPSAPI_VERSION=1. To use run-time dynamic linking, load Psapi.dll.

Requirements

Requirement Value
Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Target Platform Windows
Header psapi.h
Library Kernel32.lib on Windows 7 and Windows Server 2008 R2; Psapi.lib (if PSAPI_VERSION=1) on Windows 7 and Windows Server 2008 R2; Psapi.lib on Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP
DLL Kernel32.dll on Windows 7 and Windows Server 2008 R2; Psapi.dll (if PSAPI_VERSION=1) on Windows 7 and Windows Server 2008 R2; Psapi.dll on Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP

See also

EnumProcesses

PSAPI Functions

PSAPI_WORKING_SET_INFORMATION

QueryWorkingSetEx

Working Set Information