c/cli in action

416 1.4K 0
c/cli in action

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

www.it-ebooks.info C++/CLI in Action www.it-ebooks.info www.it-ebooks.info C++/CLI in Action NISHANT SIVAKUMAR MANNING Greenwich (74° w. long.) www.it-ebooks.info For online information and ordering of this and other Manning books, please go to www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact: Special Sales Department Manning Publications Co. Sound View Court 3B Fax: (609) 877-8256 Greenwich, CT 06830 Email: orders@manning.com ©2007 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books they publish printed on acid-free paper, and we exert our best efforts to that end. Manning Publications Co. Copyeditor: Tiffany Taylor Sound View Court 3B Typesetter: Denis Dalinnik Greenwich, CT 06830 Cover designer: Leslie Haimes ISBN 1-932394-81-8 Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – MAL – 11 10 09 08 07 www.it-ebooks.info To my loving wife Smitha, who put up with my long hours of work on the book and constantly supplied me with coffee to keep me alert and awake. Without her presence, patience, and support, this book would not have been possible. www.it-ebooks.info www.it-ebooks.info vii PART 1 THE C++/CLI LANGUAGE 1 1 ■ Introduction to C++/CLI 3 2 ■ Getting into the CLI: properties, delegates and arrays 46 3 ■ More C++/CLI: stack semantics, function overriding, and generic programming 86 PART 2 MIXING MANAGED AND NATIVE CODE 131 4 ■ Introduction to mixed-mode programming 133 5 ■ Interoping with native libraries from managed applications 179 PART 3 USING MANAGED FRAMEWORKS FROM NATIVE APPLICATIONS 229 6 ■ Interoping Windows Forms with MFC 231 7 ■ Using C++/CLI to target Windows Presentation Foundation applications 276 8 ■ Accessing the Windows Communication Foundation with C++/CLI 332 brief contents www.it-ebooks.info www.it-ebooks.info ix preface xv acknowledgments xvii about this book xix PART 1 THE C++/CLI LANGUAGE 1 1 Introduction to C++/CLI 3 1.1 The role of C++/CLI 4 What C++/CLI can do for you 6 ■ The rationale behind the new syntax 8 1.2 Hello World in C++/CLI 13 The /clr compiler option 15 ■ Using VC++ 2005 to create a /clr application 16 1.3 Declaring CLR types 18 Class modifiers 20 ■ CLI types and inheritance 22 1.4 Handles: the CLI equivalent to pointers 24 Syntax for using handles 24 ■ Tracking references 26 1.5 Instantiating CLI classes 28 The gcnew operator 28 ■ Constructors 31 Copy constructors 33 ■ Assignment operators 36 contents www.it-ebooks.info [...]... 3.4 Summary 129 www.it-ebooks.info 46 CONTENTS xi PART 2 MIXING MANAGED AND NATIVE CODE 131 4 Introduction to mixed-mode programming 4.1 Using interior and pinning pointers Interior pointers 4.2 136 ■ 133 135 Pinning pointers 141 Working with interop mechanisms 147 Accessing a managed library from native code 148 Accessing a native library from managed code 156 4.3 Using mixed types 162 Native types... accompany many of the listings, highlighting important concepts In some cases, numbered bullets link to explanations that follow the listing Source code for all of the working examples in this book is available for download from www.manning.com/sivakumar or www.manning.com/C++/CLI inAction Author Online Purchase of C++/CLI in Action includes free access to a private web forum run by Manning Publications where... Function pointers and delegates: bridging the gap 173 Using GetFunctionPointerForDelegate Using GetDelegateForFunctionPointer 4.5 5 Summary 173 175 177 Interoping with native libraries from managed applications 179 5.1 Converting between managed and native types 181 Marshalling native strings 181 Marshalling arrays 184 Simulating a native static array with managed code 185 ■ 5.2 Double thunking in mixed-mode... CONTENTS 5.6 Writing a single mixed-mode DLL for both managed and native clients 218 Wrapping the System::Object class 220 Writing derived class wrappers 223 5.7 Summary 227 PART 3 USING MANAGED FRAMEWORKS FROM NATIVE APPLICATIONS 6 Interoping Windows Forms with MFC 231 6.1 A simple Windows Forms application 6.2 Hosting a Windows Forms control in an MFC dialog 235 6.3 Hosting a Windows Forms control... is brief and introductory in nature; the chapter’s main focus is interoping WPF with native code Examples show how to host WPF controls in a native app and also how to do the reverse: host native controls in a WPF app Chapter 8 briefly introduces WCF as an analogous technology to DCOM The chapter begins with a few basic examples of writing and consuming a WCF service The main example in the chapter... Mike Stephens from Manning Publications asked if I would be interested in writing for Manning We discussed some issues with C++ experts, including several MVPs and Microsoft VC++ team members, and we finally decided on a tentative table of contents The next half year saw me working on the book, and the result is what you’re holding in your hands (unless you’re reading the e-book, in which case the previous... list of his articles, writings, and ideas about VC++, MFC, NET, and C++/CLI Nish blogs about technology and his life at blog.voidnish.com About the title By combining introductions, overviews, and how-to examples, the In Action books are designed to help learning and remembering According to research in cognitive science, the things people remember are things they discover during self-motivated exploration... exploration Although no one at Manning is a cognitive scientist, we are convinced that for learning to become permanent it must pass through stages of exploration, play, and, interestingly, re-telling of what is being learned People understand and remember new things, which is to say they master them, only after actively exploring them Humans learn in action An essential part of an In Action guide is that it... to the AO remains voluntary (and unpaid) We suggest you try asking the author some challenging questions, lest his interest stray! The Author Online forum and the archives of previous discussions will be accessible from the publisher’s website as long as the book is in print About the author Nishant Sivakumar is a software developer living in Atlanta who has been coding since 1990 Originally from sunny... Forms control as an MFC view 6.4 Giving your MFC apps an Office 2003 style UI 6.5 Using a Windows Forms control as an MFC dialog 261 6.6 Using an MFC control in a Windows Forms form 233 239 249 267 The custom MFC control 268 Hosting the MFC control from WinForms 271 Using the wrapped control from a WinForms app 273 ■ ■ 6.7 7 Summary 274 Using C++/CLI to target Windows Presentation Foundation applications . 131 4 Introduction to mixed-mode programming 133 4.1 Using interior and pinning pointers 135 Interior pointers 136 ■ Pinning pointers 141 4.2 Working with interop mechanisms 147 Accessing a. www.it-ebooks.info C++/CLI in Action www.it-ebooks.info www.it-ebooks.info C++/CLI in Action NISHANT SIVAKUMAR MANNING Greenwich (74° w. long.) www.it-ebooks.info For online information and ordering. 249 6.5 Using a Windows Forms control as an MFC dialog 261 6.6 Using an MFC control in a Windows Forms form 267 The custom MFC control 268 ■ Hosting the MFC control from WinForms 271 ■ Using

Ngày đăng: 05/05/2014, 11:14

Mục lục

    C++/CLI in Action

    About the cover illustration

    Part 1 - The C++/CLI Language

    Introduction to C++/CLI

    1.1 The role of C++/CLI

    1.1.1 What C++/CLI can do for you

    1.1.2 The rationale behind the new syntax

    1.2 Hello World in C++/CLI

    1.2.1 The /clr compiler option

    1.2.2 Using VC++ 2005 to create a /clr application

Tài liệu cùng người dùng

Tài liệu liên quan