Megosztás a következőn keresztül:


IBuffer Interface

Definition

Represents a referenced array of bytes used by byte stream read and write interfaces. Buffer is the class implementation of this interface.

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
Derived
Attributes

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

Examples

This code example shows how to retrieve a string from an IBuffer of UTF-8 bytes.

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);
    }
}

Remarks

This interface is used for resizing the buffer while preserving the contents. If your C++/WinRT class implements IBuffer and does not need or support resizing, you should throw hresult_not_implemented.

For more info, see Create, write, and read a file, which shows how to read and write bytes to a file by using a Buffer.

WriteableBitmap.PixelBuffer is an example of a property that returns an IBuffer that can't be written to directly. See that topic for a language-specific code example showing to write to the underlying pixel content in the buffer.

C++/WinRT extension functions

Note

Extension functions exist on the C++/WinRT projection types for certain Windows Runtime APIs. For example, winrt::Windows::Foundation::IAsyncAction is the C++/WinRT projection type for IAsyncAction. The extension functions aren't part of the application binary interface (ABI) surface of the actual Windows Runtime types, so they're not listed as members of the Windows Runtime APIs. But you can call them from within any C++/WinRT project. See C++/WinRT functions that extend Windows Runtime APIs.

uint8_t* data() const;

Returns a pointer to the data held inside the buffer.

Properties

Capacity

Gets the maximum number of bytes that the buffer can hold.

Length

Gets the number of bytes currently in use in the buffer.

Applies to

See also