> ## 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](/zh-TW/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" />

## 備註

工具可以傳遞遠端處理序的控制代碼，以便從目前處理序外部查詢遊戲。

如果查詢的記憶體區域有相關聯的選擇性四字元代碼標籤，該標籤會包含在 `TagFourCC` 欄位中，並以 24 位元表示法編碼在 `Buffer` 中所傳回之 `XMEM_BASIC_INFORMATION` 結構的 `TagCode` 欄位中。否則，`TagFourCC` 欄位會填入 NULL 值，且應忽略 `TagCode` 欄位。如需標籤的詳細資訊，請參閱 [XMemVirtualAlloc](/zh-TW/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](/zh-TW/reference/system/xmem/structs/xmem_basic_information)\
[XMem](/zh-TW/reference/system/xmem/xmem_members)


## Related topics

- [XMemVirtualQuery](/reference/system/xmem/functions/xmemvirtualquery.md)
- [Working with the Microsoft GDK Game OS memory manager](/build/console-features/memory/system-memory-working.md)
- [Trabajo con el administrador de memoria del sistema operativo de juego del Microsoft GDK](/es/build/console-features/memory/system-memory-working.md)
- [使用 Microsoft GDK 游戏 OS 内存管理器](/zh-CN/build/console-features/memory/system-memory-working.md)
- [Microsoft GDK Game OS 메모리 관리자 사용](/ko/build/console-features/memory/system-memory-working.md)
