Category Archives: C++

Userful C++ links

Some useful links posted on the vcblog and others

Building 8.1 apps (Windows Phone and Windows Store) using Visual Studio “14” CTP2

CTP2 of VS14 available CTP2 for Visual Studio “14” Now Available

A new VC++ series on Channel 9 VC++ Bytes on Channel 9

Graphics Diagnostics in Visual Studio 2013 Update 3 RC

WebSocket client support added to the C++ REST SDK C++ REST SDK WebSocket client

C Runtime (CRT) Features, Fixes, and Breaking Changes in Visual Studio 14 CTP1
Compiler Switch Deprecation/Removal Changes in Visual Studio “14”
Project Support for Natvis
C++11/14 Feature Tables For Visual Studio 14 CTP1


Rolling out the developer program for IoT Rolling out the Windows Developer Program for IoT

Registration for CppCon is now open

Full text of the announcement from

Opening Keynote by Bjarne Stroustrup
September 7–12, 2014
Bellevue, Washington, USA

Registration is now open for CppCon 2014 to be held September 7–12, 2014 at the Meydenbauer Center in Bellevue, Washington, USA. The conference will start with the keynote by Bjarne Stroustrup titled “Make Simple Tasks Simple!

CppCon is the annual, week-long face-to-face gathering for the entire C++ community. The conference is organized by the C++ community for the community. You will enjoy inspirational talks and a friendly atmosphere designed to help attendees learn from each other, meet interesting people, and generally have a stimulating experience. Taking place this year in the beautiful Seattle neighborhood and including multiple diverse tracks, the conference will appeal to anyone from C++ novices to experts.

Bjarne Stroustrup

What you can expect at CppCon:

  • Invited talks and panels: the CppCon keynote by Bjarne Stroustrup will start off a week full of insight from some of the world’s leading experts in C++. Still have questions? Ask them at one of CppCon’s panels featuring those at the cutting edge of the language.
  • Presentations by the C++ community: What do embedded systems, game development, high frequency trading, and particle accelerators have in common? C++, of course! Expect talks from a broad range of domains experts focused on practical C++ techniques, libraries, and tools.
  • Lightning talks: Get informed at a fast pace during special sessions of short, less formal talks. Never presented at a conference before? This is your chance to share your thoughts on a C++-related topic in an informal setting.
  • Evening events and “unconference” time: Relax, socialize, or start an impromptu coding session.

CppCon’s goal is to encourage the best use of C++ while preserving the diversity of viewpoints and experiences, but other than that it is non-partisan and has no agenda. The conference is a project of the Standard C++ Foundation, a not-for-profit organization whose purpose is to support the C++ software developer community and promote the understanding and use of modern, standard C++ on all compilers and platforms.

The first 100 registrations get a big discount – quoting from the “registration” page:

Regular registration fee is $995 but the first 100 attendees can take advantage of Super Early Bird registration and pay only $695. After that, the Early Bird registration fee is $845 and is valid until the 1st of June. …

I intend to travel to the conference and will be looking forward to meeting you there!


Using resumable functions in the CxxReadFileComponent sample


Welcome back from holidays. A few weeks ago, I posted a note about updating the samples of my book to the November CTP of Visual C++. The main goal behind the update is to move away from using PPL tasks for WinRT asynchronous programming and instead use the new resumable functions available in the CTP.

Today is the beginning! The first sample I will talk about updating is the CxxReadFileComponent sample that discusses about building a C++ WinRT Component that can be consumed from other WinRT supported languages.

Before we begin:

  1. Get the updated sample here. We will use this sample as a starting point for our migration. Before we write actual code, it is important to note that the CTP is only supported along with Microsoft Visual Studio 2013.
  2. The CTP works with VS 2013. In case you do not have VS 2013, you can get either an express (free) edition or a trial edition here.
  3. In case you have not already downloaded the Visual C++ November CTP, please do so. You can download and install the CTP from this location.
  4. Install VS 2013 first and then the CTP.
  5. Time for action!!!

The first step is to migrate the solution from Microsoft Visual Studio 2012 to the 2013 version.

When you attempt to open the solution file in Visual Studio 2013, Visual Studio prompts you to retarget the solution for Windows 8.1 as shown in the dialog below. If you choose not to retarget, then you will have to install the Windows 8 development tools in order to build the solution.

For the purpose of this exercise, go ahead and retarget the solution to Windows 8.1 by first clicking on OK in the above dialog and then right click on the project in Solution Explorer and choose Retarget to Windows 8.1

Once you ask Visual Studio to retarget the solution to Windows 8.1, Visual Studio makes the necessary changes and opens the solution. Once the solution is fully loaded, right click on the CxxReadFileComponent project in Solution Explorer and choose Properties. In the Properties Dialog, under the Platform Toolset, choose Visual C++ Compiler Nov 2013 CTP (CTP_Nov2013) and click on OK.

The CxxReadFileComponent has one class named ReadFile. You can find the relevant code in the wrongly named files, Class1.h and Class1.cpp. The ReadFile class defines public methods that returns one of the IAsync* interfaces that all WinRT asynchronous methods are expected to return. This allows for consumption of such async operations from other languages. Before we go ahead with changing code, let’s open pch.h and add a new reference for a header. Add a new include reference for pplawait.h in pch.h which pulls in all the required declarations necessary for the new resumable functions.

Things to remember when using resumable functions in C++ for WinRT

  1. You cannot have resumable support for any WinRT method that returns one of the IAsync* interfaces.
  2. Only methods that return either a Task<T> or void can be resumable.

Making code changes

Now, it is time to make changes to code. Open Class1.cpp and navigate to the ReadBytes function. The original function is listed below:

Original ReadBytes function using PPL tasks:

You can see from the code above, using tasks and chaining them can become quite “messy”. With the new resumable functions, each task can be replaced with a single call to the underlying async API along with the __await keyword prepended to the API call. That’s it. No lambdas, no chaining etc.

Updated ReadBytes function using resumable functions:

task<UINT> ReadFile::ReadBytes(String^ fileName) __resumable


    StorageFolder^ item = KnownFolders::DocumentsLibrary;

    auto storageFile = __await item->GetFileAsync(fileName);

    auto istream = __await storageFile->OpenAsync(FileAccessMode::Read);

    auto reader = ref new DataReader(istream);

    return __await reader->LoadAsync(static_cast<UINT>(istream->Size));


Disclaimer: I have not added error handling. You can add proper if- checks and handle errors. The intention here is to show the ease of use of the resumable functions.

Changes made:

  1. All resumable methods have a __resumable identifier added at the end of the function declaration in both the header and the source files.
  2. Use the __await keyword when making calls to the WinRT Async APIs.
  3. That’s it!!

Similarly I made changes to the ReadBytesWithProgress function. The original function is listed below:

Original ReadBytesWithProgress function using PPL tasks:

Updated ReadBytesWithProgress function using resumable functions:

task<UINT> ReadFile::ReadBytesWithProgress(Platform::String^ fileName, Concurrency::progress_reporter<double> progress) __resumable


    StorageFolder^ item = KnownFolders::DocumentsLibrary;

    auto storageFile = __await item->GetFileAsync(fileName);;

    auto istream = __await storageFile->OpenAsync(FileAccessMode::Read);;

    auto reader = ref new DataReader(istream);;;

    return __await reader->LoadAsync(static_cast<UINT>(istream->Size));


With these changes made, build the solution and run the C# client test app. Make sure you have a text file named 127.txt in your Documents folder before you run the test app. Once you run the app, you can see that the app makes calls into your component and reads the number of bytes in the file using the updated methods, which really simplify writing asynchronous code using C++.

That’s it for today. See you soon for a next sample update. Stay tuned as this is getting very exciting!!


How To: Use XAML and DirectX with C++ and create a compelling Windows Store app

One of the great benefits of using C++ to write Windows Store apps is the ability to mix and match various components and create compelling user experiences. There are a variety of apps that use XAML and DirectX together and have built delightful user experiences. For example, there is the FreshPaint app in the Windows Store that allows free form panting using touch or the OneNote app which allows for, as you know, note taking using a stylus (along with keyboard support).

However, if you want to take a look at code and learn from the experts and masters who have built such apps, there are very few options. One such code base is Project Austin which is a sample built by the C++ team to demonstrate using C++ (and CX) along with XAML and DirectX to build a great note taking app. Today’s post, however, is not about Project Austin. It is about a cool sample built by a colleague and C++ enthusiast, Thomas Petchel. Tom built a cool app named Weathr, which he describes as “3D weather app for Windows 8.1 using C++, DirectX, and XAML“. I cannot agree more. This is the best weather app I have seen in a long time and it shows in the user experience. Tom has also made the sources available for anyone to check out and play with. If you are serious about learning how to build such great experiences in your Windows Store apps, please check out the code. And if you make changes to the code, please ensure you contribute back the changes. This ensures that all the folks get the new stuff!!

I can talk about code and design, but I would leave that out for fellow programmers. The app is not on the Store though. So if you want to get the app, you have to build the sources J

Cheers and Happy Holidays!


Power savings and performance benefits of writing code using C++

I get a few questions my way on an almost daily basis about how writing code using C++ results in savings in power consumption and other performance benefits. In this regard, I defer to the experts (Bjarne, Sutter etc) who explain these concepts with much more clarity and authority. So here you go:




The Windows Store opportunity for C++ developers

One of my colleagues sent this statement my way and I quote him “The advent of Windows Store combines a great app-development infrastructure with a reach of 250 million people and counting. This is a great opportunity for seasoned and new app developers alike. While Microsoft has published great examples, tutorials, and help, a more detailed and focused resource like the book, “Modern C++ and Windows Store apps” is a fantastic contribution to help developers profit from this opportunity.”

Many thanks Mike Wehinger


It’s time to move away from Turbo C++

You might be surprised to hear that a good number of colleges (at least in India) still rely on using the ages old Turbo C++ package to teach aspiring students C++. With a new language standard and great library support, it is now time to bid goodbye to Turbo C++. I answered a few questions about Turbo C++ and Modern C++ in this month’s edition of PCQuest (Thank you Hiren Mehta and other good folks from PCQuest). Attaching the Q&A below.

201306-PC Quest-Sridhar


While Visual Studio 2012 is a great tool for developing Windows apps using C++, there are also similar utilities for other platforms that support the C++11 standard. These include, but are not limited to, GCC, Clang etc. We owe it to aspiring students and should teach and train them on the latest language standard. In case you have not checked out Modern C++, I urge you all to check out the new language and you will be pleasantly surprised at the changes!!