Product Details
Extending MFC Applications with the .NET Framework

Extending MFC Applications with the .NET Framework
By Tom Archer, Nishant Sivakumar

List Price: CDN$ 75.99
Price: CDN$ 52.42 & eligible for FREE Super Saver Shipping on orders over $39. Details

Availability: Not yet published
Ships from and sold by Amazon.ca

9 new or used available from CDN$ 38.74

Average customer review:
(2 )

Product Description

The Microsoft Found Classes (MFC) compose the class library for Microsoft's Visual C++. First introduced over 10 years ago, this class library is now in use by approximately 1.5 million programmers, and is the subject of many books, articles, and Web sites. MFC developers, along with their hundreds of thousands of existing applications, are not going to migrate to .NET overnight. On the other hand, there is no doubt that .NET is the future of Microsoft development. Therefore, instead of writing yet another .NET book trying to move MFC developers to .NET entirely, this book attempts to get these MFC developers on board today by showing them how to continue using MFC and combine it with .NET to become more productive. Then over time, MFC developers will move to .NET. For now, this book focuses on this untapped group of MFC developers who fall into the category of "late adopters". While there are several books on COM and .NET interoperability, they really focus more on making your new .NET apps interact with your legacy apps. We don't know of another book quite like this one.


Product Details

  • Amazon Sales Rank: #1164292 in Books
  • Published on: 2003-12-22
  • Original language: English
  • Binding: Paperback
  • 656 pages

Editorial Reviews

Book Info
Text shows MFC developers how to boost productivity by incorporating .NET functionality into existing MFC applications. CD-ROM includes the complete downloadable source code, working examples, and text code from the book. DLC: Application software--Development.

From the Inside Flap
Assumptions and Goals

This book assumes that you are an experienced MFC developer who, while not ready to completely migrate your code to .NET, is interested in seeing how .NET can make you more productive. As an MFC developer, you’re infinitely more comfortable with the document/view and dialog model of creating user interfaces and are simply much more productive with this development environment. In addition, you might have a large amount of source code that you’re not willing or able to migrate to .NET right now—if ever. However, you’re still intrigued by some of the .NET classes and how they might complement or even replace various MFC counterpart classes. That is specifically who this book targets. As opposed to the many .NET books that seem to take the attitude that it will be all or nothing for developers, this book is more realistic in realizing that many developers (especially those using C++ and MFC) will want to use .NET only where there is a clear and obvious advantage.

In addition, while I do go into some detail on the various .NET classes that I illustrate throughout this book, the book is not a “.NET class library book.” There are hundreds of .NET types and classes, and that simply isn’t the focus here. My objective is to show you a few select classes that I feel would benefit most MFC developers; see, for example, the XML chapter.

XML has become the standard for exchanging data in many organizations. However, in order to use XML from MFC, you’re probably going to be using the Microsoft IE (Internet Explorer) XMLDOM via COM (Component Object Model). While this is workable solution—I’ve written several articles and book chapters on how this is done—using the XMLDOM just doesn’t compare to the very elegant and powerful set of .NET XML classes. Therefore, a complete chapter is devoted to the .NET XML namespace, covering everything from reading/writing XML files and traversing XML documents to querying XML data using XPath.

As a result of this approach, when finished with this book, you will know how to integrate the power of the .NET Base Class Library (BCL) into your existing—and future—MFC applications, which will ultimately make you a more productive—and more marketable—programmer.

Technical Matters

While it’s sometimes helpful to think of Visual C++ .NET as containing two separate C++ compilers—one for managed (.NET) code and one for unmanaged code—technically, the Visual C++ .NET product contains only one compiler that has two distinct parts:

  • ISO Standard C++, an ISO-compliant C++ compiler that can be used (with the inclusion of the appropriate libraries) to generate native (x86) executables and libraries for projects such as console applications, Windows applications, Windows services, and so on. When combined with the MFC class library, this is what pays the bills for most of the intended readers of this book (and its authors).
  • Managed Extensions, which are the language constructs available for mixing managed C++ syntax with your standard C++ code. The Managed Extensions allow you to define and use managed types (garbage-collected reference type, value types, scoped enums, delegates, etc.) and use managed runtime facilities such as reflection and security.

Therefore, there’s only one compiler, and you can think of Managed Extensions as somewhat like other Microsoft C/C++ extensions, such as __declspec, except obviously more extensive, as it has the responsibility of exposing all of the CLI features: garbage collection, reflection, and so on. You might even think of Managed Extensions as a superset language containing Standard C++ as a subset. So now we know that a single compiler can generate both native and managed code for Standard C++. What about mixed code applications? Let’s look at two techniques for mixing native and managed C++ code: COM Interop and IJW (It Just Works).

There are actually two types of COM Interop. There is the COM Callable Wrapper (CCW), which allows you to create a “pure” native application (with no .NET build-time dependencies) that accesses .NET code via COM, and the Runtime Callable Wrapper (RCW), which allows you to access native code from managed applications. Therefore, one direction I could have taken in this book would have been to write MFC applications and then access the various selected .NET classes via CCW. However, CCW has many drawbacks that inevitably make it unappealing. First, CCW is not very efficient in terms of execution speed. Second, CCW cannot use the entire CLR type system—method parameters and properties are restricted to automation types. Finally, many .NET types are not exposed to COM, so accessing them would be very difficult or impossible.

IJW refers to the collection of mechanisms that allow managed code to call native functions, compile unmanaged types in MSIL, use unmanaged types in managed type method signatures, provide native entry points to MSIL methods, and so on. However, IJW is not only about managed code calling native functions. It’s also about exposing native entry points to managed functions and basically doing all the plumbing necessary to get C++ code to work under .NET.

If you’re a bit confused by the last paragraph, that’s perfectly understandable. After all, it now sounds like I’m talking about writing .NET applications that use native code when the book’s topic promises to be about the opposite—using .NET to augment MFC applications! As it turns out, although at first blush this does seem to be backwards, and the designers of IJW probably intended it for .NET applications that need to occasionally call a native function, it turns out that it works just fine for a .NET application that is 90% native. As a result, since IJW has full access to the .NET class hierarchy and type system and is much more efficient than CCW, this is the technique used throughout the book.



032117352XP12012003

From the Back Cover

“To anyone looking to augment their existing MFC code base and knowledge with the powerful .NET classes—which provide such capabilities as disconnected data, in-memory database (IMDB), regular expressions, and data encryption—Tom Archer’s book has it all.”

Erik Westermann, Lead Architect, Eidenai Innovations

Extending MFC Applications with the .NET Framework is the first book to show MFC developers how to boost productivity by incorporating .NET functionality into existing MFC applications. Tom Archer clearly illustrates how using the .NET Base Class Library (BCL)—to complement or replace MFC classes when there is a clear advantage—enables MFC developers to create elegant and robust Windows applications in the most efficient way possible.

Each chapter begins with an introduction that explains the technology, outlines its benefits, lists its pragmatic business uses, and summarizes the required syntax. As is an Archer trademark, this information is solidified with hands-on, practical demo applications.

This book answers the questions MFC developers have about .NET, including:

  • What are the key issues when combining MFC and Managed Extensions? Page 15
  • How can Regular Expressions be used to parse a document for multiple complex pattern types, such as email addresses? Page 84
  • How can hash codes be used to validate users without storing passwords? Page 161
  • How can MFC applications maintain data stored in XML format? Page 274
  • Once an ADO.NET DataSet is filled, how can the data be searched, sorted, and filtered? Page 336
  • What technique is used for reading image data from a database using ADO.NET classes? Page 363
  • What are the options for handling disconnected data concurrency issues? Page 396
  • How can Remoting be used to pass MFC objects between applications? Page 460

The CD-ROM supplies the complete downloadable source code, working samples, and test code from the book, as well as several productivity-enhancing utilities such as a Visual Studio .NET Custom AppWizard.



032117352XB11142003