Getting an array of bytes out of Windows::Storage::Streams::IBuffer

Viewed 13953

I have an object that implements the interface Windows::Storage::Streams::IBuffer, and I want to get an array of bytes out of it, however while looking at the documentation this interface looks pretty useless, and the documentation does not offer any reference to any other class that could be combined with this interface to achieve my purpose. All I have found so far with google is a reference to the .Net class WindowsRuntimeBufferExtensions but I am using C++ so this is also a dead end.

Can someone give a hint on how to get an array of bytes from Windows::Storage::Streams::IBuffer in C++?

7 Answers

Since this question is tagged , here's a solution using C++/WinRT. It essentially does the same as this answer under the hood, but is way more accessible. The (undocumented) data() helper on the IBuffer projection does all the heavy lifting:

uint8_t* GetPointerToPixelData(::winrt::Windows::Storage::Streams::IBuffer const& buffer)
{
    return buffer.data();
}

There is unfortunately no official documentation (yet), and I only stumbled across this in the sample code for the WritableBitmap.PixelBuffer property (make sure to select "C++/WinRT" from the language dropdown at the top right).

An identical solution (querying for the IBufferByteAccess interface) is also available from that documentation entry when selecting "C++/CX" from the language dropdown.

Related