IBuffer 介面

定義

表示位元組資料流程讀取和寫入介面所使用的位元組參考陣列。 Buffer 是這個介面的類別實作。

public interface class IBuffer
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.Guid(2421821408, 48211, 4575, 140, 73, 0, 30, 79, 198, 134, 218)]
struct IBuffer
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.Guid(2421821408, 48211, 4575, 140, 73, 0, 30, 79, 198, 134, 218)]
public interface IBuffer
Public Interface IBuffer
衍生
屬性

Windows 需求

裝置系列
Windows 10 (已於 10.0.10240.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)

範例

此程式碼範例示範如何從 UTF-8 位元組的 IBuffer 擷取字串。

public string RetrieveStringFromUtf8IBuffer(Windows.Storage.Streams.IBuffer theBuffer)
{
    using (var dataReader = Windows.Storage.Streams.DataReader.FromBuffer(theBuffer))
    {
        dataReader.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8;
        return dataReader.ReadString(theBuffer.Length);
    }
}

備註

這個介面用於調整緩衝區的大小,同時保留內容。 如果您的 C++/WinRT 類別實作 IBuffer ,而且不需要或支援調整大小,您應該擲回 hresult_not_implemented

如需詳細資訊,請參閱 建立、寫入和讀取檔案,其中示範如何使用 Buffer讀取和寫入檔案的位元組。

WriteableBitmap.PixelBuffer 是傳回無法直接寫入 IBuffer 的屬性範例。 請參閱該主題,以取得顯示要寫入緩衝區中基礎圖元內容的語言特定程式碼範例。

C++/WinRT 延伸模組函式

注意

擴充功能函式存在於特定Windows 執行階段 API 的 C++/WinRT 投影類型上。 例如, winrt::Windows::Foundation::IAsyncActionIAsyncAction的 C++/WinRT 投影類型。 擴充函式不是應用程式二進位介面的一部分, (實際Windows 執行階段類型的 ABI) 介面,因此它們不會列為Windows 執行階段 API 的成員。 但您可以從任何 C++/WinRT 專案內呼叫它們。 請參閱擴充 Windows 執行階段 API 的 C++/WinRT 函式。

uint8_t* data() const;

傳回緩衝區內保留之資料的指標。

屬性

Capacity

取得緩衝區可以保存的最大位元組數目。

Length

取得緩衝區中目前使用的位元組數目。

適用於

另請參閱