Preface
Shifting from C++ to COM
1. Define your interfaces before you define your classes(and do it in IDL).
2. Design with distribution in mind.
3. Objects should not have their own user interface.
4. Beware the COM singleton.
5. Don't allow C++ exceptions to cross method boundaries.
Interfaces
6. Interfaces are syntax and loose semantics. Both are immutable.
7. Avoid E_NOTIMPL.
8. Prefer typed data to opaque data.
9. Avoid connection points.
10. Don's provide more than one implementation of the same interface on asingle object.
11. Typeless languages lose the benefits of COM.
12. Dual interfaces are a hack.Don't require people to implement them.
13. Choose the right array type(avoid open and varying arrays).
14. Avoid passing IUnknown as a statically typed object reference(use iid_is).
15. Avoid[in,out]parameters that contain pointers.
16. Be conscious of cyclic references(and the problems they cause).
17. Avoid wire_marshal,transmit_as,call_as,and cpp_quote.
Implementations
18. Code defensively.
19. Always initialize[out]parameters.
20. Don't use interface pointers that have not been AddRef'ed
21. Use static_cast when bridging between the C++ type system and the COM type system.
22. Smart interface pointers add at least as much complexity as they remove.
23. Don't hand-optimize reference counting.
24. Implement enumerators using lazy evaluation.
25. Use flyweights where appropriate.
26. Avoid using tearoffs across apartment boundaries.
27. Be especially careful with BSTRs.
28. COM aggregation and COM containment are for identity tricks, not code reuse.
Apartments
29. Don't access raw interface pointers across apartment boundaries.
30. When passing an interface pointer between one MTA thread and another, use AddRef.
31. User-interface threads and objects must run in single-threaded apartment(STAs).
32. Avoid creating threads from an in-process server.
33. Beware the Free-Threaded Marshaler(FTM).
34. Beware physical locks in the MTA.
35. STAs may need locks too.
36. Avoid extant marshals on in-process objects.
37. Use CoDisconnectObject to inform the stub when you go away prematurely.
Security
38. CoInitializeSecurity is your friend.Learn it,love it,call it.
39. Avoid As-Activator activation.
40. Avoid impersonation.
41. Use fine-grained authentication.
42. Use fine-grained access control.
Transactions
43. Keep transactions as short as possible.
44. Always use SafeRef when handing out pointers to your own object.
45. Don't share object references across activity boundaries.
46. Beware of exposing object references from themiddle of a transaction hierarchy.
47. Beware of committing a transaction implicitly.
48. Use no transactional objects where appropriate.
49. Move nontrivial initialization to IObjectControl::Activate.
50. Don't rely on JIT activation and ASAP deactivation to achieve scalability.
Epilogue
About the Authrs
Index
COM是面向对象分布式应用程序开发中重要的中间层技术。本书作者根据自己多年COM实际开发的经验和心得,总结出了50条重要的规律,并归纳为6大类:从C++到COM的过渡,接口及COM开发基本要素,实施问题,apartment有关概念,安全性,事务。另外,还通过网站提供了书中的代码。
本书适合有经验的C++、COM及MTS程序开发人员阅读。
Don Box,Keith Brown,Tim Ewald,and Chris Sells work together as COM educators at DevelopMentro, a leading COM deucation firm.As co-founder of DevelopMentor,Don Box has consulted on such COM-based profects as Microsoft's MTS and Software AG'S port of COM to the solaris operating system.Keith Brown has worked with COM Since its appearance in 1993.In addition to his work at DevelopMentor,he Writes the Security Q&A colun for Microsoft Systems Journal Tim Ewald is a Principal Scientist at DevelpMentor,where he focuses on COM-related research and development.chris Sells,a C++ adn COM instructor for DeveopMentor,is an independent consultant specializing in designing and buiding distributed systems using COM. for more information about the authors,please see the biographies at the back of this book.