When you run your (unmanaged/C++) application in debugger, you see at the end a report of memory leaks (if any are detected). Something like this:

Detected memory leaks!
Dumping objects ->
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {381} normal block at 0x001FFC30, 54 bytes long.
Data: < x > 0C 00 B9 78 12 00 00 00 12 00 00 00 01 00 00 00
d:\marius\vc++\memoryleakstest\memoryleakstestdlg.cpp(163) : {380} normal block at 0x001FFBF0, 4 bytes long.
Data: <@ > 40 FC 1F 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\thrdcore.cpp(306) : {374} client block at 0x001FFA38, subtype c0, 68 bytes long.
a CWinThread object at $001FFA38, 68 bytes long
Object dump complete.

Some of them can be fixed immediately, because when you double click on them Visual Studio will take you to the line where the allocation was made. Some of them are harder to spot, because Visual Studio is not able to do the same. Question is how do you find the source of those allocations? Luckily, there is this global variable called _crtBreakAlloc, that can be used to force the debugger to stop the execution when a certain block is allocated.

In order to use that, you should follow several steps:

  • First, you have to find a reproducible sequence that produces the same memory allocation number. When memory blocks are allocated, they are identified with a number, called allocation number. This number is reported by Visual Studio in brackets when it lists the memory leaks (e.g. {381}).
  • Second, you have to put a breakpoint somewhere in your program to force a stop at the beginning of the execution. That means you could use function main(), your CWinApp derived class constructor, function InitInstance() or other, depending on your application type and how early in the execution of the program the block that leaks is allocated. The smaller the allocation number is, the earlier in the execution the allocation occurs.
  • Run your program in debugger.
  • When the program stops (at the first breakpoint) open the Watch window and add the following expression: {,,msvcr90d.dll}_crtBreakAlloc in the Name column. In the Value column (which by default should have the value -1) write the allocation number. Take notice that msvcr90d.dll (which is the DLL that contains the C++ runtime library) is specific to Visual Studio 2008 (and is the debug version). If you use another version of Visual Studio, you have to use the appropriate DLL.
  • Continue debugging.
  • When the block identified by the allocation number set in the Watch window is allocated, the debugger will stop the execution and jump to a line from dbgheap.c.

    In order to see the line in your code that triggered the allocation, open the Call Stack window and find, from top down, the first function from your own code.

    That will lead you to the source of the memory leak.

To read more about this topic see:
How to: Set Breakpoints on a Memory Allocation Number
How to use _crtBreakAlloc to debug a memory allocation

, Hits for this post: 1061 .

A week ago I was reporting about the problems I had experienced with Office 2010. That was not the end of the story, and it’s probably fair enough to tell how it ends.

After installing Office 2010 64 bit and then 32 bit and both crashing every other 5 minutes, I returned to Office 2007. But then I got the help of Microsoft Support who provided a couple of scripts to clean-up the Windows Registry of anything related to Office 2007 and Office 2010. (The script for Office 2007 is available here; the one for Office 2010 is not yet published). I have then installed Office 2010 32 bit on a clean Registry and now all applications in the package work like a charm. No hanging, no crashing whatsoever. And I must say I was impressed by the support people, how they helped, how they called to check if everything was working, etc. The kind of support I wish to see everywhere.

I also learned that installing the 64 bit version is not recommended unless you really have some demands, like working with huge files, over 2GB (though I’m not sure what are the scenarios when one has Excel files bigger than 2GB). Add-ins for Office 32 bit might not work with the 64 bit version. (Though the add-ins I had in 2007 worked without any update when I installed Office 2010 32 bit.) More information about the 64 bit of Office 2010 can be found in this TechNet article.

, Hits for this post: 1519 .

A new version (1.3) of VSBuildStatus add-in for Visual Studio 2005, 2008 and 2010 is available. It allows you to configure the add-in window to automatically show up when a build/clean/deploy process starts, and/or automatically close when the operation ends.

  • To enable the automatic show of the add-in window when a build/clean/deploy operation starts, check Pop-out automatically when starting a build
  • To enable the automatic hiding of the add-in window when the build/clean/deploy operation ends, check Auto hide when the build ends
    • you can set a delay interval for the hiding, varing from 0 to 300 seconds; if the delay is 0, the window is hidden immediatelly after the build ends
    • to keep the window shown when error(s) occurred during the build/clean/deploy operation, check DO NOT auto hide when an error occurs

Here is a screen short of the properties window. It opens from the Settings button.

The add-in is available on the Visual Studio Gallery.

, , , , Hits for this post: 3124 .

Last week I decided it was time to move forward from Office 2007 and install the new 2010 version. People were asking me for some time if I was trying the beta, but I was stubborn in not installing Office 2010 until the RTM. This is the journal of the past days of using Office 2010.

Day 1
I decided to install Office 2010. I also discovered that for the first time a 64-bit build was available. Since I had a Windows 7 64-bit machine, I thought I should prefer the 64 bit version over the 32 bit, because in theory at least, it should have performed better. So I downloaded and ran the 64-bit setup, but surprise, I could not install it until removing the previous, 32 bit version. That was a little bit pity, since I wanted to have them side-by-side; in case I had problems with Office 2010 I could rely on Office 2007. So I removed Office 2007 and installed 2010 x64. When I opened Outlook it was like boom, immediately showing up; the speed hit me. Plus some new features like the dashboard (File tab) or the Quick Tools. And it even found my existing 2007 profile and was able to use it, so everything was up and running. Until I opened the first email and Outlook crashed. I ignored it and restarted and went well, for a while. It only crashed 3 times the first day.

Day 2
Word 2010 crashed.
Outlook 2010 crashed.

Day 3
Outlook 2010 crashed a couple of times.

Day 4
Outlook 2010 crashed.
PowerPoint 2010 crashed.
It was time to look on the web for similar problems and I discovered others were having similar problems with the 64-bit version. So I decided I should remove it and install the 32-bit version. Things Done.

The first time I opened Outlook it crashed. Then PowerPoint 2010 crashed 6 times in 10 minutes while I was in a meeting with a colleague discussing a presentation. He laughed and told me the same happened to him. Then Outlook 2010 crashed while I was trying to send him an email. Then Word 2010 crashed when I opened a document. Things really started to get annoying. Then I had to make some new appointments in Outlook but accessing the calendar was a little bit cumbersome, as Outlook was on a crashing spree and crashed 3-4 times in several minutes.

It was time to let Office 2010 go and move back to the good old Office 2007 which used to work very good with no problems for a couple of years now. But when I put back Office 2007, my Outlook profile was no longer accessible, because Outlook 2010 somehow altered it in a way that Outlook 2007 was not able to understand. So I had to delete the old profile and make a new one. But now I’m all set again and things are going well.

The lesson learned is that Office 2010 is a no-no for the moment (luckily I didn’t have time to install it at home over the weekend as I was planning). I’ll be waiting for the first service pack, or even the next version if I continue to hear similar stories.

PS: on the other hand, IE9 looks promising on benchmarks.

, Hits for this post: 2254 .

Today Microsoft release officially Visual Studio 2010 and .NET Framework 4.0, with five major release events and many others across the globe. You can download it from MSDN. Those that don’t have an MSDN subscription can try the evaluation versions available here. Express editions are still available for free and can be downloaded from here.

During past months I have wrote various posts about the changes and new features for Visual C++. A summary of these articles are available here.

An important change in Visual Studio 2010 is that F#, now at version 2.0, is bundled in the IDE, just as the other languages, C++, C# and VB.NET. After 7 years in development it had become a first class language with today’s release.

More information about the release can be found here:
http://blogs.msdn.com/somasegar/archive/2010/04/11/announcing-visual-studio-2010-and-net-framework-4.aspx
http://blogs.msdn.com/dsyme/archive/2010/04/12/f-2-0-released-as-part-of-visual-studio-2010.aspx
http://blogs.msdn.com/jasonz/archive/2010/04/12/ship-it-visual-studio-2010-net-framework-4-now-available.aspx

Hits for this post: 4457 .

I’m sometimes asked what browsers do I use and why. I use Firefox and Chrome, 95% of the time, and IE for those few Microsoft sites that are specially designed to work only with IE. Here is a story that shows an argument why I use those two.

A few days ago I used my father’s laptop to do some web browsing. My father is not a computer specialist, but he knows how do use a computer for basic stuff like writing documents, browsing the web or downloading pictures from his digital camera. His laptop runs Windows XP and he had IE 6. Seeing that I though that’s so 2006. So I decided to upgrade that to IE 8. While IE8 was downloading I also decided to download and install Chrome for my own use. It took about a minute to download and install it. I was already surfing the web with Chrome by the time IE8 had done downloading.

Next step was to start the installer, but surprise, IE8 was requiring .NET 3.5 SP1. This was only 56MB or something so it didn’t take lot of time to download (but this could be very different in other geographical locations), however I thought that was a prerequisite whose purpose I don’t necessary see. So I started to install it and surprise: I got an error message that .NET 2.0, which was already installed, could not be uninstalled because it was not found. After some failed re-attempts I decided to uninstall .NET 2.0 manually and it worked well. However, running the .NET 3.5 SP1 setup again ended with the same error. So I decided to try .NET 3.5 without SP1. After a longer download the setup ran into the same error. Next, I downloaded .NET 3.0 and tried to install, but with the same error. At that point it was quite clear to me that there was something wrong with the uninstallation of .NET 2.0. After reading reports of similar problems on the web and without any suggestion being actually helpful I decided to download version 2.0 of the framework. Its setup allowed me to Uninstall or Repair and I chose to Uninstall. It said everything was OK so I tried 3.5 SP1 setup again, and this time it worked! Finally I was able to start the IE8 installation and it required to download and install a few updates and a couple of Windows restarts, and eventually it was up and running, one hour later after starting!

So my question to Microsoft is: how do you expect someone without good knowledge about computers and software installation be able to go through such a scenario? Chrome installation worked gracefully with 3-4 clicks and in less than a minute I was able to use it already. IE8 requires lots of updates and prerequisites like .NET and restarts and God forbids something goes wrong, you’re lost in installation. If the installation doesn’t work, you don’t have a product!

This is one reason (and definitely not the most important one) I prefer Firefox and Chrome over IE.

, , , Hits for this post: 2826 .

In my previous post I talked about the new build system for VC++ from Visual Studio 2010, which is MSBuild and the support for multi-targetting. In this post I will talk about changes to IntelliSense and browsing.

If you go back to the example I was providing in the first post, with the two identical projects created with Visual Studio 2008 and Visual Studio 2010, a second important thing to notice in the comparison of the two solution is that the infamous .NCB file is no longer present in Visual Studio 2010 solution. Instead there is a new file with extension .SDF. This is not just a renaming of the extension, the entire Intellisense for Visual C++ was redesigned in Visual Studio 2010. This is a SQL Server Database file, possible to be opened even in Visual Studio (if one wants to check its content).

In the previous versions of Visual C++, each time you modified a header, the entire solution was reparsed, in which time it was very hard to use the environment. Moreover, the IntelliSense database file (the .NCB file) never seem to shrink, only increased in size, and it could get corrupted from time to time. In the new version, files are parsed on the background, and the IDE does not read all the files, only the current translation unit (which is a source file and all the headers it includes directly and indirectly). As a result, the operation is much swifter and less error prone.

There is also a new disk folder called iPCH in the new solution. This is the storing location for IntelliSense support files and browsing database files (SDF).

#include auto completion

Part of the new IntelliSense and Browsing experience, the #include keyword supports auto-completion for the header files. That means that after typing #include, the IDE displays a list of available headers, filter by their name as you type. The following image shows this.

Call Hierarchy

This feature enables navigation through the code, showing the calls to and from a selected method, constructor or property. When selecting a call in the hierarchy window it shows the code where the call is made.

Red Squiggles

This is a feature that enables highlighting syntactic and semantic errors with a red squiggle line. Hovering the mouse over the line will show a balloon with the error message. The same error is also listed in the Error List window.

Find All References

In the previous versions, this features displayed only the compiler verified results for a search. If you searched for a function M member of a class C it only returned the references where function M was used in the context of C. The new version allows two types of search: one that is focus on speed, and returns all the matches for a symbol regardless the context (but it’s a narrowed search than the one performed with Find in Files), and one that is focused on accuracy and returns only the compiler verified results (i.e. the ones that match the search context).

Class Wizard

Yet another important change is the famous and acclaimed class wizard from VC6, that was dropped in Visual Studio 2002, and was now brought back in Visual Studio 2010.

If you are (or were) familiar with VC6 you know what the Class Wizard is. In Visual Studio 2010 it features basically the same functionality, except that it is improved with search functionality. You can search for command, messages, virtual functions, members or methods. This is great because might not know the exact name of a message or a function, but searching allows you to quickly get it with only typing part of the name. For those not familiar with VC6 this is a single point to add or remove commands, message handlers, virtual functions, member variables and methods. This was a favorite feature in VC6 for a lot of people and there was a constant pressure on Microsoft to bring it back, so here it is.

All these features are detailed in MSDN and on the VC++ Team blog. I suggest several additional readings:

, , , , Hits for this post: 6790 .

The new version of Visual Studio, called Visual Studio 2010 comes with a series of changes for Visual C++. This includes a new build system, new project system, multi-targeting, new IntelliSense, support in MFC for new controls, new additions to the C++ compiler (which were already approved for C++0x), new deployment model, and others. In this post I will talk about the new build system and multi-targeting.

In order to show the changes I will create two simple projects, one in Visual Studio 2008, called Wordpad 2008, and one in Visual Studio 2010, called Wordpad 2010. These would be simple MFC single document applications. The image bellow shows the two solutions opened in Solution Explorer.

As you can see both versions contain the same solutions file (only the suffix in the name differs). The next image shows the files on disk, in comparison for the two solutions.

MS-Build System

The first thing to notice (though it might not be the obvious) is that the project file extension was modified. In Visual Studio 2008 it is called .vcproj, but in Visual Studio 2010 is called .vcxproj. Not only the extension changed, but also the content of the file. This is because in Visual Studio 2010, Visual C++ build system was changed from VCBuild to MSBuild. This build engine was already used for the languages targeting the .NET framework.

MSBuild uses XML project files, and the most important elements of a project are:

  • Items: units of input into the build system, grouped into item collections, which can be used as parameters to the tasks, using the syntax @(ItemCollectionName). Examples of items from the Wordpad2010 project:
      < ItemGroup >
        < ClInclude Include="MainFrm.h" / >
        < ClInclude Include="Resource.h" / >
        < ClInclude Include="stdafx.h" / >
        < ClInclude Include="targetver.h" / >
        < ClInclude Include="Wordpad2010.h" / >
        < ClInclude Include="Wordpad2010Doc.h" / >
        < ClInclude Include="Wordpad2010View.h" / >
      < /ItemGroup >
    
  • Properties: pairs of key/value used to configure the builds. The value of a property can be changed after it was defined. They can be referred in the project file using the syntax $(PropertyName). Examples of properties from the Wordpad2010 project.
      < PropertyGroup Label="Globals" >
        < ProjectGuid >{1E7DC2AA-8CAC-44A8-98F6-DE69249AD30C}< /ProjectGuid >
        < RootNamespace >Wordpad2010< /RootNamespace >
        < Keyword >MFCProj< /Keyword >
      < /PropertyGroup >
    
  • Tasks: reusable units of executable code used to perform builds. Example of tasks can be compiling input files, linking, running external tools. Tasks can be reused in different projects.
  • Targets: represent groupings of tasks in a particular order and expose parts of the project file as entry points into the build system.

You can get a deeper overview on the MSBuild engine here.

Another thing to notice is the presence of a file called Wordpad2010.vcxproj.filters. This file defines the solution explorer tree with the files contained in the project. This used to be a part of the file project, but in Visual Studio 2010 it was moved into a separate file. The reason is to keep the project file only for the build, not for the organization of the project.

The user specific settings used to be stored in a file called ProjectName.vcproj.fullyqualifiedusername.user. Now there is a new file called ProjectName.vcxproj.user.

You can read more about these changes in MSDN.

Multi-targeting

Visual Studio 2008 came to support for multi-targeting of the .NET framework, not only for C# and VB.NET, but also for C++/CLI. In addition to that, Visual Studio 2010 comes with support for native multi-targeting.

The managed multi-targeting allows to target different versions of the .NET framework for mixed-mode applications. By default the target version is the latest, 4.0. This can only be changed manually in the project file. The support for changing this from the IDE was not included in this version. Actually it was dropped, because in Visual Studio 2008 this was possible.

  < PropertyGroup Label="Globals" >
    < ProjectGuid >{AB3D9231-F8B6-4EAD-A15B-C792977AB26E}< /ProjectGuid >
    < RootNamespace >MixedModeDemo< /RootNamespace >
    < TargetFrameworkVersion >v3.5< /TargetFrameworkVersion >
    < Keyword >MFCDLLProj< /Keyword >
  < /PropertyGroup >

The native multi-targeting allows to use different versions of the tools and libraries to build (native) C++ projects. Of course, you must have the targeted toolset installed on your machine, in order to do that. You can define different configurations that target different versions of the toolsets. The targeted toolset can be changed from project’s properties page, General, Platform Toolset. The following image shows the available options on a machine with Visual Studio 2008 SP1 and Visual Studio 2010 installed side by side.

It is possible to target the previous version, 2008, 2005, 2003 and 2002. In theory it’s possible to target even VC6, but there is no support from Microsoft for that.

I suggest to read more about native multi-targeting here, and about managed multi-targeting, for mixed-mode applications, here.

In a next post I will talk about the changes to IntelliSense and browsing experience.

, , Hits for this post: 6781 .

I have updated my Visual Studio addin that displays the status of a build/clean/deploy action. If you get the latest version, 1.2, and are running Visual Studio 2005, 2008 or 2010 (they are all supported) on Windows 7, the progress of the build is also displayed on the Taskbar, on the item corresponding to the Visual Studio instance.

The following images show no progress, different progress steps, and an error during the build/clean/deploy, both for Visual Studio 2008 and Visual Studio 2010 (Beta 2).

No progress

Build progress

Build progress

Error during build

Build progress

Error during build

This was possible by using the Windows 7 Taskbar interop library available on MSDN Code Gallery here.

You can get the latest version of the addin from the Visual Studio Gallery at this link.

, , , , , Hits for this post: 8087 .

I ran across a breaking error while trying to install SQL Server 2008 on a Windows 7 machine. The rule “Previous releases of Microsoft Visual Studio 2008″ failed. Here is the error message that I received.

Rule Previous releases of Microsoft Visual Studio 2008 failed.

Rule "Previous releases of Microsoft Visual Studio 2008" failed.

That was odd, because I actually had Visual Studio 2008 with SP1 installed on that machine. So I start looking for answers and found this Knowledge Base article (KB956139) from Microsoft that said that if Visual Studio 2008 SP1 was installed then “No action is required.” Obviously that didn’t help at all.

Then I start looking into the logs (which are located under C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\). There is a log file called Detail.txt that revealed the following error:

2009-11-25 17:09:35 Slp: Sco: Attempting to create base registry key HKEY_LOCAL_MACHINE, machine
2009-11-25 17:09:35 Slp: Sco: Attempting to open registry subkey
2009-11-25 17:09:35 Slp: Sco: Attempting to open registry subkey SOFTWARE\Microsoft\DevDiv\VS\Servicing\9.0\IDE
2009-11-25 17:09:35 Slp: Sco: Attempting to open registry subkey 1033
2009-11-25 17:09:35 Slp: Sco: Attempting to get registry value SP
2009-11-25 17:09:35 Slp: Sco: Attempting to get registry value kind for value SP
2009-11-25 17:09:35 Slp: Found Microsoft Visual Studio 2008 edition IDE, language 1033, SP level 0.
2009-11-25 17:09:35 Slp: Microsoft Visual Studio 2008 edition IDE, language 1033 does not have required SP level. Upgrade Microsoft Visual Studio 2008 to the SP1 before installing SQL Server 2008.
2009-11-25 17:09:35 Slp: Sco: Attempting to create base registry key HKEY_LOCAL_MACHINE, machine
2009-11-25 17:09:35 Slp: Sco: Attempting to open registry subkey
2009-11-25 17:09:35 Slp: Sco: Attempting to open registry subkey SOFTWARE\Microsoft\DevDiv\VS\Servicing\9.0\STD
2009-11-25 17:09:35 Slp: Sco: Attempting to create base registry key HKEY_LOCAL_MACHINE, machine
2009-11-25 17:09:35 Slp: Sco: Attempting to open registry subkey
2009-11-25 17:09:35 Slp: Sco: Attempting to open registry subkey SOFTWARE\Microsoft\DevDiv\VS\Servicing\9.0\PRO
2009-11-25 17:09:35 Slp: Sco: Attempting to create base registry key HKEY_LOCAL_MACHINE, machine
2009-11-25 17:09:35 Slp: Sco: Attempting to open registry subkey
2009-11-25 17:09:35 Slp: Sco: Attempting to open registry subkey SOFTWARE\Microsoft\DevDiv\VS\Servicing\9.0\VSTD
2009-11-25 17:09:35 Slp: Sco: Attempting to open registry subkey 1033
2009-11-25 17:09:35 Slp: Sco: Attempting to get registry value SP
2009-11-25 17:09:35 Slp: Sco: Attempting to get registry value kind for value SP
2009-11-25 17:09:35 Slp: Found Microsoft Visual Studio 2008 edition VSTD, language 1033, SP level 1.
[...]
2009-11-25 17:09:35 Slp: Rule evaluation done : Failed

It looked like the IDE’s version was not correctly specified in the registry under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DevDiv\VS\Servicing\9.0\IDE. This post from Heath Stewart’s blog explains how to detect the version of Visual Studio 2008. The SQL Server 2008 installer looks in the right place, so the only explanation was that there was incorrect data there. So I started regedit.exe and looked at the key. To my surprise there was no IDE key there.

No key for IDE

No key for IDE

But then I remember I was running Windows 7 64-bit and there are several registry editors (I’m still confused which to use when). So I opened the one located under C:\Windows\SysWOW64\ and this one shown more keys under DevDiv, and under Servicing\9.0 I could also see IDE.

Incorrect version of VS 2008 IDE

Incorrect version of VS 2008 IDE

As you can see from the screenshot, the SP value was 0, and SPName was “RTM”. The Visual Studio 2008 SP1 installer didn’t update these keys. (Well, that wasn’t such a big surprise, because the Visual Studio 2008 SP1 installer really sucks, but that’s another story.) So, what I did was to change those keys as shown in the following image. SP and SPIndex should have the value 1, and SPName should be “SP1″.

These are the correct values

These are the correct values

Also, make sure that the same values under the parent (Servicing\9.0) are 1.

Correct values for SP and SPIndex unde Servicing\\9.0

Correct values for SP and SPIndex unde Servicing\9.0

After making these changes I ran the setup again, and this time it worked like a charm. If you run into the same error and Visual Studio 2008 SP1 is installed then check these registry values and make sure they indicate that SP1 is installed.

, , , , Hits for this post: 5080 .