pplawait.h / experimental/resumable for co_await doesn't work - c++

I have installed on windows 10.0 visual studio 2017 (version 15.2)
I have migrating from VS2013 to VS2017 for my project (that include cpprestsdk) and change .then() method with co_await. I have read something on the web but actually i can't compile my solution anymore.
Cannot open include file pplawait.h
ignoring unknown opion '/await'
Suggestions?

Using coroutines with Visual Studio 2017 and an MFC solution into which I am using C++/WinRT with its async type functions, I have the following.
See as well this question and my answer which contains several examples of using coroutines with concurrency, std:async and C++/WinRT: C++11 threads to update MFC application windows. SendMessage(), PostMessage() required?
First of all settings in the solution Properties.
Configuration Properties -> General -> Platform Toolset Visual Studio 2017 (v141)
C/C++ -> All Options -> Additional Options -> /await
C/C++ -> All Options -> C++ Language Standard ISO C++17 Standard (/stdc++17)
And the source code for the actual function that I am using (C++/WinRT async function with co_await):
#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.
}
}

Related

OpenCASCADE 7.6.0 not compiling with a .NET 6.0 class library with Visual Studio 2022 (Windows 10)

Steps to reproduce:
Install a version of Visual Studio (I used VS Community 2022). Install OpenCASCADE 7.6.0.
Create a C++ .NET CLR project using Visual Studio 2022 targeting .net6.0.
Change settings to include OpenCASCADE header and library files.
Edit the main header by replacing the code within it with below:
#pragma once
//for OCC graphic
#include <OpenGl_GraphicDriver.hxx>
//wrapper of pure C++ classes to ref classes
#include <NCollection_Haft.h>
namespace ClrClsLibDotNetCoreMwe {
public ref class Class1
{
// TODO: Add your methods for this class here.
};
}
Attempt to build.
Issue: The build fails with the following complain:
1>C:\OpenCASCADE-7.6.0-vc14-64\opencascade-7.6.0\inc\NCollection_DefaultHasher.hxx(34,1): error C2872: 'HashCode': ambiguous symbol
1>C:\OpenCASCADE-7.6.0-vc14-64\opencascade-7.6.0\inc\NCollection_DefaultHasher.hxx(34,1): message : could be 'HashCode'
1>C:\OpenCASCADE-7.6.0-vc14-64\opencascade-7.6.0\inc\NCollection_DefaultHasher.hxx(34,1): message : or 'System::HashCode'
What fixes the problem:
Either Targeting .NET Framework instead of .NET Core (/clr instead of /clr:netcore).
Or removing one of the headers.
Please see if there is a way where I can keep both the headers and target .NET Core?
I have looked around for a possible solution before posting this question here. A promising solution was to disable implicit usings. However, that didn't pan out.
I had the same problem.
In my case, the "using namespace System;" included in the header file. The text caused the problem.
Thanks!

WinRT GetSystemIdForPublisher() unable to execute due to C++20 coroutines?

I am trying to get the system ID using
auto info = winrt::Windows::System::Profile::SystemIdentification::GetSystemIdForPublisher();
auto id = info.Id();
auto asHex = winrt::Windows::Security::Cryptography::CryptographicBuffer::EncodeToHexString(id);
But when I try to run this code I get errors E0035 and C1189 and both have the exact same description:
The <experimental/coroutine> and <experimental/resumable> headers are only supported with /await and implement pre-C++20 coroutine support. Use coroutine for standard C++20 coroutines.
(Note: the italic coroutine above is inside <>, as soon as I put <> around the a word it disappears so I have omitted it)
I am including all the relevant files in my header that I think might be needed:
#include <Windows.h>
#include <coroutine>
#include <windows.foundation.h>
#include <winrt/Windows.System.Profile.h>
#include <winrt/Windows.Security.Cryptography.h>
I am using:
Microsoft Visual Studio Community 2019
Microsoft Visual C++ 2019
Windows 10 SDK 10.0.19041.0
In your project, if you go to
Property Pages ->
Configuration Properties ->
General ->
C++ Language Standard,
do you by any chance have it set to "ISO C++20 Standard (/std:c++20)"?
C++/WinRT only runs C++17.
A few hours ago I realized that C++/WinRT exists, and I am currently trying understand the fundamentals of it. If my memory serves me correctly, I also got this exact error message when trying some not-at-all-copy-pasted-from-msdn code out. Although I am using Visual Studio 2022 (Community Edition), I do not see why that would make a difference.
I hope this is of any use.
Kind regards,
a not so experienced programmer

How do I set up Visual Studio with default headers and comments?

I am fairly new to using Visual Studio. Currently I am using Visual Studio 2015 version. Currently when I set up a new C++ console application project (with Precompiled header off or on) it displays the following:
// Name of project.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int main()
{
return 0;
}
Every time I create a new project I have to waste my time entering in my header information and comments. I would like it to look like this every time I create a new C++ console application project.
// *********************************************************************
// Name:
// Description:
// Date:
// Class Section:
// Title:
// *********************************************************************
//Heading information
#include <iostream>
#include "stdlib.h"
#include "stdafx.h"
using namespace std;
//Main function
int main()
{
//Pause system and end main function
system("pause");
return 0;
}
Is it possible to set up Visual Studio 2015 to display the code above every time I create a new project? Thanks
Create a new console application.
Edit the file to be as you want it in the new one.
Select "Export Template..." in the "File" menu.
Walk through the wizard (choose a name for your new template, etc.)
Be sure the "Automatically import the template into Visual Studio" is checked.
Restart VS
Select "New Project"
Select "Visual C++" in the tree control on the left
Select your new template in the list in the middle
The usual new-project stuff (name and location for the project, etc.)
[Note: As I'm writing this, I'm looking at it in VS 2013. I don't recall it's changing in VS 2015, but it's possible.]

Visual Studio 2013 Express - How do I add resources?

I'm currently linking to the >dynamic< libs in SFML but I have no idea how to add resources in Visual Studio 2013 Express C++. I've quite recently started out with C++, coming from C# where adding resources is as simple as drag-n-drop.
I know there's something with .rc files and headers, but I didn't find any guide on it. What I need to do is add the dll's so I don't have to manually paste them with the .exe and I also need to add .png's. Right now I'm loading them from a folder next to the executable, I don't wanna do that.
How do I do this?
You can just add an [.rc] file to the project.
An [.rc] file is a purely textual resource script that you can edit as text, or you can use various 3rd party resource editors (you don't need that for adding image resources, just check out the RC syntax).
Visual Studio Express lacks resource editors, but does support automatic recognition of, compilation of and linking of resources.
Example
Here's an example [.rc] file, just a single line, using a free icon that I just downloaded from the net:
100 ICON "resources\\Bad-Blood-Yolks-Grin.ico"
Corresponding C++ source code, presenting the icon in a message box:
#undef UNICODE
#define UNICODE
#include <windows.h>
auto main() -> int
{
MSGBOXPARAMS params = {sizeof( params )};
params.hInstance = GetModuleHandle( nullptr );
params.lpszText = L"Click OK to dismiss this box.";
params.lpszCaption = L"Καλὴ τύχη!"; // "Good luck!" in Greek.
params.dwStyle = MB_USERICON;
params.lpszIcon = MAKEINTRESOURCE( 100 );
MessageBoxIndirect( &params );
}
Result:
All done in Visual C++ Express for Desktop 2013, or whatever it calls itself. :-)
In order to synchronize identifiers between resource script and C or C++ code it's common to include a header. The resource compiler understands the most basic C preprocessor directives.
Oh, also, I added the [.rc] file as just a text file. Visual Studio Express reacts to the renaming, "rc" file extension, by popping up a warning box that it isn't supported. Just ignore the box, and to edit the file right-click and choose text editor.

Creating CMFCDesktopAlertWnd Control in Visual C++

MSDN contains an example for creating a desktop alert window:
http://msdn.microsoft.com/en-us/library/bb983515.aspx
The sample code starts with the following declaration.
CMFCDesktopAlertWnd* pPopup = new CMFCDesktopAlertWnd;
When I use it in my code, the compiler complains
'CMFCDesktopAlertWnd' : no appropriate default constructor available
This is the complete source code of my application.
(I created an empty Win32 project in Visual Studio and set
the Use MFC in a Shared DLL option on the Property | General page.)
#include <afxwin.h>
#include <afxDesktopAlertDialog.h>
class Notifier : public CWinApp
{
public:
virtual BOOL InitInstance();
};
BOOL Notifier::InitInstance()
{
CMFCDesktopAlertWnd* pPopup = new CMFCDesktopAlertWnd;
return TRUE;
}
Notifier myApp;
What am I doing wrong?
The effect is the same in VS Express 2008 and the full version of VS 2010.
Are you using VS 2008 SP1? (The service pack is important)
Are you including the proper headers in stdafx.h? More specifically, you need
#include < afxext.h >
#include < afxcontrolbars.h >
to be able to use MFC Next (feature pack) classes.
It won't work on VS Express anyway because that doesn't include MFC.