This book comprises 15 chapters. You can read them in any order, but I recommend you read Chapters 1-3 first to lay the groundwork for understanding the sample code that's presented throughout the book. After that, read the chapters that are appropriate for the particular problem you need to tackle.
Chapter 1: C++, Visual C++, and Managed C++: What's the Difference?
Way back when the first release of Visual C++ appeared, the difference between C++ and Visual C++ was clear; one was a language, and the other was a set of tools and libraries that included a compiler, an editor, a debugger, and so on. That is still the distinction today, but as time has gone by Microsoft has added support for a set of keywords (identified with two leading underscores) that are not standard C++ and are not supported by other compiler vendors . The most significant set of extra keywords are formally known as managed extensions for C++, and they are what you use to write managed code in C++. This chapter explains just what that means and discusses the role of managed and unmanaged code in modern software development.
Chapter 2: Creating Test Harnesses and Starter Applications
Although you can and will create Windows applications in C++, console applications play a very important role in the work you do. A great deal of the C++ code you will write and use is deployed as class libraries, not as standalone applications. To use these libraries, you can create test harnesses that exercise the methods of the libraries. Test harnesses are also quick ways to play with a particular coding technique to see how it works without getting caught up in a graphical user interface. They're also excellent for automated testing because they can run from the command line or a batch file. In this chapter you see how to create console applications in both managed and unmanaged C++.
Chapter 3: The .NET Base Class Libraries
This chapter introduces you to the libraries that your managed code can draw on, including classes for input and output, string manipulation, working with dates and times, regular expressions, and multithreading. It also explains the important role of namespaces in the Base Class Libraries and how to translate names in the documentation into C++ syntax.
Chapter 4: Building Simple User Interfaces with Windows Forms
This chapter shows you how to create a graphical user interface in managed C++ using the Windows Forms libraries. It's quite different from performing the same task in MFC or other C++ libraries.
Chapter 5: Writing a Class Library in Unmanaged C++
This chapter discusses some of the design thoughts that lead to a layered design, and how a class library can be used to implement one or more layers . You'll also see how to use an unmanaged class library from both managed and unmanaged C++.
Chapter 6: Writing a Class Library in Managed C++
This chapter shows you how to design and create a managed assembly that implements a class library. It distinguishes between managed ( garbage-collected ) classes and managed code, and shows you how to use managed classes from another managed language, such as C#.
Chapter 7: Building DLLs in Unmanaged C++
In this chapter you see the difference between an unmanaged DLL and a managed assembly, write a DLL in unmanaged C++, and call it from both managed and unmanaged code. You also learn how to write custom marshaling code for maximum convenience to the developers of the managed code that uses the DLL.
Chapter 8: Writing COM Components in C++
This chapter illustrates another technique for packaging unmanaged code: writing COM components. You will see how to write a COM component and how to call it from managed and unmanaged code.
Chapter 9: Using Existing COM Components in C++
When you write a COM component yourself, calling it from more code you write yourself is quite simple. This chapter shows you how to take on a slightly harder task: reusing code you didn't write, such as Word 2003. It leads you through IDL and the Object Viewer to show you how to discover interfaces and methods in a large automation server. You learn how to write both managed and unmanaged code that relies on the power of other applications to save time and effort.
Chapter 10: Writing and Consuming a Web Service
This chapter describes Web Services and the kind of distributed applications they make possible. You will see how to write and use a Web Service from both managed and unmanaged code.
Chapter 11: Writing a Data Layer in Managed C++
The ADO.NET library provides classes that your managed code can use to work with data from a variety of sources. In this chapter, you will learn about the DataSet and DataReader classes, and the purposes they serve, and learn how to get information in and out of a database. This chapter also shows you how to use a configuration file to store useful information that can be changed at runtime without requiring a recompile of your application.
Chapter 12: Writing a Windows Service
A Windows service is an application that runs unattended and deals with various background tasks . This chapter shows you how to write and test a Windows service, and how to debug one. Because there is no user interface, the service must communicate with the user in some other way, so this chapter demonstrates sending mail and adding an entry to the event log, two techniques that are likely to be useful in other types of applications as well.
Chapter 13: Strengthening Your Managed Applications with Security and Encryption
Security is an important focus for almost every developer today. In this chapter you learn about role-based security in Windows applications, and how you can use Windows account information in your code. You also see how to encrypt and decrypt data in your applications.
Chapter 14: Moving Layers to Different Machines with .NET Remoting
Building a distributed application is made significantly simpler with .NET remoting. Essentially, you write your application as though it was all on one machine, and use configuration files to spread assemblies over different machines. This chapter shows you how to build and test a two-part application built on .NET remoting, and how to add .NET events to a remote application.
Chapter 15: Building Advanced User Interfaces in Managed C++
Whereas Chapter 4 got you started writing Windows Forms applications, and other chapters throughout the book have created simple Windows applications, many developers will need to put more effort into the user interfaces of their applications. In this chapter, you see how to write your own controls, how to draw with GDI+, how to implement drag and drop, and how to internationalize and localize your WinForms applications.