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

# OpenFile

> IDStorageFactoryX::OpenFile

# IDStorageFactoryX::OpenFile

開啟檔案以供 DirectStorage 存取。

## 語法

```cpp theme={null}
HRESULT OpenFile(  
         const WCHAR *path,  
         REFIID riid,  
         void **ppv  
)  
```

### 參數

*path*   \_In\_z\_\
類型：WCHAR \*

要開啟之檔案的路徑。

*riid*\
類型：REFIID

指定 DirectStorage 檔案介面，例如 `__uuidof(IDStorageFileX)`。

*ppv*   \_COM\_Outptr\_\
類型：void \*\*

接收代表已開啟檔案的物件。

### 傳回值

類型：HRESULT

標準 HRESULT 錯誤碼。

## 備註

指定的檔案必須儲存在 DirectStorage 支援的 NVM Express (NVMe) 裝置上。

當對應 `IDStorageFileX` 物件的最後一個參考被釋放時，檔案會隱含地關閉。若要明確關閉檔案，請呼叫 [IDStorageFileX::Close](https://docs.xbox.com/zh-TW/reference/system/dstorage/interfaces/IDStorageFileX/methods/idstoragefilex_close.md)。

如需詳細資訊，請參閱 [DirectStorage 概觀](https://docs.xbox.com/zh-TW/build/console-features/storage/directstorage/directstorage-overview.md)中的「IDStorageFileX」一節。

## 需求

**標頭：** dstorage\_xs.h

**程式庫：** dstorage\_xs.lib

**支援的平台：** XBOX Series 主機

## 另請參閱

[IDStorageFactoryX](https://docs.xbox.com/zh-TW/reference/system/dstorage/interfaces/IDStorageFactoryX/idstoragefactoryx.md)\
[DStorage](https://docs.xbox.com/zh-TW/reference/system/dstorage/dstorage_members.md)


## Related topics

- [IDStorageFileX::Close](https://docs.xbox.com/zh-TW/reference/system/dstorage/interfaces/IDStorageFileX/methods/idstoragefilex_close.md)
- [IDStorageFileX (介面內容)](https://docs.xbox.com/zh-TW/reference/system/dstorage/interfaces/IDStorageFileX/idstoragefilex.md)
- [GetHandle](https://docs.xbox.com/zh-TW/reference/system/dstorage/interfaces/IDStorageFileX/methods/idstoragefilex_gethandle.md)
- [IDStorageFactoryX (介面內容)](https://docs.xbox.com/zh-TW/reference/system/dstorage/interfaces/IDStorageFactoryX/idstoragefactoryx.md)
- [DirectStorage 概觀](https://docs.xbox.com/zh-TW/build/console-features/storage/directstorage/directstorage-overview.md)
