
02 6000 ch01 11/18/03 8:52 AM Page 7 C++, Visual C++, and 1 Managed C++: IN THIS CHAPTER What’s the . Differences Between Visual Difference? C++ and C++ . Managed and Unmanaged Code . Managed and Unmanaged Data Differences Between Visual C++ . and C++ Properties . In Brief C++ is a language, and Visual C++ is a product. The language itself was developed in the early ‘80s, and C++ compilers have been for sale since about 1985. Visual C++ made its debut in 1993, and has had many major releases since that time. In the late ‘90s a standard was developed for the C++ language, and the latest release of Visual C++ (in Visual Studio .NET 2003) includes a top-notch C++ compiler that is 98% compliant to that standard, the most compliant version ever. The Visual C++ Suite of Tools Of course, Visual C++ is much more than just a compiler. In addition to a compiler, Visual C++ includes n Two very powerful C++-only class libraries (MFC and ATL). n An implementation of the Standard Template Library, STL, part of standard C++. n A debugger that includes a variety of productivity- boosting features to help you understand what your application is doing, and why. 02 6000 ch01 11/18/03 8:52 AM Page 8 8 CHAPTER 1 C++, Visual C++, and Managed C++: What’s the Difference? n An integrated development environment that enables you to edit, compile, and debug your code all from the same application. n A suite of wizards and designers that generates code for common application types, or simplifies coding by using dialog boxes like the properties window to automatically modify your code. n The .NET Framework SDK, which includes another set of class libraries (the .NET Base Class Libraries, ASP.NET, ADO.NET, and Windows Forms) along with command-line compilers and utilities for .NET development. Visual C++ is available in several editions, all at different prices. The umbrella product, Visual Studio, comes with Visual C++ as well as Visual Basic, Visual C# .NET, and other tools. Visual Studio comes in Professional, Enterprise Developer, and Enterprise Architect versions, each of which contains the three mainstream languages (C++, VB, and C#). Visual C++ .NET Standard Edition comes with only Visual C++—no VB or C# compilers. In addition, there is an Academic edition and evaluation versions are occasionally available. “I’M A VISUAL C++ PROGRAMMER”— This book assumes you’re working with the Professional Edition. If a demonstrated SO WHAT? feature is from the Enterprise or Enterprise For years, if someone told you “I’m a Visual C++ Architect edition, that detail is mentioned. programmer,” it meant that person knew C++, had The first release of Visual C++ that could learned the MFC class library (and perhaps also the produce managed code and target the .NET ATL template library), was familiar with the concepts Common Language Runtime was named underlying Windows programming and the Visual C++ .NET, and was part of Visual Windows API, and knew how to use Visual C++ to Studio .NET, released in the spring of 2002. write MFC and ATL applications for Windows, or for Since then, the new release of those products class libraries and components. includes the moniker 2003; for example, Those skills don’t always translate well to the .NET Visual C++ .NET 2003. The older product has way of building applications and libraries. A Visual been renamed Visual C++ .NET 2002, part of C++ .NET programmer building managed applica- Visual Studio .NET 2002. The changes tions has more in common with a Visual Basic .NET between the 2002 and 2003 versions are rela- programmer or a C# programmer than a Visual C++ tively minor in most of the .NET languages, 6 programmer. To use Visual C++ .NET to build but they’re quite dramatic in Visual C++. applications for the .NET Framework, you need to This book covers the 2003 product. The understand the concepts behind .NET, and learn an architectural concepts of .NET and the integrated development environment that’s quite description of the class libraries included in different from Visual C++ 6. That’s what this book is the .NET Framework are applicable if you’re here to help you learn. using the 2002 product, but the menu choices, wizards, code generators, and the like are quite different in the 2003 release. 02 6000 ch01 11/18/03 8:52 AM Page 9 9 Differences Between Visual C++ and C++ The Managed Extensions to C++ It’s long been a convention among C++ compiler developers that any identifier that starts with an underscore belongs to the compiler. Don’t start your variable or function names with an underscore, and you’ll never accidentally overwrite something the compiler was using. A similar convention is to use double underscores at the start of identifiers and keywords that are compiler-specific (implemented by one compiler vendor but not by others). This reminds developers who use these features that the work they are doing would not compile or run properly if it were built with a different compiler. Although all compilers have a handful of compiler-specific keywords, these extensions haven’t really been important to developers in the past. Millions of lines of code have been written that didn’t knowingly use compiler-specific code. (The qualifier knowingly applies because compilers vary dramatically in their standards compliance, and code that compiles and works under one compiler might behave quite differently under another.) Developers have chosen C++ development tools based on criteria like the strength of the class library, or the ease of use of the integrated editor, not the collection of extension keywords offered by the compiler itself. With the introduction of Visual C++ .NET in 2002, that situation changed. Continuing in Visual C++ .NET 2003, developers use a series of extension keywords (known as the Managed Extensions to C++) to generate code that targets the .NET Framework, also called managed code. One of the requirements for the team developing Visual C++ .NET was that existing code must compile and run without error—whether the code now ran in the framework or not. Therefore, the development team could not change the meaning or behavior of any existing keywords. The “escape hatch” of compiler-specific extensions enabled the team to meet this requirement. In a printed book, it can be hard to spot the double underscores. Can you see the difference between __gc and _gc? Could you see it if they didn’t appear side by side? There are a lot more leading double underscores in this book’s sample code than leading single underscores, so if you’re not sure, it’s probably a double underscore. If you learned C++ with a compiler other than Visual C++, you might be concerned that you have another language to learn—you don’t. The keywords, syntax, brace brackets, semi- colons, and other delights of C++ are exactly the same in Visual C++. What’s different are the libraries, wizards, and integrated development environment that combine to make you a more productive programmer no matter what kind of application you’re creating. Applications That Run Directly Under Windows When you develop an application using Visual C++ .NET 2002 or 2003, it will be either a managed or unmanaged application. In either case, it will be built to run on a Windows machine. 02 6000 ch01 11/18/03 8:52 AM Page 10 10 CHAPTER 1 C++, Visual C++, and Managed C++: What’s the Difference? An unmanaged application runs directly under Windows. Even a console application, which runs in a command prompt, runs under Windows. The compiled executable from Visual C++ cannot be executed on a non-Windows machine, although the code itself might be portable. The source code for a console application can be moved to a non-Windows machine and recompiled with a compiler for that machine. That source code would run, assuming it didn’t use any Microsoft-specific libraries such as MFC or ATL, did not attempt to load any DLLs or use any COM components, and avoided compiler-specific extensions. Of course, any kind of Windows application other than a console application is utterly nonportable. A managed application runs in the .NET runtime. As of mid-2003, no versions of the .NET runtime are generally available for platforms other than Windows. A demonstration/acade- mic research version of a subset of the .NET Framework called Rotor runs on at least one flavor of UNIX (FreeBSD) and the Mac. It doesn’t include ASP.NET or Web Services, Windows Forms, ADO.NET, or anything Windows-specific such as Registry access. The license agree- ment prohibits its use for commercial purposes. Another project for implementing the .NET Framework on a non-Windows platform is Mono, which targets Linux and other UNIX flavors. The work is partially complete and a completion date has not been announced. Because Visual C++ is itself a Windows application, it’s a good bet that you’ll be using it to create Windows applications. That’s the assumption throughout this book. Managed and Unmanaged Code A compiler that emits unmanaged code compiles your source to machine code, which then just runs under Windows. A compiler that emits managed code does not compile your source to machine code, but rather to Intermediate Language (IL). Managed code runs in the Common Language Runtime, not directly on Windows. When you build a managed application, your code is compiled to IL in a file called an assem- bly, along with metadata that describes the classes, methods, and attributes (such as security requirements) of the code you’ve created.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages20 Page
-
File Size-