> ## 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.

# XtfGetConsoleInfoList

> XtfGetConsoleInfoList

# XtfGetConsoleInfoList

返回包含主机相关信息的 `XtfConsoleInfo` 对象。

<a id="syntaxSection" />

## 语法

```cpp theme={null}
HRESULT XtfGetConsoleInfoList(
         PCWSTR address,
         XtfConsoleInfo *hConsoleInfo
)  
```

<a id="parametersSection" />

### 参数

*address*\
类型：PCWSTR

\[in] 主机的地址。

*hConsoleInfo*\
类型：XtfConsoleInfo\*

\[out] 与 [XtfGetConsoleFieldValue](/reference/tools/xtf/xtfapi/functions/xtfgetconsolefieldvalue-xbox-microsoft-m) 函数一起使用以检索主机相关信息的指针。

<a id="retvalSection" />

### 返回值

类型：HRESULT

如果函数成功且可以使用 [XtfGetConsoleFieldValue](/reference/tools/xtf/xtfapi/functions/xtfgetconsolefieldvalue-xbox-microsoft-m) 从 **hConsoleInfo** 检索值，则返回 `S_OK`；否则返回 HRESULT 错误代码。

<a id="remarksSection" />

## 备注

若要检索主机相关信息，请先使用此函数获取 `XtfConsoleInfo` 指针，然后使用 [XtfGetConsoleFieldValue](/reference/tools/xtf/xtfapi/functions/xtfgetconsolefieldvalue-xbox-microsoft-m) 从该指针中检索主机相关信息。检索所需信息后，请使用 [XtfCloseConsoleInfoList](/reference/tools/xtf/xtfapi/functions/xtfcloseconsoleinfolist-xbox-microsoft-m) 来释放与返回的 `XtfConsoleInfo` 指针关联的资源。

<Note>`XtfGetConsoleInfoList` 从主机检索所有信息，并提供指向该信息的指针。[XtfGetConsoleFieldValue](/reference/tools/xtf/xtfapi/functions/xtfgetconsolefieldvalue-xbox-microsoft-m) 仅迭代该检索到的信息。你必须同时使用这两个函数才能检索主机相关信息。</Note>

<Note>如果此函数的 `address` 中指定的目标主机尚未预配，那么当 `field` 中指定了 [XtfConsoleFieldId::DeviceID](/reference/tools/xtf/xtfapi/enums/xtfconsolefieldid-xbox-windows-t) 时，[XtfGetConsoleFieldValue](/reference/tools/xtf/xtfapi/functions/xtfgetconsolefieldvalue-xbox-microsoft-m) 函数会返回空值。</Note>

以下代码示例演示如何同时使用 `XtfGetConsoleInfoList` 和 `XtfGetConsoleFieldValue` 函数来检索开发主机的主机 ID。

```cpp theme={null}
int wmain(int argc, wchar_t **argv)
{
  HRESULT             hr             = S_OK;
  PCWSTR              consoleAddress = L" 190.167.10.18";
  XtfConsoleInfo      hConsoleInfo   = nullptr;
  XtfConsoleFieldType fieldType      = XtfConsoleFieldType::FieldTypeUINT32;
  BYTE *              pValueBuffer   = nullptr;
  UINT32              bufferSize     = 0;

  hr = XtfGetConsoleInfoList(consoleAddress, &hConsoleInfo);
  if (FAILED(hr))
  {
    wprintf(L"\n\n*** XtfGetConsoleInfoList failed 0x%x", hr);
    return hr;
  }

  hr = XtfGetConsoleFieldValue(hConsoleInfo, XtfConsoleFieldId::ConsoleId, &fieldType, nullptr, &bufferSize);
  if (hr != HRESULT_FROM_WIN32(ERROR_MORE_DATA))
  {
    XtfCloseConsoleInfoList(hConsoleInfo);
    wprintf(L"\n\n*** XtfGetConsoleFieldValue failed 0x%x", hr);
    return hr;
  }

  pValueBuffer = new BYTE[bufferSize];

  hr  = XtfGetConsoleFieldValue(hConsoleInfo, XtfConsoleFieldId::ConsoleId, &fieldType, pValueBuffer, &bufferSize);
  if (SUCCEEDED(hr))
  {
    PWCHAR consoleId = (PWCHAR)pValueBuffer;
    wprintf(L"\n\n*** Console ID is %s", consoleId);
  }
  else
  {
    wprintf(L"\n\n*** XtfGetConsoleFieldValue failed 0x%x", hr);
  }

  XtfCloseConsoleInfoList(hConsoleInfo);
  delete[] pValueBuffer;

  return hr;
}  
```

<a id="requirementsSection" />

## 要求

**头文件：** xtfapi.h

**库：** XtfApi.lib

**支持的平台：** Windows（适用于 XBOX 主机工具）

<a id="seealsoSection" />

## 另请参阅

[XtfConsoleControl](/reference/tools/xtf/xtfconsolecontrol/xtfconsolecontrol_members)\
[XBOX Tools Framework](/reference/tools/xtf/atoc-xbox-tools-framework)


## Related topics

- [XtfCloseConsoleInfoList](/zh-CN/reference/tools/xtf/xtfapi/functions/xtfcloseconsoleinfolist-xbox-microsoft-m.md)
- [XtfGetConsoleFieldValue](/zh-CN/reference/tools/xtf/xtfapi/functions/xtfgetconsolefieldvalue-xbox-microsoft-m.md)
- [XtfGetCredentialInfoList](/zh-CN/reference/tools/xtf/xtfapi/functions/xtfgetcredentialinfolist-xtfapi-xbox-windows-m.md)
- [XtfCloseCredentialInfoList](/zh-CN/reference/tools/xtf/xtfapi/functions/xtfclosecredentialinfo-xtfapi-xbox-windows-m.md)
- [XtfGetCredentialInfoCount](/zh-CN/reference/tools/xtf/xtfapi/functions/xtfgetcredentialinfocount-xtfapi-xbox-windows-m.md)
