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: 14094 .

.NET provides two classes for image transformations: Matrix, used for geometric transformations, and ColorMatrix, used for color transformations.

One of such color transformations is inverting or negating. This means subtracting each color component from 255. Black (0,0,0) becomes White (255, 255, 255), and Green (0, 255, 0) becomes Magenta (255, 0, 255).

You can find many examples on the web that look like this:

public Bitmap Transform(Bitmap source)
{
    //create a blank bitmap the same size as original
    Bitmap newBitmap = new Bitmap(source.Width, source.Height);

    //get a graphics object from the new image
    Graphics g = Graphics.FromImage(newBitmap);

    // create the negative color matrix
    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.Matrix00 = colorMatrix.Matrix11 = colorMatrix.Matrix22 = -1f;
    colorMatrix.Matrix33 = colorMatrix.Matrix44 = 1f;

    // create some image attributes
    ImageAttributes attributes = new ImageAttributes();

    attributes.SetColorMatrix(colorMatrix);

    g.DrawImage(source, new Rectangle(0, 0, source.Width, source.Height),
                0, 0, source.Width, source.Height, GraphicsUnit.Pixel, attributes);

    //dispose the Graphics object
    g.Dispose();

    return newBitmap;
}

Using this code one can get a negative image.

Original image

Original image

Negative image

Negative image

This runs fine on Windows XP. But when I ran it on Windows 7, I was getting only a black image. All the pixels were ARGB(255, 0, 0, 0). This was how it looked:

Incorrectly transformed image

Incorrectly transformed image

I was surprised to learn that it worked on Windows XP, but not on Windows 7. I don’t have Windows Vista to test but I guess it’s the same as with Windows 7. I thought it must be something in the GDI+ library, because building with .NET 3.5 SP1 or 4.0 Beta 2 didn’t change a thing.

After trying different things, I figured out what the problem was: the color matrix was incorrect. It must be defined like this:

ColorMatrix colorMatrix = new ColorMatrix(
   new float[][]
   {
      new float[] {-1, 0, 0, 0, 0},
      new float[] {0, -1, 0, 0, 0},
      new float[] {0, 0, -1, 0, 0},
      new float[] {0, 0, 0, 1, 0},
      new float[] {1, 1, 1, 0, 1}
   });

With this change the Transform function produces a correct negative image, regardless the operating system or the .NET framework version.

However, what I don’t know yet, is why it worked on Windows XP. The only conclusion I can draw is that the GDI+ implementation has a fault there, that was later corrected. That’s why an incorrect color matrix produced a correct transformation on Windows XP.

, , , , Hits for this post: 11484 .

I was doing some development in Visual Studio 2010 Beta 2 and I had to add some references to my projects. When I opened the Add Reference dialog I realized something was wrong: it was working very fast. Since I’m using Visual Studio 2008 for every day development I am used to wait tens of seconds before the dialog loads all the references and only after that I can select what I want. But in Visual Studio 2010 it popped up instantly and all the tabs were browse able at the same speed. This was not normal. Usually new versions are slower that older ones (and I suspect Visual Studio 2010 has such features), but Add Reference dialog works great.

Then I browsed the web I came across this post from Scott Guthrie who explain what has changed:

  • default active tab when the Add Reference dialog is opened is now Projects, and not .NET
  • .NET and COM tabs load asynchronously in worker threads, populating the lists as references are discovered, without blocking the UI thread, which means you can browse through the references as soon as you open the tab

There are only two things that I can say: first is that I’m impressed. I now get instantly what it used to take maybe half a minute. Second is that I’m puzzled that it took so many years to implement that. Anyway, good work.

, , Hits for this post: 17668 .

With VC++ Feature Pack Microsoft has added new classes to MFC to provide support for new controls. However, these controls were not available from the designer. One had to manually wrote all the code for enabling an application to use these controls. Visual Studio 2010 Beta 2, released a couple of weeks ago, provides support in the designer for these controls.

MFC controls in the Toolbar

MFC controls in the Toolbar

Here is a screen shot of a dialog application with these controls:

New MFC Controls

New MFC Controls

The controls are:

  • Color button (CMFCColorButton): represent a color picker control allowing users to select a color
  • Font combo box (CMFCFontComboBox) : represent a combo control that displays a list of fonts available in the system
  • Edit browse (CMFCEditBrowseCtrl): an editable control with a button that displays a dialog for selecting a file or a folder
  • Visual Studio list box (CVSListBox): an editable list control with buttons for adding, removing or rearranging items in the list
  • Masked edit (CMFCMaskedEdit): a masked edit control that has a string template representing the structure of the allowed input, which is validated against the value provided by the user
  • Menu button (CMFCMenuButton): displays a pop-up menu (from a menu resource) and reports the command selected by the user
  • Property grid (CMFCPropertyGridCtrl): an editable property grid control
  • Shell list (CMFCShellListCtrl): a list control that displays the files and folders from you system just list Windows Explorer list view does
  • Shell tree (CMFCShellTreeCtrl): a tree control that displays the folder from your system just like the Windows Explorer folder view does
  • Link control (CMFCLinkCtrl): is a special button that has the appearance of a hyperlink and invokes the target link when pressed

Not all the properties for these controls are available from the designer. For instance the properties list still needs hand coding, it is not possible to select a menu resource for the menu button nor the starting point for the shell tree and list. However, having them available in the toolbar is a good step forward.

, , , , Hits for this post: 25104 .