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

# GetDevice

> 取得指向建立此介面之裝置的指標。

取得指向建立此介面之裝置的指標。

## 語法

```cpp theme={null}
void GetDevice(
    const IID & riid,
    void** ppvDevice
)
```

### 參數

*riid*\
類型：const IID &

裝置介面的全域唯一識別碼 (**GUID**)。
裝置介面的 **REFIID** 或 **GUID** 可使用 \_\_uuidof() 巨集取得。
例如，\_\_uuidof([ID3D12Device](/zh-TW/reference/graphics/d3d12_x/interfaces/id3d12device/id3d12device)) 會取得裝置介面的 **GUID**。

*ppvDevice \[out, optional]*\
類型：**void**\*\*

指向記憶體區塊的指標，該區塊會接收指向裝置之 [ID3D12Device](/zh-TW/reference/graphics/d3d12_x/interfaces/id3d12device/id3d12device) 介面的指標。

### 傳回值

類型：void

此方法會傳回其中一個 [Direct3D 12 傳回碼](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/d3d12-graphics-reference-returnvalues)。

## 備註

任何傳回的介面其參考計數都會遞增一，因此請務必在釋放傳回的指標之前對其呼叫 ::release()，否則會發生記憶體流失。

#### 範例

[D3D12Multithreading](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/working-samples) 範例使用 **ID3D12DeviceChild::GetDevice** 的方式如下：

```cpp theme={null}
// Returns required size of a buffer to be used for data upload
inline UINT64 GetRequiredIntermediateSize(
_In_ ID3D12Resource* pDestinationResource,
_In_range_(0,D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
_In_range_(0,D3D12_REQ_SUBRESOURCES-FirstSubresource) UINT NumSubresources)
{
D3D12_RESOURCE_DESC Desc = pDestinationResource->GetDesc();
UINT64 RequiredSize = 0;

ID3D12Device* pDevice;
pDestinationResource->GetDevice(__uuidof(*pDevice), reinterpret_cast<void**>(&pDevice));
pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, 0, nullptr, nullptr, nullptr, &RequiredSize);
pDevice->Release();

return RequiredSize;
}

```

請參閱 [D3D12 參考中的範例程式碼](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/notes-on-example-code)。

<div class="code" />

## 需求

**標頭:** d3d12\_xs.h 或 d3d12\_x.h\
**程式庫:** d3d12\_xs.lib 或 d3d12\_x.lib\
**支援的平台**: XBOX Series 主機和 XBOX One 系列

## 另請參閱

[ID3D12DeviceChild](/zh-TW/reference/graphics/d3d12/interfaces/id3d12devicechild/id3d12devicechild_public)


## Related topics

- [IGameInputRawDeviceReport::GetDevice](/zh-TW/reference/input/gameinput/interfaces/igameinputrawdevicereport/methods/igameinputrawdevicereport_getdevice.md)
- [IGameInputReading::GetDevice](/zh-TW/reference/input/gameinput/interfaces/igameinputreading/methods/igameinputreading_getdevice.md)
- [PartyNetwork::GetDevices](/zh-TW/services/playfab/multiplayer/networking/reference/classes/PartyNetwork/methods/partynetwork_getdevices.md)
- [PartyEndpoint::GetDevice](/zh-TW/services/playfab/multiplayer/networking/reference/classes/PartyEndpoint/methods/partyendpoint_getdevice.md)
- [PartyChatControl::GetDevice](/zh-TW/services/playfab/multiplayer/networking/reference/classes/PartyChatControl/methods/partychatcontrol_getdevice.md)
