Using Visual C++ 2010

We’ve finally come to the end of the trail! In the previous post, Using CodeBlocks 10.05 – Part 8, I was able to cover up to the end of Book VI of C++ All-In-One Desk Reference For Dummies. This post begins with Book VII Chapter 1. After you’ve read this post, you’ll have the complete story on code updates for my book unless someone comes up with additions I need to make, which will appear in future posts. You can find a complete list of these posts in the C++ All-in-One for Dummies category archive.

Book VII doesn’t rely on CodeBlocks 10.05. Instead, the original text relies on Visual C++ 2008. In the interest of completeness, I decided to test the code in this book with Visual C++ 2010just to make sure it works. I used the version of Visual C++ 2010 that comes with the full product and didn’t test using an Express edition.

 

If you have problems with an Express edition product, please let me know and I’ll do my best to accommodate your needs. However, you should know in advance the the Express editions are, by design, incomplete and the examples may not work no matter how hard you work. The idea is that you’ll buy the full version of the product to get the functionality you need.


Always open the Solution (.SLN) file associated with the project to get the best upgrade. Whenever you open one of the book’s projects using Visual C++ 2010, you’ll see the Visual Studio Conversion Wizard dialog box shown here:

2010Update01

Simply click Finish and the wizard will convert the project to work with Visual C++ 2010. After the conversion is complete, you’ll see a completion dialog box. Clear the Show the Conversion Log When the Wizard is Closed option and then click Close. You’ll see the converted project.

The converted project won’t display any source code files. So, you’ll need to open Solution Explorer. In Solution Explorer, open the Source Files folder and double click the .CPP file associated with the project, such as Hello World.cpp for the project in Book VII Chapter 1. At this point, you can set breakpoints and then click Start Debugging to see the example run, just as you ordinarily would.

 

Before you can use the debugger with any of the examples, you must recompile them using Visual C++ 2010. Otherwise, the debugger will report errors and not run. Choose Build | Rebuild Solution to rebuild you application.


Some of the examples may display a warning message such as this one when you rebuild them as part of the upgrade:

 

LINK : warning LNK4075: ignoring ‘/INCREMENTAL’ due to ‘/PROFILE’ specification
SimpleDialog.obj : warning LNK4075: ignoring ‘/EDITANDCONTINUE’ due to ‘/OPT:REF’ specification


This message doesn’t appear to cause any problem with the example working as described in the book. Please let me know if you experience any problems in this regard.

The SimpleDialog example found in both Chapters 2 and 5 requires a change to the CSimpleDialogDlg::OnBnClickedCheck() method to make the buffer work as expected. Use the following code instead:

void CSimpleDialogDlg::OnBnClickedCheck()
{
    // Obtain the input string from m_Input.
    CString ThisString = _T("");
    int len = m_Input.LineLength(0);
    m_Input.GetLine(0, ThisString.GetBuffer(len), len);
 
    // Release the buffer created for ThisString.
    ThisString.ReleaseBuffer();
 
    // Place the information in m_Output.
    m_Output.SetWindowTextW(ThisString.GetBuffer());
    ThisString.ReleaseBuffer();
}

This should be the only problem you encounter while working with the code. Please let me know if you have any questions about any of the examples in the book at John@JohnMuellerBooks.com.