Windows programming isn’t difficult. In fact, Microsoft Visual C++ 2008 makes it remarkably easy,
as you’ll see throughout the course of this book. There’s just one obstacle in your path: Before you get
to the specifics of Windows programming, you have to be thoroughly familiar with the capabilities
of the C++ programming language, particularly the object-oriented aspects of the language. Objectoriented
techniques are central to the effectiveness of all the tools that are provided by Visual C++
2008 for Windows programming, so it’s essential that you gain a good understanding of them. That’s
exactly what this book provides.
This chapter gives you an overview of the essential concepts involved in programming applications
in C++. You’ll take a rapid tour of the Integrated Development Environment (IDE) that comes with
Visual C++ 2008. The IDE is straightforward and generally intuitive in its operation, so you’ll be able
to pick up most of it as you go along. The best approach to getting familiar with it is to work through
the process of creating, compiling, and executing a simple program. By the end of this chapter, you
will have learned:
❑ What the principal components of Visual C++ 2008 are
❑ What the .NET Framework consists of and the advantages it offers
❑ What solutions and projects are and how you create them
❑ About console programs
❑ How to create and edit a program
❑ How to compile, link, and execute C++ console programs
❑ How to create and execute basic Windows programs
The .NET Framework
The .NET Framework is a central concept in Visual C++ 2008 as well as in all the other .NET development
products from Microsoft. The .NET Framework consists of two elements: the Common Language Runtime
(CLR) in which your application executes, and a set of libraries called the .NET Framework class libraries.
The .NET Framework class libraries provide the functional support your code will need when executing
with the CLR, regardless of the programming language used, so .NET programs written in C++, C#, or any
of the other languages that support the .NET Framework all use the same .NET libraries.
There are two fundamentally different kinds of C++ applications you can develop with Visual C++ 2008.
You can write applications that natively execute on your computer. These applications will be referred
to as native C++ programs. You write native C++ programs in the version of C++ that is defined by the
ISO/ANSI (International Standards Organization/American National Standards Institute) language standard.
You can also write applications to run under the control of the CLR in an extended version of C++
called C++/CLI. These programs will be referred to as CLR programs, or C++/CLI programs.
The .NET Framework is not strictly part of Visual C++ 2008 but rather a component of the Windows operating
system that makes it easier to build software applications and Web services. The .NET Framework
offers substantial advantages in code reliability and security, as well as the ability to integrate your C++
code with code written in over 20 other programming languages that target the .NET Framework. A slight
disadvantage of targeting the .NET Framework is that there is a small performance penalty, but you won’t
notice this in the majority of circumstances.
The Common Language Runtime (CLR)
The CLR is a standardized environment for the execution of programs written in a wide range of high-level
languages including Visual Basic, C#, and of course C++. The specification of the CLR is now embodied
in the European Computer Manufacturers Association (ECMA) standard for the Common Language
Infrastructure (CLI), ECMA-335, and also in the equivalent ISO standard, ISO/IEC 23271, so the CLR
is an implementation of this standard. You can see why C++ for the CLR is referred to as C++/CLI —
it’s C++ for the Common Language Infrastructure, so you are likely to see C++/CLI compilers on other
operating systems that implement the CLI.
Note that information on all ECMA standards is available from www.ecma-international.org and
ECMA-335 is currently available as a free download.
The CLI is essentially a specification for a virtual machine environment that enables applications written
in diverse high-level programming languages to be executed in different system environments without
changing or recompiling the original source code. The CLI specifies a standard intermediate language for
the virtual machine to which the high-level language source code is compiled. With the .NET Framework,
this intermediate language is referred to as Microsoft Intermediate Language (MSIL). Code in the intermediate
language is ultimately mapped to machine code by a just-in-time (JIT) compiler when you execute a
program. Of course, code in the CLI intermediate language can be executed within any other environment
that has a CLI implementation.
Writing C++ Applications
You have tremendous flexibility in the types of applications and program components that you can develop
with Visual C++ 2008. As noted earlier in this chapter, you have two basic options for Windows applications:
You can write code that executes with the CLR, and you can also write code that compiles directly
to machine code and thus executes natively. For window-based applications targeting the CLR, you use
Windows Forms as the base for the GUI provided by the .NET Framework libraries. Using Windows Forms
enables rapid GUI development because you assemble the GUI graphically from standard components
and have the code generated completely automatically. You then just need to customize the code that has
been generated to provide the functionality you require.
For natively executing code, you have several ways to go. One possibility is to use the Microsoft Founda -
tion Classes (MFC) for programming the graphical user interface for your Windows application. The MFC
encapsulates the Windows operating system Application Programming Interface (API) for GUI creation
and control and greatly eases the process of program development. The Windows API originated long
before the C++ language arrived on the scene so it has none of the object-oriented characteristics that
would be expected if it were written today; however, you are not obliged to use the MFC. If you want
the ultimate in performance, you can write your C++ code to access the Windows API directly.
C++ code that executes with the CLR is described as managed C++ because data and code is managed by
the CLR. In CLR programs, the release of memory that you have allocated dynamically for storing data is
taken care of automatically, thus eliminating a common source of error in native C++ applications. C++
code that executes outside of the CLR is sometimes described by Microsoft as unmanaged C++ because
the CLR is not involved in its execution. With unmanaged C++ you must take care of all aspects of allocating
and releasing memory during execution of your program yourself, and you also forego the enhanced
security provided by the CLR. You’ll also see unmanaged C++ referred to as native C++ because it compiles
directly to native machine code.
Categories:
Programing With visual C++
Subscribe to:
Post Comments (Atom)
0 Response for the "Programming with Visual C++ 2008 Windows"
Post a Comment