C++/CLI in Action


C++ is the language of choice for thousands of applications and millions of lines of code. With C++/CLI, developers can integrate existing C++ code into the .NET platform without rewriting their applications. This book explores the C++/CLI syntax, teaches how to mix native C++ and managed .NET code, and shows how to integrate C++ with Windows Forms, WPF (Avalon), and WCF (Indigo).

Imagine taking a C++-based program you've been using for a decade and giving it a snazzy new ...

See more details below
Other sellers (Paperback)
  • All (14) from $23.98   
  • New (6) from $27.99   
  • Used (8) from $23.98   
Sending request ...


C++ is the language of choice for thousands of applications and millions of lines of code. With C++/CLI, developers can integrate existing C++ code into the .NET platform without rewriting their applications. This book explores the C++/CLI syntax, teaches how to mix native C++ and managed .NET code, and shows how to integrate C++ with Windows Forms, WPF (Avalon), and WCF (Indigo).

Imagine taking a C++-based program you've been using for a decade and giving it a snazzy new interface using Windows Presentation Foundation. How about making your old business applications talk to your new ones using Windows Communication Foundation. C++/CLI makes this—and more—possible. C++/CLI in Action shows you how to bridge the gap between your existing C++ code and the .NET platform. C++/CLI in Action will help you if:

  • You're hesitant to migrate to .NET because it means rewriting code in C# or VB.
  • You have significant C++ expertise that you want to leverage in the .NET.
  • You only need to use pieces of the .NET framework, such as Windows Forms or web services.

There's no fluff here. Designed for readers who already know C++, this book starts by teaching the unique aspects of the C++/CLI language. After a quick tour through the basics, readers work through examples of integrating standard C++ into the .NET-based applications and building programs that mix C++ and .NET code for maximum performance and efficiency.

This book explores the C++/CLI syntax, teaches how to mix native C++ and managed .NET code, and shows how to integrate C++ with Windows Forms, WPF (Avalon), and WCF (Indigo) for maximum performance and efficiency.

Read More Show Less

Product Details

  • ISBN-13: 9781932394818
  • Publisher: Manning Publications Company
  • Publication date: 3/1/2007
  • Edition number: 1
  • Pages: 416
  • Product dimensions: 7.40 (w) x 9.20 (h) x 0.90 (d)

Meet the Author

Nishant Sivakumar has been programming since 19909, and has extensive experience with Visual C++, MFC, C#, and the .NET Framework. Nish has been a Microsoft Visual C++ MVP since 2002, and maintains an MVP tips and tricks website (www.voidnish.com) along with a Microsoft Technology blog (blog.voidnish.com). He works for The Code Project and is in charge of the MFC libraries Ultimate Toolbox, Ultimate Grid and Ultimate TCP/IP products sold through The Code Project Storefront. Nish has been working with Microsoft Technologies since the DOS days and is currently exploring .NET 3.0 technologies such as WPF and WCF. Nish loves reading Science Fiction, P G Wodehouse and Agatha Christie. In addition to C++/CLI in Action, Nish has authored Extending MFC applications with the .NET Framework as well as Summer Love and Some More Cricket, a romantic comedy. Presently, he lives in Toronto with his loving wife Smitha.

Read More Show Less

Table of Contents

Preface     xv
Ac1nowledgments     xvii
About this book     xix
The C++/CLI Language     1
Introduction to C++/CLI     3
The role of C++/CLI     4
What C++/CLI can do for you     6
The rationale behind the new syntax     8
Hello World in C++/CLI     13
The /clr compiler option     15
Using VC++ 2005 to create a /clr application     16
Declaring CLR types     18
Class modifiers     20
CLI types and inheritance     22
Handles: the CLI equivalent to pointers     24
Syntax for using handles     24
Tracking references     26
Instantiating CLI classes     28
The gcnew operator     28
Constructors     31
Copy constructors     33
Assignment operators     36
Boxing and unboxing     38
Implicit boxing in the new syntax     38
Boxing and type-safety     40
Implementation at the MSIL level     41
Assigning null to a boxed value type     43
Summary     45
Getting into the CLI: properties, delegates and arrays     46
Properties     47
Scalar Properties     48
Indexed properties     55
Delegates and events     58
Delegates     59
Events     64
CLI Arrays     68
Basic CLI array concepts     69
Single-dimensional arrays     70
Multidimensional arrays     71
Jagged arrays     72
Arrays as function arguments     74
Returning arrays from functions     75
Parameter arrays     76
Using System::Array methods     77
Array covariance     80
Arrays of non-CLI objects     81
Directly accessing CLI arrays using native pointers     83
Summary     84
More C++/CLI: stack semantics, function overriding, and generic programming     86
Stack semantics and deterministic destruction     87
The new destructor and finalizer syntaxes     88
Stack semantics     96
Guidelines for using destructors and stack semantics     101
Function overriding     102
Explicit overriding     103
Renamed overriding     104
Multiple overriding     105
Sealed and abstract functions     106
Generics and managed templates     108
Why have parameterized types?     108
Generics syntax for classes and functions     110
Constraint mechanism     113
Issues with the constraint mechanism and simple types     116
Comparison with templates     120
Managed templates     124
Summary     129
Mixing Managed and Native Code     131
Introduction to mixed-mode programming     133
Using interior and pinning pointers     135
Interior pointers     136
Pinning pointers     141
Working with interop mechanisms     147
Accessing a managed library from native code     148
Accessing a native library from managed code     156
Using mixed types     162
Native types with managed members     162
Managed types with native members     166
Function pointers and delegates: bridging the gap     173
Using GetFuctionPointerForDelegate     173
Using GetDelegateForFunctionPointer     175
Summary     177
Interoping with native libraries from managed applications     179
Converting between managed and native types      181
Marshalling native strings     181
Marshalling arrays     184
Simulating a native static array with managed code     185
Double thunking in mixed-mode function calls     186
Wrapping a native API and exposing a CLI interface     190
Overview of the native API     191
Writing the CLI wrapper     193
Exposing an MFC extension DLL to .NET     206
Overview of the MFC extension DLL     207
Writing the managed regular MFC DLL wrapper     208
Accessing a COM object via a custom RCW     212
The COM object to interop with     212
Writing the custom RCW     215
Using the custom RCW     218
Writing a single mixed-mode DLL for both managed and native clients     218
Wrapping the System::Object class     220
Writing derived class wrappers     223
Summary     227
Using Managed Frameworks from Native Applications     229
Interoping Windows Forms with MFC     231
A simple Windows Forms application     233
Hosting a Windows Forms control in an MFC dialog     235
Hosting a Windows Forms control as an MFC view     239
Giving your MFC apps an Office 2003 style UI     249
Using a Windows Forms control as an MFC dialog     261
Using an MFC control in a Windows Forms form     267
The custom MFC control     268
Hosting the MFC control from WinForms     271
Using the wrapped control from a WinForms app     273
Summary     274
Using C++/CLI to target Windows Presentation Foundation applications     276
What is WPF?     278
Overview of XAML     280
Anatomy of a simple WPF application     283
Using C ++/CLI to write a WPF application     288
Creating a new C++/CLI Avalon project     289
Using procedural code     289
Dynamically loading XAML     294
Deriving from a class in a C# DLL     297
A brief look at some WPF Graphics features     300
Using brushes and shapes     300
Transformations     304
Hosting a WPF control in a native C++ application     310
Using a mixed-mode extension DLL     310
Using a mixed-mode application     319
Hosting a native control in a WPF application     326
Summary     331
Accessing the Windows Communication Foundation with C++/CLI      332
Hello World with the Windows Communication Foundation     334
Duplex communication in WCF     338
Creating the service     340
Creating the client     342
Migrating a native DCOM application to WCF     344
The example DCOM server     346
The native MFC client     348
Writing a WCF proxy service     351
Modifying the MFC client to use WCF     356
Writing a pure WCF service     359
Comparison of the two migration methods     362
Hosting a WCF service in an IIS server     362
Summary     366
A concise introduction to the .NET Framework     368
Index     385
Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star


4 Star


3 Star


2 Star


1 Star


Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation


  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously

    If you find inappropriate content, please report it to Barnes & Noble
    Why is this product inappropriate?
    Comments (optional)