locked
Writing an implementation of IMFByteStream RRS feed

  • Question

  • I want to make a C++ class that inherits from IMFByteStream and wraps a System::IO::Stream^ so that I can use it with Windows Media Foundation. I have made the class inheriting from IMFByteStream and added all of the required virtual methods. For instance, here is the declaration for `Read` in the header file:

    virtual HRESULT Read(
    	_In_   BYTE *pb,
    	_In_   ULONG cb,
    	_Out_  ULONG *pcbRead
    	);

     And the corresponding bit in the .cpp file

    HRESULT StreamWrapper::Read(
    	_In_   BYTE *pb,
    	_In_   ULONG cb,
    	_Out_  ULONG *pcbRead
    	)
    {
             //one day there will be some code in here
    	return -1;
    }

    This gives me a compiler error for each function :

    error C2695: 'ProjectName::StreamWrapper::Read': overriding virtual function differs from 'IMFByteStream::Read' only by calling convention

    What do I do? I have been using C# for quite a few years now but I need to work with C++ and media foundation to decode mp3s and do low level audio processing. I've opened a real can of worms here. I suspect that I have missed some macro. Or perhaps I have completely misunderstood how the library works or how to implement interfaces. This problem of trying to get WinRT or .NET streams to play nicely with Media Foundation is driving me mental. If writing a wrapper for IMFByteStream is the wrong way to do this then a broader picture of what I'm trying to do can be found here:  http://stackoverflow.com/questions/11265871/windows-8-passing-a-stream-to-a-mfsourcereader


    Thanks
    • Edited by Ciemnl Saturday, June 30, 2012 4:36 PM
    Saturday, June 30, 2012 4:35 PM

All replies

  • Methods should be declared as STDMETHODCALLTYPE, ie:

    HRESULT STDMETHODCALLTYPE StreamWrapper::Read(
        _In_ BYTE *pb,
        _In_ ULONG cb,
        _Out_ ULONG *pcbRead
        )
    

    This is necessary for all COM APIs; the calling convention used to call COM functions is different from the standard C++ calling convention.
    Wednesday, August 15, 2012 8:40 PM