我已安装在windows 10.0 visual studio 2017(15.2版) 我已经从VS2013迁移到VS2017用于我的项目(包括cpprestsdk)并使用co_await更改.then()方法。我在网上看过一些东西,但实际上我不能再编译我的解决方案了。 无法打开包含文件pplawait.h 忽略未知的选择' / await'
建议?
答案 0 :(得分:1)
在Visual Studio 2017和我使用C ++ / WinRT及其async
类型函数的MFC解决方案中使用协同程序,我有以下内容。
请参阅此问题和我的回答,其中包含使用concurrency
,std:async
和C ++ / WinRT协同程序的若干示例:C++11 threads to update MFC application windows. SendMessage(), PostMessage() required?
首先解决方案属性中的设置。
我正在使用的实际函数的源代码(带有co_await
的C ++ / WinRT异步函数):
#include <pplawait.h>
#pragma comment(lib, "windowsapp")
#include "winrt/Windows.Foundation.h"
#include "winrt/Windows.Web.Syndication.h"
// . . . other code
// sample function using co_await to retrieve an RSS feed which may take
// a while so we want to start it and then continue when the results are
// received. we are using one of the async functions of C++/WinRT to retrieve
// the RSS feed text. We require a pointer to a CMainFrame object which has
// the function we need to output the text lines to a displayed window.
winrt::Windows::Foundation::IAsyncAction myTaskMain(CMainFrame *p)
{
winrt::Windows::Foundation::Uri uri(L"http://kennykerr.ca/feed");
winrt::Windows::Web::Syndication::SyndicationClient client;
winrt::Windows::Web::Syndication::SyndicationFeed feed = co_await client.RetrieveFeedAsync(uri);
// send the text strings of the RSS feed list to an MFC output window for
// display to the user.
for (winrt::Windows::Web::Syndication::SyndicationItem item : feed.Items())
{
winrt::hstring title = item.Title().Text();
p->SendMessageToOutputWnd(WM_APP, COutputWnd::OutputBuild, (LPARAM)title.c_str()); // print a string to an output window in the output pane.
}
}