在 C++ (WinRT) 中从 IBuffer 转换为 const unsigned char

Convert from IBuffer to const unsigned char in C++ (WinRT)

我想从 C# 转换为 C++ 并 return 再次缓冲到 C# 如何将 IBuffer 转换为 "const unsigned char *data" 然后再转换为 IBuffer

Windows::Storage::Streams::IBuffer^ Decode(Windows::Storage::Streams::IBuffer^ buff, int len, int frame_size, int decode_fec);

Windows::Storage::Streams::IBuffer^ MyApi::Decode(Windows::Storage::Streams::IBuffer^ buff, int len, int frame_size, int decode_fec)
{

}

您可以通过查询 IBufferByteAccess interface then accessing IBufferByteAccess::Buffer 以字节形式获取其内容来访问 IBuffer 的内容 *

IUnknown* pUnk = reinterpret_cast<IUnknown*>(buff);
IBufferByteAccess* pBufferByteAccess = nullptr;
HRESULT hr = pUnk->QueryInterface(IID_PPV_ARGS(pBufferByteAccess);
byte *pbytes = nullptr;
hr = pBufferByteAccess->Buffer(&pbytes);