Useful regular expressions for searching C++ code with Visual Studio

I’m generally more of a grep person but sometimes it’s easier to just use the built-in search in Visual Studio, especially if you want to be able to restrict the search to parts of your Visual Studio solution. Visual Studio does have pretty powerful search built in if you do use regular expressions instead of the default text matching. Here are a couple of regexes to get you started:

Find all shared_ptr calls that use “new” instead of the recommended make_shared: shared_ptr<.+>(new .+)

Find all empty destructors – very useful if you want to remove them in C++11 code: ~.+s+{s*}

How to turn off the shouty menus in Visual Studio, 2013 edition

Visual Studio 2013, much like its predecessor Visual Studio 2012, also “features” the SHOUTY uppercase menus. As in Visual Studio 2012, these can be turned off using a registry setting.

tl;dr – run this command in PowerShell:


Set-ItemProperty -Path HKCU:SoftwareMicrosoftVisualStudio12.0General -Name SuppressUppercaseConversion -Type DWord -Value 1

Visual Studio 2012 C++ Variadic Template support in the runtime library

As VS2012’s C++ compiler doesn’t support “true” variadic templates, the new runtime library classes that use variadic templates are implemented using macro magic behind the scenes. In order to get the “variadic” templates to accept more than the default of five parameters, you’ll have to set _VARIADIC_MAX to the desired maximum number of parameters (between five and ten).

For more information, see the “faux variadics” section of this blog post on MSDN.

If you want to remove a (C++) project from a Visual Studio 2010 solution

… make sure that you have removed all dependencies on the project that you are about to remove before you remove the project from the solution.

If you don’t, the projects that still have dependencies on the project you just removed will retain the dependencies, but the dependencies will have become invisible and the only way to rid yourself of the “phantom dependencies” is by editing the actual vxcproj files with a text editor and remove the dependency entry in there manually.

Don’t ask how long it took me to figure that out.

 

Quick tip if you see bad DLL or entry point’msobj80.dll’when building software with VS2008

Try stopping mspdbsrv.exe (the process that generates the pdb files during a build) if it is still running. My understanding is that it’s supposed to shut down at the end of the compilation but it seems that it can turn into a zombie process and if the latter happens, you can get the above error when linking your binaries.

Anyway, I just ran into this issue and stopping the process via the Task Manager resolved the issue for me.