locked
How to handle the class IBuffer in my interface

    Question

  • Hi: all

    I want to write a Ansync ReadData API like the  ReadAsync API of IInputStream,

    Windows::Foundation::IAsyncOperationWithProgress<Windows::Storage::Streams::IBuffer^, unsigned int>^ ReadAsync(Windows::Storage::Streams::IBuffer^ buffer, unsigned int count, Windows::Storage::Streams::InputStreamOptions options)

     I want to send the byte data to the caller of this Ansync Read API, But I do not know how to use the parameter "IBuffer^buffer",

    Below is my codes of the API :

    IAsyncOperationWithProgress<IBuffer^, unsigned int>^ INetworkIORandomAccessStream::ReadAsync(IBuffer^ buffer, unsigned int count, InputStreamOptions options)
    {
    
    	return create_async([this](progress_reporter<unsigned int> progress) {
    		//How to send the byte data in this case
    		//return (IBuffer^)buffer; 
        });
    
    }

    Please give me some help . Thanks

    Wednesday, March 28, 2012 10:45 AM

Answers

  • Hi Pitt.Chen,

    To access the data in the buffer query the IBuffer for its IBufferByteAccess interface.

    --Rob

    Wednesday, March 28, 2012 8:36 PM
    Owner
  • Hello,

    We can not return two value in IAsyncOperationWithProgress. You can use int* to get the int return value, and the unsigned int should be uint32 in C++/CX. Please follow these codes:

    // In .h file
    using namespace Windows::Storage::Streams;
    		Windows::Foundation::IAsyncActionWithProgress
    <IBuffer^>^ ReadAsync(IBuffer^ buffer, unsigned int count, InputStreamOptions options,int* outcount);
    
    
    
    // In .cpp file
    using namespace Windows::Foundation;
    using namespace Windows::Foundation::Collections;
    using namespace Concurrency;
    
    IAsyncActionWithProgress<IBuffer^>^ WinRTComponent::ReadAsync(
    IBuffer^ buffer, unsigned int count, InputStreamOptions options, int* outcount)
    {
    	return create_async([this](progress_reporter<IBuffer^> progress) {
    		//How to send the byte data in this case
    		//return (IBuffer^)buffer; 
    		});
    }

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Jesse Jiang Monday, April 09, 2012 1:35 AM
    Thursday, March 29, 2012 10:53 AM

All replies

  • Hi Pitt.Chen,

    To access the data in the buffer query the IBuffer for its IBufferByteAccess interface.

    --Rob

    Wednesday, March 28, 2012 8:36 PM
    Owner
  • Hello,

    We can not return two value in IAsyncOperationWithProgress. You can use int* to get the int return value, and the unsigned int should be uint32 in C++/CX. Please follow these codes:

    // In .h file
    using namespace Windows::Storage::Streams;
    		Windows::Foundation::IAsyncActionWithProgress
    <IBuffer^>^ ReadAsync(IBuffer^ buffer, unsigned int count, InputStreamOptions options,int* outcount);
    
    
    
    // In .cpp file
    using namespace Windows::Foundation;
    using namespace Windows::Foundation::Collections;
    using namespace Concurrency;
    
    IAsyncActionWithProgress<IBuffer^>^ WinRTComponent::ReadAsync(
    IBuffer^ buffer, unsigned int count, InputStreamOptions options, int* outcount)
    {
    	return create_async([this](progress_reporter<IBuffer^> progress) {
    		//How to send the byte data in this case
    		//return (IBuffer^)buffer; 
    		});
    }

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Jesse Jiang Monday, April 09, 2012 1:35 AM
    Thursday, March 29, 2012 10:53 AM