> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XMemVirtualQuery

> XMemVirtualQuery

# XMemVirtualQuery

检索调用进程虚拟地址空间中一段页范围的信息。

<a id="syntaxSection" />

## 语法

```cpp theme={null}
BOOL XMemVirtualQuery(  
         HANDLE Process,  
         PVOID Address,  
         PXMEM_BASIC_INFORMATION Buffer  
)  
```

<a id="parametersSection" />

### 参数

*Process*   \_In\_\
类型：HANDLE

进程句柄，通常通过调用 [GetCurrentProcess](https://learn.microsoft.com/windows/desktop/api/processthreadsapi/nf-processthreadsapi-getcurrentprocess) 获取。

*Address*   \_In\_opt\_\
类型：PVOID

指向要查询的页区域的基地址的指针。此值将向下舍入到下一个页边界。如果此参数设置为高于进程可访问的最高内存地址，则函数将失败，错误代码设置为 **ERROR\_INVALID\_PARAMETER**。

*Buffer*   \_Out\_\
类型：PXMEM\_BASIC\_INFORMATION

指向 [XMEM\_BASIC\_INFORMATION](/reference/system/xmem/structs/xmem_basic_information) 结构的指针，其中返回有关指定页范围的信息。

<a id="retvalSection" />

### 返回值

类型：BOOL

成功时返回 `TRUE`；否则返回 `FALSE`。若要获取扩展错误信息，请调用 [GetLastError](https://msdn.microsoft.com/library/windows/desktop/ms679360\(v=vs.85\).aspx)。

<a id="remarksSection" />

## 备注

工具可以将句柄传递给远程进程，以从当前进程外部查询游戏。

如果所查询的内存区域具有关联的可选四字符代码标签，则该标签将包含在 `Buffer` 中返回的 `XMEM_BASIC_INFORMATION` 结构的 `TagFourCC` 字段中，并在 `TagCode` 字段中编码为 24 位表示形式。否则，`TagFourCC` 字段将填充 NULL 值，`TagCode` 字段应被忽略。有关标签的详细信息，请参阅 [XMemVirtualAlloc](/reference/system/xmem/functions/xmemvirtualalloc)。

示例：若要计算通过直接调用 'XMemVirtualAlloc' 分配的内存的总内存使用量，需要结合使用 'XMemSetOption' 和 'XMemVirtualQuery'。

```cpp theme={null}
// To enable commit tracking
XMEM_OPTION option;
option.Option = eXMEMOPT_XMEMALLOCDEFAULT_TAG_VIRTUALALLOC;
option.u.Bool = TRUE;
XMemSetOption(option);

// To query the total commit
SIZE_T address = 0;
SIZE_T commitSize = 0;
XMEM_BASIC_INFORMATION info; = {};
while (XMemVirtualQuery(GetCurrentProcess(), (PVOID)address, &info))
{
        if ((info.State & MEM_COMMIT) &&
                (*(PDWORD)(info.TagFourCC) == *(PDWORD)("XmVA"))) {

                commitSize += info.RegionSize;
        }

        address += info.RegionSize;
}
```

<a id="requirementsSection" />

## 要求

**头文件：** xmem.h

**库：** xmem.lib

**支持的平台：** XBOX One 系列主机和 XBOX Series 主机

<a id="seealsoSection" />

## 另请参阅

[XMEM\_BASIC\_INFORMATION](/reference/system/xmem/structs/xmem_basic_information)\
[XMem](/reference/system/xmem/xmem_members)


## Related topics

- [使用 Microsoft GDK 游戏 OS 内存管理器](/zh-CN/build/console-features/memory/system-memory-working.md)
- [XMemMakeTag](/zh-CN/reference/system/xmem/functions/xmemmaketag.md)
- [XMemMapPhysicalPages](/zh-CN/reference/system/xmem/functions/xmemmapphysicalpages.md)
- [XMemMapPhysicalPagesScatter](/zh-CN/reference/system/xmem/functions/xmemmapphysicalpagesscatter.md)
- [XMEM_OPTIONS](/zh-CN/reference/system/xmem/enums/xmem_options.md)
