我已经在windows10.0 visual studio 2017 (版本15.2)上安装了我已经为我的项目(包括cpprestsdk)从VS2013迁移到VS2017,并使用co_await更改了.then()方法。我在网上读过一些东西,但实际上我不能再编译我的解决方案了。无法打开包含文件pplwait.h,忽略未知操作'/await‘
有什么建议吗?
发布于 2018-06-10 04:10:10
在Visual Studio2017中使用协程,并在MFC解决方案中使用C++/WinRT及其async
类型函数,我有以下几点。
另请参阅此问题和我的答案,其中包含在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.
}
}
https://stackoverflow.com/questions/44596349
复制相似问题