October 24, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Visual Studio .NET 2003, aka Everett, for the C++ Programmer

  • December 18, 2002
  • By Kate Gregory
  • Send Email »
  • More Articles »

My plans for a column on image manipulation in Managed C++ have been temporarily nudged aside by the end of the non-disclosure limits for beta testers (like me) of the next version of Visual Studio, formerly known as Everett and now officially called Visual Studio.NET 2003. This version is of special interest to Visual C++ programmers, who get all kinds of neat stuff that was missing from the current released version.

Seems like yesterday I showed you how to make a Windows Forms application in Managed C++ by starting with a C# application and doing a little search-and-replace. Fun as that was, you have to like this way better: create a new project. Choose Visual C++ for the project type (if you wish, you can expand Visual C++ and restrict it to .NET projects) and Windows Forms application for the template. (See Figure 1.) How do you like that?



Click here for larger image

When you're working on a Windows Forms application, Managed C++ looks just like C# or VB (See Figure 2) with just a few tiny differences — it says C++ in the title bar, and there's a lightning bolt on the properties window for easy event access. You have all the shortcuts you might expect &mash; for example, double-click a button on the form to edit the click handler for the button.



Click here for larger image

When you get to the code, you'll see that code outlining is on by default, as it is in VB and C#, rather than a hidden option you have to know about to awaken, as it is in the release version of Visual C++. But a bigger thrill than that greeted me the first time I looked at Managed C++ in Everett:


/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container * components;

Those are documentation-generation comments! Note the three slashes rather than just two for ordinary comments. On the tools menu (Figure 3) you'll see a new addition: Build Comment Web Pages. This generates a series of HTML pages that describe the objects in your project or solution, their member variables and member functions. Most of the information, such as the names and types of the parameters to a function, comes directly from the code itself. The documentation generator supplements that with information from these special comments to produce pages like Figure 4.



Click here for larger image

As for writing the button handler, you have the entire .NET Base Class Library to work with. You just need to remember that you are working with pointers, so you use -> rather than . to separate objects from methods, and that in C++ namespaces and static methods are both set off with the scope delimiter, ::, rather than the . in use in VB and C#. Here's the handler for the button click in my sample application:

System::Void GreetMe_Click(System::Object *  sender, 
                           System::EventArgs *  e)
 {
    label1->Text = String::Format("Hello, {0}", 
                                  textBox1->Text);
 }

This code is all in a giant .h file, and all the functions are inline. If any become unwieldy it should be simple enough to move them to a separate .cpp file and just leave the declarations in the .h file.

My little application works like a charm (Figure 5.) It takes very little time to put a Windows Forms application together in Managed C++. There's still no tool to convert MFC applications over to the .NET Framework, but if you're starting a new application, and you were thinking of going to C#, why not stick with C++ now?

The other C++-specific news in this version is the ANSI/ISO compliance. Of course compliance increases with every release, but now it's reaching into the high-90's, the most compliant release ever. That should make it attractive to those of you writing cross-platform code: why not build and debug in this amazingly productive tool, then copy your source code to your target machines at the last minute and just compile them with some other compiler? That's what standards are for, after all.

So, when can you start working with Visual Studio .NET 2003? It's in final beta now, and MSDN subscribers can download a copy today. (Start at http://msdn.microsoft.com/vstudio/productinfo/vstudio03/default.asp and follow the links.) If you're not an MSDN subscriber, but you do own a copy of Visual Studio .NET 2002, you'll be able to buy a copy of the new version for a nominal fee (around $29 US) when it's released. When will that be? It will be released, along with Windows .NET Server 2003, in the spring of next year. I can't wait!

About the Author

Kate Gregory is a founding partner of Gregory Consulting Limited (www.gregcons.com). In January 2002, she was appointed MSDN Regional Director for Toronto, Canada. Her experience with C++ stretches back to before Visual C++ existed. She is a well-known speaker and lecturer at colleges and Microsoft events on subjects such as .NET, Visual Studio, XML, UML, C++, Java, and the Internet. Kate and her colleagues at Gregory Consulting specialize in combining software develoment with Web site development to create active sites. They build quality custom and off-the-shelf software components for Web pages and other applications. Kate is the author of numerous books for Que, including Special Edition Using Visual C++ .NET.


From Kate Gregory's Codeguru column, "Using Visual C++ .NET".







Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel