locked
How do I use CreateRandomAccessStreamOverStream with ComPtr<IStream>?

    Question

  • How do I use CreateRandomAccessStreamOverStream from a ComPtr<IStream>?  Code example please.  There are no code examples anywhere.  I am trying to manipulate an IStream with WIC and convert it and return it as IRandomAccessStream from my C++/CX component.

    Thanks in advance!


    SB Software Developer

    Wednesday, October 10, 2012 2:19 AM

Answers

  • Thanks for the help! 
    But I realized that I should just send a IRandomAccessStream to the c++ component and that the IStream created by CreateStreamOverRandomAccessStream changes the original IRandomAccessStream.

    SB Software Developer

    • Marked as answer by Sacha Bwin Thursday, October 11, 2012 9:46 PM
    Thursday, October 11, 2012 9:43 PM
  • //////.h file

    public:

    void ManipulateRandomAccessStreamFunction(_Out_Windows::Storage::Streams::IRandomAccessStream^ randomAccessStream);

     

    /////.cpp file

    void MyClass::ManipulateRandomAccessStreamFunction(_Out_ Windows::Storage::Streams::IRandomAccessStream^ randomAccessStream)
    {
    ComPtr<IStream> stream ;
    
    CreateStreamOverRandomAccessStream(randomAccessStream, IID_PPV_ARGS(&stream));
    		
    //Manipulate Stream with WIC or whatever here, that's it
    
    }

    SB Software Developer



    • Edited by Sacha Bwin Friday, October 19, 2012 7:15 PM
    • Marked as answer by Sacha Bwin Friday, October 19, 2012 7:27 PM
    Friday, October 19, 2012 7:13 PM

All replies

  • Something like the following:

    // pStream is our initialized ComPtr<IStream>
    IRandomAccessStream *pRas = nullptr;
    hr = CreateRandomAccessStreamOverStream(pStream.Get(), BSOS_DEFAULT, IID_PPV_ARGS(&pRas));  
    if (SUCCEEDED(hr)) { 
        // ..... 
    }
    --Rob

    Wednesday, October 10, 2012 4:22 AM
    Owner
  • This almost works but I had to change

    IRandomAccessStream **pRas = nullptr;

    to IRandomAccessStream^ **pRas = nullptr;


    and

    IID_PPV_ARGS(&pRas)); 
    gets the error

     IntelliSense: operand of __uuidof must have a class or enum type for which __declspec(uuid('...'))

    Also I need to return an actual IRandomAccessStream not a native pointer as this is WinRT.
    (I just learned native/c++ last week... many other languages for 25+ years)    
    I basically want to return a bitmap in the IRandomAccessStream or other format from my C++/CX component



    • Edited by Sacha Bwin Wednesday, October 10, 2012 6:34 AM
    Wednesday, October 10, 2012 6:22 AM
  • So how can I convert a ComPtr<IStream> into an IRandomAccessStream?

    Now I need to convert it to an IRandomAccessStream not a COM Pointer so
    NOT ComPtr<IRandomAccessStream> because I can't return a ComPtr<T> it must be a type that is not native in WinRT.  So it must be a raw IRandomAccessStream. 

    How do I go about doing this?


    I just learned c++ last week (28 years into my career) so I am new to pointers. 


    SB Software Developer

    Wednesday, October 10, 2012 6:28 PM
  • Try including library shcore.lib


    n.Wright

    Wednesday, October 10, 2012 9:34 PM
  • I tried this but I still get the error on:

    IID_PPV_ARGS(&randomAccessStream)


    SB Software Developer

    Thursday, October 11, 2012 6:56 PM
  • Thanks for the help! 
    But I realized that I should just send a IRandomAccessStream to the c++ component and that the IStream created by CreateStreamOverRandomAccessStream changes the original IRandomAccessStream.

    SB Software Developer

    • Marked as answer by Sacha Bwin Thursday, October 11, 2012 9:46 PM
    Thursday, October 11, 2012 9:43 PM
  • I encounter the same problem as these:

    This almost works but I had to change 
    IRandomAccessStream **pRas  = nullptr; 
    to IRandomAccessStream^ **pRas = nullptr; 
     and
    IID_PPV_ARGS(&pRas));  
    gets the error
    
     IntelliSense: operand of __uuidof must have a class or enum type for which __declspec(uuid('...')) 
    
    

     

     

    Couldn't tell us about how you solve this problem.

    Friday, October 19, 2012 7:58 AM
  • //////.h file

    public:

    void ManipulateRandomAccessStreamFunction(_Out_Windows::Storage::Streams::IRandomAccessStream^ randomAccessStream);

     

    /////.cpp file

    void MyClass::ManipulateRandomAccessStreamFunction(_Out_ Windows::Storage::Streams::IRandomAccessStream^ randomAccessStream)
    {
    ComPtr<IStream> stream ;
    
    CreateStreamOverRandomAccessStream(randomAccessStream, IID_PPV_ARGS(&stream));
    		
    //Manipulate Stream with WIC or whatever here, that's it
    
    }

    SB Software Developer



    • Edited by Sacha Bwin Friday, October 19, 2012 7:15 PM
    • Marked as answer by Sacha Bwin Friday, October 19, 2012 7:27 PM
    Friday, October 19, 2012 7:13 PM
  • Thank you for you reply.

    But what you sat is convert IRandomAccessStream to IStream.

    I want to know how to convert IStream to IRandomAccessStream.....

    I tried this:

    IRandomAccessStream^ comRAS;
    IUnknown* p11 = reinterpret_cast<IUnknown *>(comRAS);
    
    static const GUID guidIRandomAccessStream = 
    	{ 0x905a0fe1, 0xbc53, 0x11df, { 0x8c, 0x49, 0x00, 0x1e, 0x4f, 0xc6, 0x86, 0xda } };
    
    hr = CreateRandomAccessStreamOverStream(pStream.Get(), BSOS_DEFAULT, guidIRandomAccessStream, (void**)&p11);
    
    It works OK, p11 is not nullptr anymore, but comRAS is nullptr yet. I want to know why ???
    Friday, October 19, 2012 11:58 PM
  • Try CreateStreamOverRandomAccessStream instead of CreateRandomAccessStreamOverStream like so:

    CreateStreamOverRandomAccessStream(randomAccessStream, IID_PPV_ARGS(&stream));

    You should then be able to manipulate the stream and it changes the source RandomAccessStream.


    SB Software Developer

    Saturday, October 20, 2012 2:59 AM
  • ComPtr<IWICStream> pStream=nullptr;
    HRESULT hr = m_wicFactory->CreateStream(&pStream);
    hr = pStream->InitializeFromFilename(TEXT("Assets\\Logo.png"), GENERIC_READ);
    
    IRandomAccessStream^ randomAccessStream;
    CreateStreamOverRandomAccessStream(randomAccessStream, IID_PPV_ARGS(&pStream));

    Above is my test code.

    I get a IWICStream and want to convert it to IRandomAccessStream.

    It failed according what you said above.

    Saturday, October 20, 2012 4:06 AM
  • IRandomAccessStream^ rasTest; static const GUID guidIRandomAccessStream = { 0x905a0fe1, 0xbc53, 0x11df, { 0x8c, 0x49, 0x00, 0x1e, 0x4f, 0xc6, 0x86, 0xda } }; hr = CreateRandomAccessStreamOverStream(pStream.Get(), BSOS_DEFAULT, guidIRandomAccessStream, (void**)(&rasTest));

    After many times test. I find this way can resolve the proble.

    What I want to say is guidIRandomAccessStream, It's guid of IRandomAccessStream.

    You can get it in MSDN

    Thanks S B.

    • Proposed as answer by Jumping fish Saturday, October 20, 2012 7:14 AM
    Saturday, October 20, 2012 7:14 AM
  • Hello SB, I am not sure, but I think you are in the quest of rendering xaml to a bitmap. I have seen that there is a lot of information that it is not supported ... and I would like to know your opinión at this momento, is that possible?

    Juan Pablo G.C. MAP 2010 MCTS

    Wednesday, October 24, 2012 5:23 AM