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't provide more than one implementation of the same interface on a single 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 contatin 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 betwwen 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 apartments(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.ConInitializeSecurity is your friend.Learn it,love it,call it.
39.Avoid As-Activator activation.
40.Avoid impersonation.
41.Use fine-grained awthentication.
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 the middle of a transaction hierarchy.
47.Beware of committing a transaction implicitly.
48.Use nontransactional 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 Authors
Index