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

# SetName

> 将名称与设备对象关联。此名称用于调试诊断和工具。

将名称与设备对象关联。
此名称用于调试诊断和工具。

## 语法

```cpp theme={null}
HRESULT SetName(
    LPCWSTR Name
)
```

### 参数

*Name \[in]*\
类型：**LPCWSTR**

一个以 **NULL** 结尾的 **UNICODE** 字符串，包含要与设备对象关联的名称。

### 返回值

类型：HRESULT

此方法返回 [Direct3D 12 返回代码](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/d3d12-graphics-reference-returnvalues)之一。

## 备注

此方法采用 UNICODE 名称。

请注意，这只是 [ID3D12Object::SetPrivateData](/reference/graphics/d3d12/interfaces/id3d12object/methods/id3d12object_setprivatedata_public) 与 **WKPDID\_D3DDebugObjectNameW** 的便捷包装器。
因此，使用 `SetName` 设置的名称可以通过使用相同 GUID 的 [ID3D12Object::GetPrivateData](/reference/graphics/d3d12/interfaces/id3d12object/methods/id3d12object_getprivatedata_public) 检索。
此外，D3D12 支持窄字符串名称，直接使用 **WKPDID\_D3DDebugObjectName** GUID。

## 要求

**头文件：** d3d12\_xs.h 或 d3d12\_x.h\
**库：** d3d12\_xs.lib 或 d3d12\_x.lib\
**支持的平台**：XBOX Series 主机和 XBOX One 系列

## 另请参阅

[Direct3D 12 编程环境设置](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/directx-12-programming-environment-set-up)

[ID3D12Object](/reference/graphics/d3d12_xs/interfaces/ID3D12Object/id3d12object)


## Related topics

- [SetPrivateData](/zh-CN/reference/graphics/d3d12/interfaces/id3d12object/methods/id3d12object_setprivatedata_public.md)
- [XMemSetWin32HeapName](/zh-CN/reference/system/xmem/functions/xmemsetwin32heapname.md)
- [XFrontPanelSetDisplayName](/zh-CN/reference/devkit/xfrontpaneldisplay/functions/xfrontpanelsetdisplayname.md)
- [XtfSetOverlayFolder](/zh-CN/reference/tools/xtf/xtfapi/functions/xtfsetoverlayfolder-xtfapi-xbox-windows-m.md)
- [ObjectSet](/zh-CN/services/playfab/api-references/events/data-types/objectset.md)
