Can't use create_async() with WRL WinRT component

依然范特西╮ 提交于 2019-12-30 12:15:28

问题


I want to write a WinRT component with async support using WRL, but I found create_async() is undefined even I included the ppltask.h and using namespace concurrency How to create a background task with WRL pattern?

My function is like:

HRESULT GetStreamAsync([out, retval] IAsyncOperation<IRRandomAccessStream*>** operation);

I also try to use IThreadPoolStatics->RunAsync(), but seems it only can be used in case of IAsyncAction and without return value. Does anyone can help?


回答1:


concurrency::create_async is only usable in C++/CX (this may not be expressly stated in the documentation, but all of the possible return types are hat types, indicating it is only usable in C++/CX).

WRL includes the Microsoft::WRL::AsyncBase base class template, which you can derive from to implement asynchronous operations using C++ and WRL.

I don't know of a canonical implementation that wraps std::future or concurrency::task, but you can find an example of an implementation in the Boost-licensed CxxReflect library (search for async_operation_base and task_based_async_operation).



来源:https://stackoverflow.com/questions/12890841/cant-use-create-async-with-wrl-winrt-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!