Home > C++, Windows Development > Visual Studio 2012 – Day 1 Annoyances (with an emphasis on C++)

Visual Studio 2012 – Day 1 Annoyances (with an emphasis on C++)

February 19, 2013 Leave a comment Go to comments

Update 21st February 2013: added information about Update 2, the C++11 Compiler November 2012 CTP (in two sections) and Find & Replace

Update 16th April 2013: the final version of Update 2 is now released; Update 1 is no longer needed (article updated)

So this is it, huh folks? 16 years of development, and the latest incarnation of the de-facto standard Windows development tool has an interface that might as well be from 1997. The compiler is not much better either it seems, as this C++11 feature support comparison shows: Visual Studio 2012 fails to include such basic support as initializer lists*, uniform initialization*, default and deleted constructors, inherited constructors and non-static data member initializers, while just about managing to shoehorn in raw string literals in the Update 1 package. Yet strangely, Microsoft managed to find time to implement SCARY iterators, checked iterators and futures and promises. SCARY iterators were only an optional part of the ratified C++11 standard.

But, the purpose of this article is to get your life in Visual Studio 2012 running smoothly, so let’s start with the basics.

* these features and others were added in the C++11 Compiler November 2012 CTP, see below

Getting rid of the all-caps menu bars

Open Windows PowerShell (if you don’t know how to do this, open a command prompt, type powershell and press Enter), and type:

Set-ItemProperty -Path HKCU:\Software\Microsoft\VisualStudio\11.0\General -Name SuppressUppercaseConversion -Type DWord -Value 1

(all on one line)

Then restart Visual Studio. Sadly there is not an option to shoot the HCI guru who made this design decision. It was nice of them to provide a registry override though, almost as if they knew everyone would hate it.

Themes you can use

Gone is the soothing blue theme of Visual Studio 2010, replaced with, apperently, “very light” or “very dark”. Fortunately, help is at hand. The Visual Studio 2012 Color Theme Editor includes a number of pre-made themes including the original blue, plus green, tan and a few others to ease the burden on your eyes.

It is worth noting that the forthcoming Visual Studio 2012 Update 2 will include the Visual Studio 2010 blue theme once more.

Install Update 2

It doesn’t seem to appear on Windows Update, so in case you missed it, be sure to download Visual Studio 2012 Update 2 from Microsoft’s web site. This is a cumulative update which also includes all of the changes in Update 1.

List of changes in Visual Studio 2012 Update 1

List of changes in Visual Studio 2012 Update 2 (also includes everything in Update 1)

Install The Latest Compiler

Visual Studio 2012’s C++ compiler includes some features of C++11 not present in Visual Studio 2010 (see list below). Since Visual Studio 2012 was released, Microsoft have published a preview of a new compiler with additional (but by no means complete) C++11 feature support. You can read all the details on the Visual C++ Team Blog post Announcing November CTP of the C++ compiler, now with more C++11, and download the Visual C++ Compiler November 2012 CTP here.

To use the November CTP compiler, you need to change the platform toolset on each project and build configuration that you want to use the compiler with. Right-click your project, choose Properties, and in the General tab change the Platform toolset from “Visual Studio 2012 (v110)” to “Microsoft Visual C++ Compiler Nov 2012 CTP (v120_CTP_Nov)” and click OK.

A couple of things to note:

  • the compiler is just that, a compiler; it doesn’t include any changes to the C++ standard library, which means that things like initializer lists on vectors will not work.
  • the new compiler breaks binary compatibility with the old one

The preview compiler may contain bugs and should not be used in production environments.

C++: intsafe.h fudge no longer required

If you have been wrapping your #includes of stdint.h and intsafe.h in #pragmas disabling warning C4005 (the headers had duplicate macro definitions in them), you can get rid of those fudges now. The new versions included with Visual Studio 2012 do not suffer this problem.

C++: problems with container iterators

The following simple piece of code compiled fine under Visual Studio 2010:

std::transform(&arr[0], &arr[arrSize], &arr[0], doSomething);

Debug builds of this will now give a warning such as:

c:\program files (x86)\microsoft visual studio 11.0\vc\include\algorithm(1066): warning C4996: ‘std::_Transform1’: Function call with parameters that may be unsafe – this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ ‘Checked Iterators’2> c:\program files (x86)\microsoft visual studio 11.0\vc\include\algorithm(1047) : see declaration of ‘std::_Transform1’

Release builds continue to work as expected. There are two solutions to this, assuming you don’t want to put up with or disable the warnings:

Use a so-called checked iterator. This is a non-portable Microsoft extension to the C++ standard library, and in this particular case, a checked array iterator ensures that the capacity of the array targeted in the above line of code is not exceeded by the number of elements that will be written to it (ie. a checked iterator avoids buffer overflows).

Consider the following code:

int a[5] = { 1, 2, 3, 4, 5 };
int b[3];

std::copy(&a[0], &a[5], &b[0]);

5 elements will be written to an array only large enough to store 3 (capacity of 3 elements), causing a buffer overflow and potentially a crash if other important data is overwritten or the code attempts to write to read-only memory.

A checked array iterator flags this up safely:

std::copy(&a[0], &a[5], stdext::checked_array_iterator<int *>(b, 3));

The template argument specifies the type of data in the array (as a pointer), and its arguments are the target location and capacity of the target. In this trivial example we can clearly see the problem, but in the case of dynamically allocated arrays whose sizes are set by variables whose values are only known at run-time, this can be handy.

If, like me, you don’t think you need proprietary C++ extensions to hold your hand and don’t want to make your code less portable, just disable the warnings by adding _SCL_SECURE_NO_WARNINGS to your pre-processor defines.

Getting Boost to work

This is actually fairly easy, you can just download Boost as normal and then grab some pre-compiled binaries as follows:

First download the Boost sources and headers and unpack them into a folder such as C:\Program Files (x86)\boost.

Then download the pre-compiled binaries for Windows. Pick the 32 or 64-bit version as appropriate (or both if you need them). The EXE will create a folder of libraries. Move them to C:\Program Files (x86)\boost\boost_x_yy_z\lib32 or lib64 where boost_x_yy_z is the version-named Boost folder you copied in the previous step. Then simply include the path to these libraries in the library paths for your project.

Find & Replace

It might just be me but pressing ALT+R to replace the next occurrence never seemed to work in Visual Studio 2010. This annoyance appears to be fixed in Visual Studio 2012 (assuming I didn’t just ruin the keyboard shortcuts in 2010). However, there has been one critical and breaking change to Find & Replace in Visual Studio 2012: regular expressions now use the .NET Framework syntax instead of the custom syntax used in previous versions.

What does this mean? Well, for example:

  • substitutions like \1 now have to be written as $1
  • lazy matching (matching as few characters as possible) now uses the “proper” regex syntax of *? and +? instead of @ and # before.
  • matches are now invalidated with (?!foo) instead of ~(foo)

A full list of changes can be found on the MSDN page Using Regular Expressions in Visual Studio. Be wary of this change if you use regular expressions in Find & Replace as you may get unexpected effects with the old syntax!

Where is WinDiff?

Good question. Gone, apparently, so you’re going to need a new file comparison tool if you are used to WinDiff.

There is a (ironically named) comparison of file comparison tools on Wikipedia that you might want to use as a starting point. So far I have preferred DevArt’s Code Compare, which is also very well integrated with the Visual Studio IDE itself, but can also be used separately. Another decent tool is Scooter Software’s Beyond Compare. These tools have both free and paid versions (the paid versions include such features as 3-way diff and primitive GUI-based merging). Unfortunately they both have two critical flaws compared to WinDiff:

  • you can’t see a merged view of the documents, only a side-by-side comparison
  • neither of them (nor many other free tools it seems) can detect moved lines in C++ code

You can obtain WinDiff online fortunately, however I would recommend the fork WinMerge instead (note: this doesn’t have a merged document view either). I wasn’t going to include this originally as it hadn’t been updated for 2 years, but it seems like development has recently resumed on it.

Setup Projects (.vdproj) are no longer supported

This is probably the most heinous omission of all the things changed in Visual Studio 2012. You can now develop applications but have no way to deploy them to anyone else’s computers. You have several options:

  1. InstallShield Limited Edition, a license for which is included in Visual Studio 2012, is in my opinion bloated and over-complicated
  2. Windows Installer XML (WiX Toolkit), a command-line based installer creator which parses XML files to generate the installer executable. Overkill and time-consuming for most of us.
  3. Caphyon Advanced Installer, which comes in five editions, the free one doing everything that Visual Studio 2010 Setup & Deployment Projects did and more. This is the installer packager I now use, and while it is more complex than the old Setup Projects, the results are good.

Additionally, Advanced Installer sports the ability to import not just existing Setup Projects from .vdproj files but also entire Visual Studio solutions, automatically calculating and including dependencies, pre-requisites and so on. In honesty, I had problems getting this to work, however creating a project from scratch worked fine. The software is also integrated with the Visual Studio IDE so you can create and edit Advanced Installer projects from within Visual Studio if you wish.

C++11 features which weren’t supported in Visual Studio 2010

It isn’t all bad news. Here is what Visual Studio 2012 does include beyond the previous version:

  • enum class (strongly-typed enumerations)
  • forward-declared enums
  • POD re-working; trivial and standard layout types recognized
  • range-based for loop (Visual Studio 2010 had a proprietary syntax for this; Visual Studio 2012 uses the official syntax)
  • override and final
  • atomics
  • futures and promises
  • SCARY iterators

More detailed information can be found in the MSDN C++11 Features (Modern C++) documentation.

C++11 features which weren’t supported in Visual Studio 2012 but are supported in the November 2012 CTP Compiler

The CTP adds the following C++11 features over the 2012 RTM compiler:

  • variadic templates
  • uniform initialization
  • initializer lists (but no C++ standard library support yet)
  • explicit conversion operator
  • raw string literals (but no Unicode string literals)
  • delegating constructors (but no inherited constructors)
  • function template default arguments

I’ll report on additional issues and annoyances as I find them.

  1. Andy
    April 5, 2013 at 12:45

    The SuppressUppercaseConversion registry entry doesn’t work anymore with Update 2. Also, custom lower case menu titles are converted to all caps. Thus, the old trick which worked for Office 2013 (manually renaming all menu titles) is rendered useless.

    How come that virtually everything in VS 2012 can be customized but there is intentionally no way to get rid of the ******* upper case menu titles?

  2. Andy
    April 5, 2013 at 13:02

    Have to correct myself: The registry entry still works. It turned out I ran VS2012 with another user by running it directly from the Update 2 installer. Sorry and forget what I said…

  1. No trackbacks yet.

Share your thoughts! Note: to post source code, enclose it in [code lang=...] [/code] tags. Valid values for 'lang' are cpp, csharp, xml, javascript, php etc. To post compiler errors or other text that is best read monospaced, use 'text' as the value for lang.

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: