locked
error code for IAsyncOperationWithProgress

    Question

  • Hello all,

    I have implemented a socket client for my app. There is a async read interface like this:

    IAsyncOperationWithProgress<IBuffer^, unsigned int>^ CSmiHttpClient::ReadAsync(IBuffer^ buffer, 
    			unsigned int count, InputStreamOptions options)
    {
    	m_psBuffer = buffer;
    	m_readCompleteEvent = task_completion_event<void>();
    
    	m_cancellationTokenSource = cancellation_token_source();
    
    	mCurReadOp = create_async([this](progress_reporter<unsigned int> progress) {
    		task<void> task1 = create_task(m_readCompleteEvent, m_cancellationTokenSource.get_token()).then([this, progress]{
    			if (is_task_cancellation_requested())
    			{
    				cancel_current_task();
    				return;
    			}
    			progress.report(100);
    		});
    		
    		return m_psBuffer; 
    	});
    }

    And i process async call via IAsyncOperationWithProgressCompletedHandler.

    IFACEMETHODIMP CReceiveOperation::Invoke( 
        _In_opt_ IAsyncOperationWithProgress<IBuffer*, UINT32> *asyncInfo, AsyncStatus status )
    {
        if (asyncInfo == nullptr)
        {
            return E_POINTER;
        }
    
        ComPtr<IBuffer> spWinRtBuffer;
        HRESULT hrResult = asyncInfo->GetResults(&spWinRtBuffer);
        ComPtr<IMFAsyncResult> spResult;
        ComPtr<IAsyncInfo> spAsyncInfo;
        ComPtr<IInputStream> spInputStream;
        ComPtr<IDataReader> spDataReader;
        DWORD cbBufferLen = 0;
    
        if (SUCCEEDED(hrResult))
        {
            hrResult = spWinRtBuffer->get_Length(&_cbRead);
        }
    
        if (SUCCEEDED(hrResult) && _cbRead == 0)
        {
            hrResult = MF_E_NET_READ;
        }
    
        ComPtr<IUnknown> spThisUnk;
        HRESULT hr = this->QueryInterface(IID_PPV_ARGS(&spThisUnk));
    
        if (SUCCEEDED(hr))
        {
            hr = MFCreateAsyncResult(spThisUnk.Get(), _spCallback.Get(), _spState.Get(), &spResult);
        }
    
        if (SUCCEEDED(hr))
        {
            spResult->SetStatus(hrResult);
            hr = MFInvokeCallback(spResult.Get());
        }
    
        if (SUCCEEDED(asyncInfo->QueryInterface(IID_IAsyncInfo, &spAsyncInfo)))
        {
            spAsyncInfo->Close();
        }
    
        return hr;
    }

    Now i want to return some error code when network is bad, how can i set the error code for IAsyncOperationWithProgressCompletedHandler?

    thanks


    haha

    Monday, May 19, 2014 10:05 AM

All replies

  • I am trying to understand the question: Do you want to know how to set an hr in IAsyncOperationWithProgress, or how to check the network status?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, May 19, 2014 7:58 PM
    Moderator
  • Yes, you are right.

    haha

    Tuesday, May 20, 2014 1:31 AM