Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8499577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:42:19+00:00 2026-06-11T00:42:19+00:00

I need to get IRandomAccessStream to a file without a picker. However, I’m stuck

  • 0

I need to get IRandomAccessStream to a file without a picker.

However, I’m stuck with IStorageFile or IRandomAccessStreamReference and can’t find a way to get IRandomAccessStream from either of those.

I write the code with C++ (no /ZW), but I don’t think it matters in this case.

Please help,
Moshe

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:42:21+00:00Added an answer on June 11, 2026 at 12:42 am

    I managed to do what I wanted using OpenReadAsync of StorageFile. But this involves 2 async calls and is cumbersome. I wonder if there is a shorter and a more elegant way. The relevant sample code below:

    IFACEMETHODIMP MyClass::BeginCreateObject( 
        //... rest of parameters
        _In_ IMFAsyncCallback *pCallback,
        _In_ IUnknown *punkState)
    {
        OutputDebugStringW(__FUNCTIONW__);
        HRESULT hr;
    
        HString hstrStorageFile;
        hstrStorageFile.Set(RuntimeClass_Windows_Storage_StorageFile);
    
        // Get the Activation Factory
        ComPtr<IActivationFactory> pStorageFileActivationFactory;
        hr = GetActivationFactory(hstrStorageFile.Get(), &pStorageFileActivationFactory);
        if (FAILED(hr))
        {
            ::Microsoft::WRL::Details::RaiseException(hr);
        }
    
        // QI for StorageFileStatics
        ComPtr<IStorageFileStatics> pStorageFileStatics;
        hr = pStorageFileActivationFactory.As(&pStorageFileStatics);
        if (FAILED(hr))
        {
            ::Microsoft::WRL::Details::RaiseException(hr);
        }
    
        HString hstrFileName;
        hstrFileName.Set(L"My_Cool_Movie.ts");
    
        // Call CreateFileAsync
        __FIAsyncOperation_1_Windows__CStorage__CStorageFile * operation;    
        hr = pStorageFileStatics->GetFileFromPathAsync(hstrFileName.Get(),
            &operation
            );
        if (FAILED(hr))
        {
            ::Microsoft::WRL::Details::RaiseException(hr);
        }
    
        typedef IAsyncOperationCompletedHandler<StorageFile*> HandlerDoneType; 
        ComPtr<HandlerDoneType> handler(Callback<HandlerDoneType>( 
            this, &MyClass::FileOpenCompletionHandler)); 
        hr = operation->put_Completed(handler.Get()); 
    
       ComPtr<IMFAsyncResult> spResult;
    
       //maybe I should pass some data in the first parameter?
       hr = MFCreateAsyncResult(nullptr, pCallback, punkState, &_spOpenResult);
    
       //the further processing will be done in the completion handler
        return  hr;
    }
    
    IFACEMETHODIMP MyClass::EndCreateObject( 
        _In_ IMFAsyncResult *pResult,
        _Out_  MF_OBJECT_TYPE *pObjectType,
        _Out_  IUnknown **ppObject)
    {
        OutputDebugStringW(__FUNCTIONW__);
        if (pResult == nullptr || pObjectType == nullptr || ppObject == nullptr)
        {
            return E_INVALIDARG;
        }
    
        HRESULT hr = S_OK;
        //get a random access stream 
        if(!_spFile)
        {
            return E_FAIL;
        }
    
        ComPtr<IRandomAccessStream> streamHandle;
        hr = _spStream.As(&streamHandle);
        if (FAILED(hr))
        {
            ::Microsoft::WRL::Details::RaiseException(hr);
        }
    
        //Do what you need with IRandomAccessStream!
        //...
    
        return S_OK;
    }
    
    IFACEMETHODIMP MyClass::CancelObjectCreation( 
        _In_ IUnknown *pIUnknownCancelCookie)
    {
        return E_NOTIMPL;
    }
    
    HRESULT MyClass::FileOpenCompletionHandler( IAsyncOperation<StorageFile*>* async, AsyncStatus status)
    {
        //file is open, call the invoke to carry one
    
        if (status == Completed) { 
            HRESULT hr = async->GetResults(_spFile.GetAddressOf()); 
    
            if (_spFile) { 
                ComPtr<IRandomAccessStreamReference> streamReference;
                hr = _spFile.As(&streamReference);
                if (FAILED(hr))
                {
                    ::Microsoft::WRL::Details::RaiseException(hr);
                }
    
                __FIAsyncOperation_1_Windows__CStorage__CStreams__CIRandomAccessStreamWithContentType * operation;    
                hr = streamReference->OpenReadAsync(&operation);
    
                if (FAILED(hr))
                {
                    ::Microsoft::WRL::Details::RaiseException(hr);
                }
    
                typedef IAsyncOperationCompletedHandler<IRandomAccessStreamWithContentType*> OpenReadAsyncHandlerDoneType; 
                ComPtr<OpenReadAsyncHandlerDoneType> handler(Callback<OpenReadAsyncHandlerDoneType>( 
                    this, &MyClass::FileOpenReadCompletionHandler)); 
    
                hr = operation->put_Completed(handler.Get()); 
            }
    
            return hr;
        }
        else { 
            OutputDebugStringW(L"Unexpected async status\n");
            return E_FAIL;
      } 
    
        return S_OK;
    }
    
    HRESULT MyClass::FileOpenReadCompletionHandler( IAsyncOperation<IRandomAccessStreamWithContentType*>* async, AsyncStatus status)
    {
        if (status == Completed) { 
            HRESULT hr = async->GetResults(_spStream.GetAddressOf()); 
    
            if (_spStream) { 
                _spOpenResult->SetStatus(S_OK);
                hr = MFInvokeCallback(_spOpenResult.Get());
                _spOpenResult.ReleaseAndGetAddressOf();
            }
            return hr;
        }
        else { 
            OutputDebugStringW(L"Unexpected async status\n");
            return E_FAIL;
      } 
    
        return S_OK;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to get the contents from this URL http://google.fr/ok in a NSString can
i need get protocol(HTTP, FTP, SSMTP, IMAP, ETC) from ip address and port with
I have 4 Tables (listed bellow) and need: get last 10 Chats from Room
I have two combobox. I need get some value from first combobox1 after combobox1
After load content to page using div.load('page.php'); I need get all of links from
I have table id, title, showCount . I need get TOP 10 row from
I need get documents from db by oid, like: Docs.objects(_id='4f4381f4e779897a2c000009') But how to do
I need get H264 stream from x264 encoder and make some kind of live
I need to find values inside this string: 10days25hours15minutes I need get the numbers
I need get selectedItemPosition from one spinner and use it in second spinner. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.