Using Lambdas in MFC Applications – Dealing with C++ REST SDK

C++ REST SDK (also known as Casablanca) offers support for HTTP client/server, JSON, URI, asynchronous streams, WebSockets client, oAuth and PPL Tasks. We can get C++ REST SDK from CodePlex  or use the one shipped with Visual Studio 2013. This article gives suggestions of how to set up a Visual C++ project (particularly one that … Read more

Using Lambdas in MFC Applications – Replacing Callback Functions

According to C++11 Standard, stateless lambdas, i.e. having an empty lambda introducer or capture no variables, are implicitly convertible to function pointers. Visual C++ in Visual Studio 2012 and newer, supports this feature. Moreover, in Visual C++ stateless lambdas are convertible to function pointers with arbitrary calling conventions. This is great if have to deal … Read more

Using Lambdas in MFC Applications – Sorting Arrays

Beginning with Visual Studio 2010 which supports lambda expressions introduced by C++11 standard, you can handily sort an MFC array like in the following example: Sorting CStringArray by using a lambda expression // Example #1 // … CStringArray arr; arr.Add(_T(“John”)); arr.Add(_T(“Zorro”)); arr.Add(_T(“Sandy”)); arr.Add(_T(“Jimmy”)); // … bool bAscending = true; // … std::sort( arr.GetData(), // position … Read more

Codexpert – 2014 Articles Summary

Microsoft Libraries Multiple-View File Explorer Shows how to easily make a Windows file manager with multiple views by using MFC framework and IExplorerBrowser interface. MFC Support for Direct2D – Part 1 Using the MFC D2D classes for making a simple image viewer. MFC Support for Direct2D – Part 2 Demonstrates how to easily make a … Read more

C++11: Let’s Write a “Hello Lambda!”

A lambda expression (aka lambda function), introduced in C++11 standard, is a simplified notation for defining an anonymous function object. However, its syntax and using may look weird for many people so let’s try to make a simple program to accommodate with it. // Example #1 #include <iostream> int main() { [] () mutable throw() … Read more

C++ Gems: ref-qualifiers

VC++ 2014 is finally supporting ref-qualifiers, maybe a lesser know feature in C++11 that goes hand in hand with rvalue references. In this post I will explain what ref-qualifiers are and why they are important. But before talking about ref-qualifiers let’s talk about the well known cv-qualifiers. cv-qualifiers Let’s take the following example of a … Read more

User defined literals

The C++ language defines various built-in literals (numerical, character, string, boolean and pointer) and a series of prefixes and suffixes to specify some of them. The suffix or prefix is part of the literal. auto b = true; // boolean auto s = “sample”; // const char[7] auto i = 128; // int auto d … Read more

Five new algorithms to C++11 that you should know about

C++11 added a bunch of new general purpose algorithms to the <algorithm> header. In this article we will look at five of them that C++ developers should know about. all_of, any_of and none_of These are actually three, not just a single algorithm, all_of, any_of, none_of, but they are very similar. They check if the supplied … Read more

The standard way of converting between numbers and strings in C++11

In C++03 there was no standard way of converting numbers to strings. The best way to do that was using a std::stringstream: int n = 42; std::stringstream ss; ss << n; std::string s = ss.str(); One could put that into a more generic function that looks like this: template <typename T> std::string to_string(T const & … Read more

Codexpert – 2013 Articles Summary

C++ Language and STL <filesystem> header in Visual Studio 2012 Shows sample usage of filesystem header, new to VS2012, that defines types and functions for working with files and folders. C++11 concurrency: threads An introduction to threads support in C++11. C++11 concurrency: locks A walk through the synchronization mechanism for multi-threading provided by C++11. C++11 … Read more