没有合适的资源?快使用搜索试试~ 我知道了~
首页Expert Visual C++_CLI.pdf
Expert Visual C++_CLI.pdf
需积分: 9 92 浏览量
更新于2023-03-16
评论
收藏 2.99MB PDF 举报
Expert C++/CLI: .NET for Visual C++ Programmers Several members of the Visual C++ team have been great sources for in-depth informa- tion about implementation details of C++/CLI and the CLR. These guys are Martyn Lovell, Brandon Bray, Arjun Bijanki, Jeff Peil, Herb Sutter, Ayman Shoukry, and Bill Dunlap. Many top- ics that I cover in this book are insights that I got from them.
资源详情
资源评论
资源推荐

Expert C++/CLI: .NET for Visual C++ Programmers
Copyright © 2007 by Marcus Heege
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means,
electronic or mechanical, including photocopying, recording, or by any information storage or retrieval
system, without the prior written permission of the copyright owner and the publisher.
ISBN-13: 978-1-59059-756-9
ISBN-10: 1-59059-756-7
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1
Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence
of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark
owner, with no intention of infringement of the trademark.
Lead Editor: James Huddleston
Technical Reviewer: Stanley Lippman
Editorial Board: Steve Anglin, Ewan Buckingham, Gary Cornell, Jason Gilmore, Jonathan Gennick,
Jonathan Hassell, James Huddleston, Chris Mills, Matthew Moodie, Jeff Pepper, Paul Sarknas,
Dominic Shakeshaft, Jim Sumser, Matt Wade
Project Manager: Elizabeth Seymour
Copy Edit Manager: Nicole Flores
Copy Editor: Damon Larson
Assistant Production Director: Kari Brooks-Copony
Production Editor: Lori Bring
Compositor: Gina Rexrode
Proofreader: Patrick Vincent
Indexer: Brenda Miller
Artist: April Milne
Cover Designer: Kurt Krames
Manufacturing Director: Tom Debolski
Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor,
New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders-ny@springer-sbm.com, or
visit http://www.springeronline.com.
For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley,
CA 94710. Phone 510-549-5930, fax 510-549-5939, e-mail info@apress.com, or visit http://www.apress.com.
The information in this book is distributed on an “as is” basis, without warranty. Although every precau-
tion has been taken in the preparation of this work, neither the author(s) nor Apress shall have any
liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly
or indirectly by the information contained in this work.
The source code for this book is available to readers at http://www.apress.com in the Source Code/
Download section.
www.it-ebooks.info

Contents at a Glance
About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
About the Technical Reviewer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
■CHAPTER 1 Why C++/CLI?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
■CHAPTER 2 Managed Types, Instances, and Memory. . . . . . . . . . . . . . . . . . . . . . . . 11
■CHAPTER 3 Writing Simple .NET Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
■CHAPTER 4 Assemblies, Metadata, and Runtime Services . . . . . . . . . . . . . . . . . . 49
■CHAPTER 5 Defining Managed Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
■CHAPTER 6 Special Member Functions and Resource Management . . . . . . . . 117
■CHAPTER 7 Using C++/CLI to Extend Visual C++ Projects
with Managed Code
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
■CHAPTER 8 Mixing the Managed and the Native Type System . . . . . . . . . . . . . . 173
■CHAPTER 9 Managed-Unmanaged Transitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
■CHAPTER 10 Wrapping Native Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
■CHAPTER 11 Reliable Resource Management. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
■CHAPTER 12 Assembly Startup and Runtime Initialization. . . . . . . . . . . . . . . . . . . 279
■APPENDIX A Programmatically Updating the .NET Security Policy . . . . . . . . . . . 303
■APPENDIX B Measuring the Performance of Thunks . . . . . . . . . . . . . . . . . . . . . . . . 307
■INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
iii
www.it-ebooks.info

Contents
About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
About the Technical Reviewer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
■CHAPTER 1 Why C++/CLI?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Extending C++ with .NET Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
What Is .NET?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
What Is C++/CLI? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Building C++/CLI Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Object File Compatibility. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Interaction Between Managed and Unmanaged Code . . . . . . . . . . . . . . . . . 6
DLLs with Managed Entry Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Compilation Models. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Wrapping Native Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
■CHAPTER 2 Managed Types, Instances, and Memory. . . . . . . . . . . . . . . . . . 11
System::Object. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Primitive Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Custom CTS Type Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Managed Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Managed Heap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Tracking Handles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Values and Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Value Types and Reference Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Boxing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Unboxing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
System::String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Managed Arrays. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Managed Array Initialization. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Iterating Through an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Managed Arrays of Tracking Handles . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
v
www.it-ebooks.info
剩余342页未读,继续阅读
















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0