In the previous post I have compared two alternative ways of transforming a string to upper case, both using std::transform: one that modifies an existing string and one that generates a new one by inserting at the end using std::back_inserter. For the second alternative I have presented two implementations, one that does an initial reservation for the newly created string and one that does not.

The curious conclusion of the tests was that the version with reserve was actually slower than the one that did not perform an initial reservation.

The solution was built with Visual Studio 2015 Update 2. As it was later noticed in the comments, the actual cause of that is a Microsoft optimization for std::string by using an array of 16 characters for strings that do not exceed this size and only dynamically allocate memory for larger strings. Since all the strings had a length between 3 and 12 characters, this optimization was used for all strings. Therefore, reserve() dynamically allocated memory that was never used and its execution time only added to the overall time.

To actually be able to test the performance of these two implementations with VC++, the strings should be larger than 16 characters. So I changed the code to generate strings between 17 and 25 characters long.

The results this time were totally different. The 3rd version with initial reserving was more performant than the one that did not do that. It can also be noticed that the more strings need to be transformed the more similar times it takes for all the versions.

No of strings time v1 time v2 time v3 Percentage of slowdown with v2 Percentage of slowdown with v3
1000 122 219 205 79.5 68.0
10000 1202 2178 2055 81.2 71.0
100000 13563 22758 21431 67.8 58.0
1000000 136160 225669 214149 65.7 57.3
10000000 1368034 2268991 2155969 65.9 57.6
100000000 23090172 27997658 27322888 21.3 18.3

In the chart below with blue it is represented the results for version 2 and with orange the results for version 3 (with initial reservation).
transform2

Note: Generating 100 milion strings between 17 and 25 characters require a lot of memory. In my tests it peaked to 13GB. So if you want to run the code you should be aware of this.

, , , Hits for this post: 582 .

UPDATE: For an update on the implementation and the conclusions see A comparison of two std::transform alternatives revisited.

I was writing a small utility function to transform a string to uppercase. The obvious solution for that is std::transform, but as I was writing it I realized there are several alternatives:

  • transform an existing string, by setting its elements to uppercase one by one
  • iterate over an existing string, and insert a copy of its uppercased elements into another string, initially empty, using std::back_inserter

Obviously, the second approach should be slower since it has to deal with buffer reallocations. However, I was curious how slower comparing to the first approach that would be. So I decided to test it.

UPDATE: It has been suggested that in the second version I should make a reserve of the string before using std::back_inserter to add characters to the string. Therefore I added a 3rd version that does that.

This is how I implemented the two version different versions of the helper function:

To test it, I decided to randomly generate strings. The length of the strings and their content is randomly generated. Both functions are tested with the same strings after a copy is initially done.

The results, tested with a 64-bit release build with Visual Studio 2015 Update 2, look like below. Times are in microseconds.

No of strings time v1 time v2 time v3 Percentage of slowdown with v2 Percentage of slowdown with v3
1000 40 57 64 42.5 60
10000 593 568 637 42.5 53.1
100000 3894 5769 6497 48.2 66.8
1000000 40005 57852 65793 44.6 64.5
10000000 394573 584048 734463 48 86.1
100000000 4298742 6171199 7577972 43.6 76.3

I have run this several times with similar results. The following image shows how much slower the versions using std::back_inserter were comparing with the version that modifies the string directly. With blue it is represented the results for version 2 and with orange the results for version 3 (with initial reservation).
transform

This clearly indicates that using std::back_inserter is slower, and it is actually 30 to 60% slower. However, what has surprized me is that reserving the necessary space for the string before std::back_inserter starts inserting elements is even slower (in some cases it can take twice as much time than version 1). Of course this measures the time to allocate the buffer too, not just the time for transforming the string, but the point here is to profile the entire function, not just the transform operation.

, , , Hits for this post: 748 .

Last week I have attended ITCamp in Cluj-Napoca, Romania. The conference has already established itself as the most important community-driven technology conference in Romania and lately, as the organizers put it, its focus has shifted from being a Microsoft-centric conference to a technology-centric conference. And this year it has been larger than ever before: 600 attendants, more than 40 speakers, more than 50 sessions and open panels grouped on 5 different tracks. A little bit for everybody. And with so many tracks and session it was a little bit hard to make choices for what to attend or maybe rather what to skip.

All sessions have been recorded and will be made available some time in the future (as far as I understood). In the meanwhile I wanted to point some of the things I seen and learnt at ITCamp. I actually attended more talks than the one mentioned here. Most of them were really good and I apologize to those not mentioned, but I don’t want to mention everything here, so I will try to summarize only a few things that I found the most interesting.

  • Security
    I have attended several talks on security. Paula Januszkiewicz gave all of us creeps by showing how a skillful person can extract information such as encrypted passwords and history information that the system stores on disk without most users being really aware of it. And even though the secrets are well kept for a regular user, a malicious person or software can exploit weaknesses to extract these information. On the other hand Jayson E. Street shared his experiences with compromising security in all sorts of companies around the world. Having a 100% success rate Jayson doesn’t blame it on the employees or users (explicitly saying there is no such thing as stupid user) but on the lack of education/training on security that companies are providing (or rather not providing) for their employees. His talks made us laugh but also think a lot and hopefully be more aware of things we shouldn’t do from the point of view of security. One thing for sure, I will never plugin a USB stick that I find on my desk in a blank envelope with my name on it. Thanks Jayson!

  • Internet of Things
    Who would have though several years ago that your greenhouse could be monitored and controlled from the internet? That it could send pictures to your phone? That you can make predictions on when and how much to sprinkle based on the existing data? That’s what Laurent Ellerbach, Microsoft Technical Evangelist Lead, shown in his keynote. Sensors, Raspberry PI, cameras, Azure IoT Hub, Stream Analytics, Mobile Services, SQL Azure and others working together to create a real world system for a sprinkler for his small greenhouse at home. It was a very interesting talk with a real life project and its development over time to include more and more services.
  • PowerShell is now an OOP language
    I am not very skilled with PowerShell, though I have to use it from time to time. I had no idea though that PowerShell 5 supports many features from object-oriented programming. These includes: classes, methods, properties, inheritance, enumerations and others. Razvan Rusu delivered an entertaining talk for both developers and sysadmins showing how easy you can do things in PowerShell and what the new OOP features are. It was really interesting and will certainly look at PowerShell from a different perspective from now on.
  • .NET core
    Raffaele Rialdi gave a compelling introduction to .NET core, its components, flavors, its new deployment mechanism based on NuGet and other related topics.
, , , , , , , Hits for this post: 2972 .

The Chromium Embedded Framework (CEF for short) is an open source framework for embedding Chromium-based browsers in other applications. The base implementation is targeting C/C++ applications but ports for other languages exist (these include Java, C#, Delphi, Python).

The nightly builds (for various systems and platforms) of CEF are available for download at https://cefbuilds.com/. These include:

  • CEF source code necessary to build your apps with
  • CEF dynamic and static library files (together with its dependencies) that you must use in your application
  • C++ wrappers for the C API
  • source code of two sample applications, one called CefSimple and one called CefClient
  • symbol files for debugging binary distribution of CEF
  • build of CefClient sample app with all dependencies and resources

Building the 64-bit version of the sample applications is not straight forward though. In this article I will show what you have to do make it work.

Prerequisites

The following prerequisites are necessary:

  • Visual Studio 2013
  • CMake tools

Notice: Though CMake should be able to generate projects for Visual Studio 2015, I was not able to make it happen. Moreover, the cef_sandbox.lib lib is built with Visual C++ 2013 which means the modules that are linking it should also be built with the same tool set.

You should download the nightly build of the development branch for Windows 64 bit and unzip it.

Create Visual Studio projects

To create Visual Studio projects run the following command from the CEF’s main folder in a console:

This will create:

  • a VC++ 2013 solution called cef.sln in the main folder
  • VC++ 2013 project files for libcef_dll, cefsimple, cefclient
  • two additional project files called ALL_BUILD and ZERO_CHECK

This is how the content of the CEF folder looks after generating the Visual Studio project and solution files.
cef3

This is how the Visual Studio solutions looks.
cef1

Create 64-bit configurations

Though the download is suppose to represent the 64-bit version of the framework, and the DLLs and LIBs in the Debug and Release folder (i.e. the CEF builds and its dependencies) are indeed built for the x64 platform, the generated projects do not have configurations targeting the x64 platform.

What you have to do is:

  • create configuration for targeting the x64 platform (by copying the settings from x86)
    cef7
  • change the Output Directory for all projects and configurations to be $(SolutionDir)$(Configuration)\ which means the output folder will be the existing Debug or Release folder from the main CEF folder.
    cef8
  • for the libcef_dll project change the Librarian > All Options > Additional options to /machine:X64 %(AdditionalOptions)
    cef9
  • for the cefsimple and cefclient projects change the additional dependencies settings to point to libcef.lib, libcef_dll_wrapper.lib and cef_sandbox.lib, instead of the relative paths as in the project.
    cef10
    This is how the list should look for all platforms and configurations:
  • for the cefsimple and cefclient projects add $(SolutionDir)$(Configuration)\ to the Library Directories for all configurations and platforms
    cef11
  • modify the Post Build Event for the cefsimple and cefclient projects to no longer copy files from the solution’s Debug and Release folders to the project’s Debug and Release folders.

    Initially, the post build event looks like this (for Debug configurations)

    It should be changed to look like this (beware at the output folder indicated by outputresource; it should be the Debug\Release folder in the main folder):

Resources

In the main folder there is a sub-folder called Resources. The entire content of this folder must be copied to the out folders, Debug and/or Release. These files are necessary for the sample applications to run properly.

Building and running

With all these in place you can build the projects. The build should succeed and the content of the Debug folder for instance should look like below.
cef4

You can then run the two sample applications. This is how cefsimple looks.
cef5

This is how cefclient looks.
cef6

, , , , , Hits for this post: 5099 .

C++17 was supposed to be a major update of the C++ ISO standard. After the Jacksonville meeting (29.02 – 05.03) it looks like it’s rather going to be a major disappointment. I’m not trying to downplay the things that have been voted into the C++17 standard so far, but all major features we hoped for this new version were moved out: modules, concepts, ranges, coroutines, uniform function call syntax.

Here is a brief report of the meetings, Trip report: C++ meeting at Jacksonville, and a quote of what was moved out for the next version:

Let me start enumerating the things we are not going to have in C++17:

  • Modules: They will not be in C++17, but in a separate technical specification. That is really a pity, as we will be for more years without having what I was expecting to let me get rid of the text substitution paradigm of the include directive as well as improve compilation times.
  • Concepts: They will not be integrated in C++17, but stay for now in their own technical specification. There were concerns about some issues in the TS, which I do not consider essential. Despite that there is implementation experience and even other TS depends on it, it was rejected to move concepts to the IS.
  • Ranges: This is a library solution highly depending on concepts. So, no way.
  • Coroutines: There was a very sound proposal with implementation experience. However, again this was targeted to another technical specification.

Besides that, we also will not have the half of uniform function call syntax that I thought was not controversial. To be clear, I really wanted both halves.

You can discuss on the report on reddit. The general feeling is disappointment though.

On a side note, standard C++ library in Visual Studio 2015 update 2 is C++17 feature complete (on what has been voted so far prior to the Jacksonville meeting).

, , , , , , Hits for this post: 5791 .

The C# Interactive window has been made available again in Visual Studio with the first update to 2015, this time as a REPL window. You can type or paste and execute C# code, and it includes support for adding references to external DLLs and using namespaces. The window is intended for rapid prototyping C# code.

It is available from Views > Other Windows > C# Interactive.
csrepl1

Here is a simple example where we declare an integer variable, increment its value and then print it.
csrepl3

You can write any C# code including lambdas and LINQ queries.
csrepl4
You can also define types and write functions.
csrepl8
csrepl9

If you want to use a namespace you must use the using directive just as you do in C#.
csrepl5

For references to additional DLLs (whether from the framework or custom) you use the #r command specifying the path to the module.
csrepl6
After you referenced a module you can use its namespaces and the types available there.
csrepl7

For a list of all commands use the #help command.

, , , , Hits for this post: 7325 .

I am building a hybrid mobile app with Visual Studio Tools for Apache Cordova that is able to make phone calls, send text message or emails, view a location on a map, etc. These are all handled with external applications (for instance use Gmail to send an email or Maps to pinpoint a location). They are placed in an anchor tag in HTML, such as <a href="tel:12345678">, <a href="sms:12345678">, <a href="mailto:name@domain.com"> or <a href="geo:...">. These work fine except that when you execute one of these actions and the system opens another app you see for a short time a webview with an error: “Web page not available”. Then the external app opens, you take the action and then go back to the app. At that point you again see this webview with the error as shown below.

ERR_UNKNOWN_URL_SCHEME when sending a text message

ERR_UNKNOWN_URL_SCHEME when sending a text message


This seem to be a known issue as I found many references of it on the web. Here are several for reference:

I am using the InAppBrowser plugin to open links in external apps. In order for this to work the schemes must be white-listed in Cordova’s config.xml file and the launch-external attribute should be set to true (which was already set in my case).

The indicated solution is to override WebView.shouldOverrideUrlLoading method.

I added the following in plugins\cordova-plugin-inappbrowser\src\android\InAppBrowser.java in the plugin’s WebView extension, but that did not work as the code did not even execute.

Looking for a solution I have noticed that this was only working OK for tel: and for others it was exhibiting this behavior. Then I found the following code in the InAppBrowser plugin class, in the execute() method.

I have changed that to include the other schemes and that fixed the problem.

With this in place, the web page error no longer shows up for any URL scheme.

I’m not sure if this is the best solution, but it is the only one that I managed to implement.

, , , , , , , Hits for this post: 14535 .

Visual Studio 2015 comes with many new features and improvements in the IDE, the debugger or language compilers. Obviously, there are more than three things I like in the new IDE, but three things have caught my attention from the very beginning.

The Error Window

vs2015error1
One of the things that bothered me the most about the error window was the mixture of errors/warnings/messages from both MSBuild and IntelliSense. But I don’t usually care about the later and their presence in the error window is usually annoying me. This is now fixed and you can select to see messages from Build, IntelliSense or both.
vs2015error2
In addition to this you can apply even more filtering:

  • You can select the source of the messages: Entire Solution, Current Project, Open Documents or Current Document.
    vs2015error3
  • You can search the error list, and the search includes the text in all the output list columns (Code, Description, Project, File or Line).
    vs2015error4
  • You can individually show or hide Errors, Warnings and Message (but this feature has been available for many years).

The Find in Files Append

I’m working with large source bases and I often need to do find in files, usually going from search to search until I find what I need. The problem was there were only two output windows for the search results and when you need to do a 3rd you had to discard one of the previous searches while you might still needed the results. I have requested for many years that Visual Studio should support more than two find results windows. I actually created a User Voice request a few years ago.

In Visual Studio 2015 they have implemented an append feature, were you could append your search results to one of the existing two windows.

vs2015find1

As a result the old search results are not discarded, but aggregated in a the form of a tree list in the search results window.

vs2015find2
vs2015find3

Though this is not what exactly I was expecting it provides the feature I was looking for with probably minimal changes to the Visual Studio IDE.

The Inline Create Definition (for C++)

I’m not sure how this feature is actually called, but what it does is creating a definition for a function in the source file from the declaration in the header and displays it in a boxed document inside the header document. Here is an example:

You declare a function/method in a header file. Visual Studio figures out the definition is missing.
vs2015inline1
Use the Quick Actions (CTRL + .) to create a definition of the symbol in the source file.
vs2015inline2
The definition is added to the source file that is opened as a document in a box just below the function declaration.
vs2015inline3
I find this very useful to get going with a new function. Of course for writing larger functions you’ll probably switch to the actual document tab where the source file is opened.

With these new features only Visual Studio has become much more productive for me. And there are plenty more.

, , Hits for this post: 9362 .

I have tried to assemble together information about the Visual C++ releases, the compiler and the frameworks (MFC and ATL). You can find these on many places, but it is often incomplete or focused on something particular (Visual Studio, C++ compiler, framework, etc.).

The table below is the result of this effort. It is incomplete because it’s not easy to find information about products released more than two decades ago, but if you can help filling in the gaps please drop a comment with the information you have and I will update the table.

Product Codename Release date C++ version _MSC_VER MFC version _MFC_VER ATL version _ATL_VER
C 1.0 100
C 2.0 200
C 3.0 300
C 4.0 400
C 5.0 500
C 6.0 1990 600
C/C++ 7.0 1992 700 1.0 0x0100
Visual C++ 1.0 Caviar 1993 1.0 800 2.0 0x0200
Visual C++ 1.1 Barracuda 1993 1.1
Visual C++ 1.5 Dolphin 1993 1.5 850 2.5 0x0250
Visual C++ 1.51 1.5
Visual C++ 1.52 1.52
Visual C++ 1.52b 1.52b
Visual C++ 1.52c 1.52c
Visual C++ 2.0 2.0 900 3.0 0x0300
Visual C++ 2.1 2.1
Visual C++ 2.2 2.2
Visual C++ 4.0 Olympus 1995-12-11 4.0 1000 4.0 0x0400
Visual C++ 4.2 4.2 1020 4.2 0x0420
1.0 0x0100
1.1 0x0110
2.0 0x0200
Visual Studio 97 Boston 1997-04-28 5.0 1100 4.21 0x0421 2.1 0x0210
Visual Studio 6.0 Aspen 1998 6.0 1200 6.0 0x0600 3.0 0x0300
Visual Studio .NET 2002 Rainier 2002 7.0 1300 7.0 0x0700 7.0 0x0700
Visual Studio .NET 2003 Everett 2003 7.1 1310 7.1 0x0710 7.1 0x0710
Visual Studio 2005 Whidbey 2005 8.0 1400 8.0 0x0800 8.0 0x0800
Visual Studio 2008 Orcas 2008 9.0 1500 9.0 0x0900 9.0 0x0900
Visual Studio 2010 Dev10 2010 10.0 1600 10.0 0x0A00 10.0 0x0A00
Visual Studio 2012 Dev11 2012-08-15 11.0 1700 11.0 0x0B00 11.0 0x0B00
Visual Studio 2013 Dev12 2013-10-17 12.0 1800 12.0 0x0C00 12.0 0x0C00
Visual Studio 2015 Dev14 2015-07-20 14.0 1900 14.0 0x0E00 14.0 0x0E00

Several notes on the history of VC++:

  • Visual Studio 97 was the first product that bundled together several products (Visual C++, Visual Basic, Visual J++)
  • Visual Studio 6.0 is the only version of Visual Studio that was not named after the release year, but the version number
  • MFC was first release in 1992 with C/C++ 7.0
  • MFC 6.0 released with Visual Studio 6 did not change the name of the MFC DLLs, that were still named mfc42.dll
  • ATL was first released in between Visual C++ 4.2 and Visual Studio 97. The first release of the framework to be included in a product was ATL 2.1 released with Visual Studio 97
  • Visual C++ version 3.0 was skipped to 4.0 to align the product version with the MFC version, whose next version was 4.0
  • Visual Studio 2015, the compiler and framework version are 14.0 and not 13.0, a number which was skipped (for the good old superstitions)
  • _MFC_VER and _ATL_VER macros were initially incorrectly documented in MSDN as 0x1000 instead of 0x0A00

References

, , , Hits for this post: 13796 .

If you work on a Apache Cordova project in Visual Studio 2013 using Visual Studio Tools for Apache Cordova CTP 3 or 3.1 you should know there are important breaking changes in migrating the project from Visual Studio 2013 to Visual Studio 2015. The project can be migrated, but you have to do everything manually, as Visual Studio is not able to apply the changes automatically.

First of all, Visual Studio Tools for Apache Cordova CTP3.x are not longer supported in Visual Studio 2013 in the first place. If you try to install Update 5 it will prompt you to remove it before continuing.
vs2013u5
This is explained in the release notes for Update 5.

Also note: All prior releases of the Tools for Apache Cordova are incompatible with Update 5. If you have previously installed a Tools for Apache Cordova CTP extension, you must uninstall that extension before installing Visual Studio 2013 Update 5. If you require Apache Cordova support, we encourage you to try Visual Studio 2015.

The options for those developing with the VS tools for Apache Cordova in VS2013 are either to switch to Visual Studio 2015 or not install the last update and continue to work with CTP 3.x in VS2013.

In this article I will show you how to migrate a Cordova application from VS2013 to VS2015 and I will exemplify with a test application.

I have this app called TestApp. It’s built with Ionic and AngularJS. It is a JavaScript app, not a TypeScript app, but this works just the same regardless what language you use. It has the following project structure, with the Javascript source code in a folder called app, the libraries in libs and the templates in views. There are other folders apart from the ones VS has created, mainly css and images.

vs2013proj1 vs2013proj2

The application is just a test, it doesn’t do anything but it works for both Android and iOS.

ripple1 ripple2

When you open this project in Visual Studio 2015 it is not loaded. Visual Studio complains that “This project is incompatible with the current edition of Visual Studio.”
vs2015proj1
You have to covert it manually in order to make it available for Visual Studio 2015. Fortunately, the steps to do this are documented, but not in MSDN as one might expect, but on GitHub. There is a document called Known Issues – Visual Studio 2015 that explains what has to be done.

  • Create a new empty Apache Cordova app. The only purpose of this app is to copy from files to your actually project.
    vs2015proj2
  • Copy the .jsproj and taco.json files into the project folder of the application you migrate. Make sure you overwrite the existing .jsproj with this new project file.
  • Delete the existing bin and bld folders
  • Create a folder called www
  • Move everything except for config.xml and folders merges, res and plugins to the www folder.

If you open the project again in Visual Studio 2015 it will work and you can build and run it. For my test application the new project looks like this.
vs2015proj3

You can see that the all the folders and files under the www folder appear automatically in the solution explorer. They are not added with a Content or Folder element in the .jsproj file. You can make a comparison of the old and new .jsproj and see how simplified the new file is.
jsprojcompare1

Another thing to notice here is that the NodeJS module used for building the project is no longer called vs-mda (i.e. Visual Studio Multi-Device Application) but vs-tac (i.e. Visual Studio Tools for Apache Cordova).
jsprojcompare2

However, when I tried to build I got the following error:

MSBUILD : cordova-build error BLD401: Error : BLD00401 : Could not find module ‘delayed-stream’] code: ‘MODULE_NOT_FOUND’. Please Go to Tools –> Options –> Tools for Apache Cordova –> Cordova Tools –> Clear Cordova Cache and try building again.

This might have been related to the version of Apache Cordova I had globally installed, i.e. 5.1.1. If you get the same install it via npm.

However, you may still get problems when you try to build for Android.

MSBUILD : cordova-build error BLD10205: Please install Android target “”
You may not have the required environment or OS to build this project
MDAVSCLI : error : cmd: Command failed with exit code 2

The Android target name is empty, but if you do a Rebuild you get more information and actual required target name:

[Error: Please install Android target: “android-21”.

Hint: Open the SDK manager by running: C:\Program\ Files\ (x86)\Android\android-sdk\tools\android.BAT
You will require:
1. “SDK Platform” for android-21
2. “Android SDK Platform-tools (latest)
3. “Android SDK Build-tools” (latest)]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\ApacheCordovaTools\vs-mda-targets\Microsoft.MDA.FileMirroring.targets(352,5): error MSB3073: The command “platforms\android\cordova\clean.bat” exited with code 2.

These can be installed using the Android SDK Manager. Make sure you select all the mentioned components.
android1
With these changes you can build successfully for Android.

One more thing here is the version of Apache Cordova used by vs-tac to build. vs-tac uses Cordova 4.3.1, but I already had Cordova 5.1.1 installed on my machine and used by vs-mda. If you have a newer Cordova version than 4.3.1 what you have to do instruct vs-tac to use this one in the taco.json file.

Replace the version 4.3.1 of the cordova command line interface with desired version (in my case 5.1.1). When you rebuilt it will install it and build with it.

Your environment has been set up for using Node.js 0.12.7 (x64) and npm.
—— Ensuring correct global installation of package from source package directory: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\ApacheCordovaTools\packages\vs-tac
—— Name from source package.json: vs-tac
—— Version from source package.json: 1.0.0
—— Package already installed globally at correct version.
—— Installing Cordova tools cordova@5.1.1 for project from npm. This could take a few minutes…

You can find the various Cordova versions installed under %APPDATA%\npm\node_modules\vs-tac\node_modules\cordova.
vstac3

For more information see:

, , , , Hits for this post: 14386 .