Mailbag: How to create a Visual Studio project to compile the sample .NET Framework detection code

Question:

I have downloaded both versions of the sample .NET Framework version detection code (described here and here), and I am trying to compile it to test it out on my system.  However, I am running into issues trying to create a Visual Studio project that will correctly build the sample code.  What do I need to do to get this sample code to compile on my system?

Answer:

You should be able to use the following steps to create a project and compile the sample .NET Framework detection code using either Visual Studio 2005 or Visual Studio 2008:

  1. Start Visual Studio 2005 or Visual Studio 2008 (the steps are equivalent in both versions of VS)
  2. Click on the File menu, choose File | New | Project...
  3. In the Visual C++ node, select the Win32 project item, provide a name and click OK
  4. In the Win32 Application Wizard dialog, click Next on the Overview screen
  5. Select Windows Application on the Application Settings screen (but do not change any of the other settings) and click Finish
  6. Right-click on your project in the Visual Studio Solution Explorer and choose Properties
  7. In the property pages, change the Configuration drop down at the top from Active (Debug) to All Configurations
  8. Go to Configuration Properties | C/C++ | Precompiled Headers and change the Create/Use Precompiled Header from Use Precompiled Header (/Yu) to Not Using Precompiled Headers
  9. Click OK to dismiss the property pages
  10. Replace the contents of your main CPP file with the contents of the file from my blog post (the original detection sample, or the enhanced sample that does some additional checks behind the scenes)
  11. Save all of the project files
  12. Build the project

Note - while testing the above steps, I noticed that the sample code was generating several warnings during the build process.  I fixed these and posted updated versions of both samples that will build by default without any warnings.