#pragma once #include #include #include #include #include class NativeBuffer : public Microsoft::WRL::RuntimeClass, ABI::Windows::Storage::Streams::IBuffer, Windows::Storage::Streams::IBufferByteAccess> { public: virtual ~NativeBuffer() { } STDMETHODIMP RuntimeClassInitialize(byte *buffer, UINT totalSize) { m_length = totalSize; m_buffer = buffer; return S_OK; } STDMETHODIMP Buffer(byte **value) { *value = m_buffer; return S_OK; } STDMETHODIMP get_Capacity(UINT32 *value) { *value = m_length; return S_OK; } STDMETHODIMP get_Length(UINT32 *value) { *value = m_length; return S_OK; } STDMETHODIMP put_Length(UINT32 value) { m_length = value; return S_OK; } static Windows::Storage::Streams::IBuffer^ GetIBuffer(byte *buffer, uint32_t totalSize) { Microsoft::WRL::ComPtr nativeBuffer; Microsoft::WRL::Details::MakeAndInitialize(&nativeBuffer, buffer, totalSize); auto obj = reinterpret_cast(nativeBuffer.Get()); return reinterpret_cast(obj); } private: UINT32 m_length; byte *m_buffer; };