did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

We're the #1 textbook rental company. Let us show you why.

9780201379686

Effective COM 50 Ways to Improve Your COM and MTS-based Applications

by ; ; ;
  • ISBN13:

    9780201379686

  • ISBN10:

    0201379686

  • Edition: 1st
  • Format: Paperback
  • Copyright: 1998-12-03
  • Publisher: Addison-Wesley Professional

Note: Supplemental materials are not guaranteed with Rental or Used book purchases.

Purchase Benefits

  • Free Shipping Icon Free Shipping On Orders Over $35!
    Your order must be $35 or more to qualify for free economy shipping. Bulk sales, PO's, Marketplace items, eBooks and apparel do not qualify for this offer.
  • eCampus.com Logo Get Rewarded for Ordering Your Textbooks! Enroll Now
List Price: $44.95 Save up to $11.24
  • Buy Used
    $33.71

    USUALLY SHIPS IN 2-4 BUSINESS DAYS

Supplemental Materials

What is included with this book?

Summary

The evolution of the Component Object Model (COM) has in many ways paralleled the evolution of C++. Both movements shared a common goal of achieving better reuse and modularity through refinements to an existing programming model. In the case of C++, the preceding model was procedural programming in C, and C++'s added value was its support for class-based object-oriented programming. In the case of COM, the preceding model was class-based programming in C++, and COM's added value is its support for interface-based object-oriented programming.

As C++ evolved, its canon evolved as well. One notable work in this canon was Scott Meyers' Effective C++. This text was perhaps the first text that did not try to teach the reader the basic mechanics and syntax of C++. Rather, Effective C++ was targeted at the working C++ practitioner and offered 50 concrete rules that all C++ developers should follow to craft reasonable C++-based systems. The success of Effective C++ required a critical mass of practitioners in the field working with the technology. Additionally, Effective C++ relied on a critical mass of supporting texts in the canon. At the time of its initial publication, the supporting texts were primarily The C++ Programming Language by Stroustrup and The C++ Primer by Lippman, although a variety of other introductory texts were also available.

The COM programming movement has reached a similar state of critical mass. Given the mass adoption of COM by Microsoft as well as many other development organizations, the number of COM developers is slowly but surely approaching the number of Windows developers. Also, five years after its first public release, there is finally a sufficiently large canon to lay the tutorial groundwork for a more advanced text. To this end, Effective COM represents a homage to Scott Meyers' seminal work and attempts to provide a book that is sufficiently approachable that most working developers can easily find solutions to common design and coding problems.

Virtually all existing COM texts assume that the reader has no COM knowledge and focus most of their attention on teaching the basics. Effective COM attempts to fill a hole in the current COM canon by providing guidelines that transcend basic tutorial explanations of the mechanics or theory of COM. These concrete guidelines are based on the authors' experiences working with and training literally thousands of COM developers over the last four years as well as on the communal body of knowledge that has emerged from various Internet-based forums, the most important of which is the DCOM mailing list hosted at DCOM-request@discuss.microsoft.com.

This book owes a lot to the various reviewers who offered feedback during the book's development. These reviewers included Saji Abraham, David Chappell, Steve DeLassus, Richard Grimes, Martin Gudgin, Ted Neff, Mike Nelson, Peter Partch, Wilf Russell, Ranjiv Sharma, George Shepherd, and James Sievert. Special thanks go to George Reilly, whose extensive copyediting showed the authors just how horrible their grammar really is. Any errors that remain are the responsibility of the authors. You can let us know about these errors by sending mail to effectiveerrata@develop.com. Any errata or updates to the book will be posted to the book's Web page, http://www.develop.com/effectivecom.

The fact that some of the guidelines presented in this book fly in the face of popular opinion and/or "official" documentation from Microsoft may at first be confusing to the reader. We encourage you to test our assertions against your current beliefs and let us know what you find. The four authors can be reached en masse by sending electronic mail to effectivecom@develop.com.

Intended Audience

This book is targeted at developers currently using the Component Object Model and Microsoft Transaction Server (MTS) to develop software. Effective COM is not a tutorial or primer; rather, it assumes that the reader has already tackled at least one pilot project in COM and has been humbled by the complexity and breadth of distributed object computing. This book also assumes that the reader is at least somewhat familiar with the working vocabulary of COM as it is described in Essential COM. The book is targeted primarily at developers who work in C++; however, many of the topics (e.g., interface design, security, transactions) are approachable by developers who work in Visual Basic, Java, or Object Pascal.

What to Expect

The book is arranged in six chapters. Except for the first chapter, which addresses the cultural differences between "100% pure" C++ and COM, each chapter addresses one of the core atoms of COM.

Shifting from C++ to COM

Developers who work in C++ have the most flexibility when working in COM. However, it is these developers who must make the most adjustments to accommodate COM-based development. This chapter offers five concrete guidelines that make the transition from pure C++ to COM-based development possible. Aspects of COM/C++ discussed include exception handling, singletons, and interface-based programming.

Interfaces

The most fundamental atom of COM development is the interface. A well-designed interface will help increase system efficiency and usability. A poorly designed interface will make a system brittle and difficult to use. This chapter offers 12 concrete guidelines that help COM developers design interfaces that are efficient, correct, and approachable. Aspects of interface design discussed include round-trip optimization, semantic correctness, and common design flaws.

Implementations

Writing COM code in C++ requires a raised awareness of details, irrespective of the framework or class library used to develop COM components. This chapter offers 11 concrete guidelines that help developers write code that is efficient, correct, and maintainable. Aspects of COM implementation discussed include reference counting, memory optimization, and type-system errors.

Apartments

Perhaps one of the most perplexing aspects of COM is its concept of an apartment. Apartments are used to model concurrency in COM and do not have analogues in most operating systems or languages. This chapter offers nine concrete guidelines that help developers ensure that their objects operate properly in a multithreaded environment. Aspects of apartments discussed include real-world lock management, common marshaling errors, and life-cycle management.

Security

One of the few areas of COM that is more daunting than apartments is security. Part of this is due to the aversion to security that is inherent in most developers, and part is due to the fairly arcane and incomplete documentation that has plagued the security interfaces of COM. This chapter offers five concrete guidelines that distill the security solution space of COM. Aspects of security discussed include access control, authentication, and authorization.

Transactions

Many pages of print have been dedicated to Microsoft Transaction Server, but precious few of them address the serious issues related to the new transactional programming model implied by MTS. This chapter offers eight concrete pieces of advice that will help make your MTS-based systems more efficient, scalable, and correct. Topics discussed include the importance of interception, activity-based concurrency management, and the dangers of relying on just-in-time activation as a primary mechanism for enhancing scalability.

Acknowledgments

First and foremost, Chris woul

Author Biography

Don Box is a leading educator, recognized authority on the Component Object Model (COM), coauthor of the Simple Object Access Protocol (SOAP) specification, and coiner of the term "COM is Love." He recently joined Microsoft as an architect in the Microsoft® .NET Developer and Platform Evangelism Group.

Earlier in his career, Box cofounded DevelopMentor Inc., a component software think tank aimed at educating developers on the use of the COM, Java, and XML. A popular public speaker, Box is known for engaging audiences around the world, combining deep technical insight with often outrageous stunts.

Keith Brown focuses on application security at Pluralsight, which he cofounded with several other .NET experts to foster a community, develop content, and provide premier training. Keith regularly speaks at conferences, including TechEd and WinDev, and serves as a contributing editor and columnist to MSDN Magazine.

Tim Ewald is a Director of Content at DevelopMentor, a premier developer services company. His research and development work focuses on the design and implementation of scalable systems using component technologies such as COM and Java. Tim has authored or co-authored several DevelopMentor courses, including the MTS and COM+ curriculum. He is also a co-author of Effective COM (Addison-Wesley), a former columnist for DOC and Application Strategies, and a frequent conference speaker. Before joining DevelopMentor, Tim worked as an independent consultant specializing in COM and related technologies.

Chris Sells is a content strategist on the Microsoft MSDN content team. Previously, he was the director of software engineering at DevelopMentor. Chris is the author of Windows Telephony Programming (Addison-Wesley, 1998) and Windows Forms Programming in Visual Basic .NET (Addison-Wesley, 2004), and coauthor of Effective COM (Addison-Wesley, 1999), ATL Internals (Addison-Wesley, 1999), and Essential .NET, Volume 1 (Addison-Wesley, 2003).



Table of Contents

Preface ix
Shifting from C++ to COM 1(30)
1. Define your interfaces before you define your classes (and do it in IDL).
1(7)
2. Design with distribution in mind.
8(9)
3. Objects should not have their own user interface.
17(2)
4. Beware the COM singleton.
19(4)
5. Don't allow C++ exceptions to cross method boundaries.
23(8)
Interfaces 31(50)
6. Interfaces are syntax and loose semantics. Both are immutable.
31(5)
7. Avoid E_NOTIMPL.
36(2)
8. Prefer typed data to opaque data.
38(5)
9. Avoid connection points.
43(4)
10. Don't provide more than one implementation of the same interface on a single object.
47(5)
11. Typeless languages lose the benefits of COM.
52(5)
12. Dual interfaces are a back. Don't require people to implement them.
57(3)
13. Choose the right array type (avoid open and varying arrays).
60(5)
14. Avoid passing IUnknown as a statically typed object reference (use iid_is)
65(3)
15. Avoid [in, out] parameters that contain pointers.
68(4)
16. Be conscious of cyclic references (and the problems they cause).
72(4)
17. Avoid wire_marshal, transmit_as, call_as, and cpp_quote.
76(5)
Implementations 81(44)
18. Code defensively.
81(4)
19. Always initialize [out] parameters.
85(5)
20. Don't use interface pointers that have not been AddRef' ed
90(8)
21. Use static_cast when bridging between the C++ type system and the COM type system.
98(3)
22. Smart interface pointers add at least as much complexity as they remove.
101(6)
23. Don't hand-optimize reference counting.
107(2)
24. Implement enumerators using lazy evaluation.
109(3)
25. Use flyweights where appropriate.
112(3)
26. Avoid using tearoffs across apartment boundaries.
115(3)
27. Be especially careful with BSTRs.
118(2)
28. COM aggregation and COM containment are for identity tricks, not code reuse.
120(5)
Apartments 125(30)
29. Don't access raw interface pointers across apartment boundaries.
125(4)
30. When passing an interface pointer between one MTA thread and another, use AddRef.
129(2)
31. User-interface threads and objects must run in single-threaded apartments (STAs).
131(2)
32. Avoid creating threads from an in-process server.
133(3)
33. Beware the Free-Threaded Marshaler (FTM).
136(6)
34. Beware physical locks in the MTA.
142(4)
35. STAs may need locks too.
146(5)
36. Avoid extant marshals on in-process objects.
151(3)
37. Use CoDisconnectObject to inform the stub when you go away prematurely.
154(1)
Security 155(28)
38. CoInitializeSecurity is your friend. Learn it, love it, call it.
155(8)
39. Avoid As-Activator activation.
163(4)
40. Avoid impersonation.
167(4)
41. Use fine-grained authentication.
171(7)
42. Use fine-grained access control.
178(5)
Transactions 183(18)
43. Keep transactions as short as possible.
183(2)
44. Always use SafeRef when handing out pointers to your own object.
185(3)
45. Don't share object references across activity boundaries.
188(3)
46. Beware of exposing object references from the middle of a transaction hierarchy.
191(3)
47. Beware of committing a transaction implicitly.
194(1)
48. Use nontransactional objects where appropriate.
195(3)
49. Move nontrivial initialization to IObjectControl::Activate
198(1)
50. Don't rely on JIT activation and ASAP deactivation to achieve scalability.
199(2)
Epilogue 201(2)
About the Authors 203(2)
Index 205

Supplemental Materials

What is included with this book?

The New copy of this book will include any supplemental materials advertised. Please check the title of the book to determine if it should include any access cards, study guides, lab manuals, CDs, etc.

The Used, Rental and eBook copies of this book are not guaranteed to include any supplemental materials. Typically, only the book itself is included. This is true even if the title states it includes any access cards, study guides, lab manuals, CDs, etc.

Excerpts

The evolution of the Component Object Model (COM) has in many ways paralleled the evolution of C++. Both movements shared a common goal of achieving better reuse and modularity through refinements to an existing programming model. In the case of C++, the preceding model was procedural programming in C, and C++'s added value was its support for class-based object-oriented programming. In the case of COM, the preceding model was class-based programming in C++, and COM's added value is its support for interface-based object-oriented programming.As C++ evolved, its canon evolved as well. One notable work in this canon was Scott Meyers'Effective C++. This text was perhaps the first text that did not try to teach the reader the basic mechanics and syntax of C++. Rather,Effective C++ was targeted at the working C++ practitioner and offered 50 concrete rules that all C++ developers should follow to craft reasonable C++-based systems. The success ofEffective C++ required a critical mass of practitioners in the field working with the technology. Additionally,Effective C++ relied on a critical mass of supporting texts in the canon. At the time of its initial publication, the supporting texts were primarilyThe C++ Programming Languageby Stroustrup andThe C++ Primerby Lippman, although a variety of other introductory texts were also available.The COM programming movement has reached a similar state of critical mass. Given the mass adoption of COM by Microsoft as well as many other development organizations, the number of COM developers is slowly but surely approaching the number of Windows developers. Also, five years after its first public release, there is finally a sufficiently large canon to lay the tutorial groundwork for a more advanced text. To this end,Effective COMrepresents a homage to Scott Meyers' seminal work and attempts to provide a book that is sufficiently approachable that most working developers can easily find solutions to common design and coding problems.Virtually all existing COM texts assume that the reader has no COM knowledge and focus most of their attention on teaching the basics.Effective COMattempts to fill a hole in the current COM canon by providing guidelines that transcend basic tutorial explanations of the mechanics or theory of COM. These concrete guidelines are based on the authors' experiences working with and training literally thousands of COM developers over the last four years as well as on the communal body of knowledge that has emerged from various Internet-based forums, the most important of which is the DCOM mailing list hosted at DCOM-request@discuss.microsoft.com.This book owes a lot to the various reviewers who offered feedback during the book's development. These reviewers included Saji Abraham, David Chappell, Steve DeLassus, Richard Grimes, Martin Gudgin, Ted Neff, Mike Nelson, Peter Partch, Wilf Russell, Ranjiv Sharma, George Shepherd, and James Sievert. Special thanks go to George Reilly, whose extensive copyediting showed the authors just how horrible their grammar really is. Any errors that remain are the responsibility of the authors. You can let us know about these errors by sending mail to effectiveerrata@develop.com . Any errata or updates to the book will be posted to the book's Web page, http://www.develop.com/effectivecom.The fact that some of the guidelines presented in this book fly in the face of popular opinion and/or "official" documentation from Microsoft may at first be confusing to the reader. We encourage you to test our assertions against your current beliefs and let us know what you find. The four authors can be reacheden masseby sending electronic mail to effectivecom@dev

Rewards Program