1

How to implement both IBufferByteAccess and IBuffer in Universal Windows (C++/CX)?

According to MSDN:

When you implement the IBuffer interface, you must implement the IBufferByteAccess interface, which is a COM interface for accessing the buffer directly. C++ callers use this interface to avoid making a copy of the buffer.

With following example:

ref class BufferWrapper sealed :
        public Windows::Storage::Streams::IBufferByteAccess,
        public Windows::Storage::Streams::IBuffer
{
    public:

        // Inherited via IBufferByteAccess
        virtual HRESULT QueryInterface(REFIID riid, void ** ppvObject) override;

        virtual ULONG AddRef(void) override;

        virtual ULONG Release(void) override;

        virtual HRESULT Buffer(byte ** value) override;


        // Inherited via IBuffer
        virtual property unsigned int Capacity;

        virtual property unsigned int Length; 
}

IBuffer is ok, but I get error on IBufferByteAccess that a C++/CX mapping ref class can only derive from another ref class or from interface class.

when I remove ref:

class BufferWrapper :
        public Windows::Storage::Streams::IBufferByteAccess,
        public Windows::Storage::Streams::IBuffer

IBufferByteAccess is ok, but I get error from IBuffer that a standard class cannot derive from a C++/CX class.

In header file I do not include anything, in source file I only included header that I have found here

#include <robuffer.h>

I have also found here that this header is only thing I need to include.

The problem is (I think) that IBufferByteAccess is not ref class but a struct derived from public IUnknown. Is there any header file with another deifnition of IBufferByteAccess that is ref class/interface that I am not aware of?

MegaTron
  • 102
  • 6
  • That is correct, you must use WRL. Perhaps the [MediaBufferWrapper sample](https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/SimpleCommunication/common/MediaExtensions/Microsoft.Samples.SimpleCommunication) is useful. – Hans Passant Aug 18 '17 at 17:55
  • I have found answer I needed [here](https://stackoverflow.com/questions/10520335/how-to-wrap-a-char-buffer-in-a-winrt-ibuffer-in-c) ! Exactly what I needed! – MegaTron Aug 18 '17 at 19:11

1 Answers1

0

So basically I have found an answer to my question. what I needed was to wrap char* buffer in winrt object. how this could be done can be found in the answer of this stack overflow question: How to wrap a char* buffer in a WinRT IBuffer in C++

MegaTron
  • 102
  • 6