| Preface |
|
xiii | |
|
|
|
1 | (18) |
|
|
|
1 | (2) |
|
|
|
3 | (2) |
|
COM can Run Across Processes |
|
|
3 | (1) |
|
COM Methods Can Be Called Across a Network |
|
|
4 | (1) |
|
COM Objects Must Be Unique Throughout the World |
|
|
5 | (1) |
|
COM is Language Independent |
|
|
5 | (1) |
|
|
|
5 | (2) |
|
|
|
7 | (4) |
|
Interfaces Isolate the Client From the Server |
|
|
8 | (2) |
|
|
|
10 | (1) |
|
|
|
10 | (1) |
|
The Source of All Interfaces - IUnknown |
|
|
10 | (1) |
|
|
|
11 | (1) |
|
How to Be Unique -- the GUID |
|
|
12 | (2) |
|
|
|
14 | (1) |
|
Interactions Between Client and Server |
|
|
15 | (1) |
|
|
|
16 | (3) |
|
TWO Understanding the Simplest COM Client |
|
|
19 | (8) |
|
Four Steps to Client Connectivity |
|
|
20 | (5) |
|
Initializing the COM Subsystem: |
|
|
21 | (1) |
|
Query COM for a Specific Interface |
|
|
22 | (2) |
|
Execute a Method on the Interface |
|
|
24 | (1) |
|
|
|
24 | (1) |
|
|
|
25 | (2) |
|
THREE Understanding a Simple COM Server |
|
|
27 | (16) |
|
|
|
28 | (1) |
|
Building a DLL-Based (In-Process) COM Server |
|
|
29 | (1) |
|
Creating the Server Using the ATL Wizard |
|
|
30 | (3) |
|
|
|
33 | (3) |
|
Adding a Method to the Server |
|
|
36 | (4) |
|
Running the Client and the Server |
|
|
40 | (1) |
|
|
|
41 | (2) |
|
FOUR Creating your own COM Clients and Servers |
|
|
43 | (12) |
|
|
|
43 | (2) |
|
|
|
45 | (10) |
|
FIVE Understanding ATL-Generated Code |
|
|
55 | (12) |
|
|
|
56 | (2) |
|
|
|
58 | (1) |
|
|
|
58 | (2) |
|
The COM Object -- "CBeepObj" |
|
|
60 | (1) |
|
|
|
61 | (1) |
|
|
|
62 | (1) |
|
|
|
63 | (1) |
|
|
|
64 | (1) |
|
|
|
65 | (1) |
|
|
|
66 | (1) |
|
SIX Understanding the Client and Server |
|
|
67 | (24) |
|
|
|
67 | (4) |
|
|
|
68 | (1) |
|
COM is Language-Independent |
|
|
68 | (1) |
|
COM is Built Around the Concept of Transparency |
|
|
69 | (1) |
|
Interfaces are Contracts Between the Client and Server |
|
|
69 | (1) |
|
Software Changes. Interfaces Don't |
|
|
70 | (1) |
|
|
|
71 | (2) |
|
|
|
73 | (12) |
|
VTABLES -- Virtual Function Tables |
|
|
75 | (2) |
|
|
|
77 | (2) |
|
|
|
79 | (2) |
|
Understanding QueryInterface |
|
|
81 | (1) |
|
Reference Counting with AddRef and Release |
|
|
82 | (3) |
|
|
|
85 | (3) |
|
COM Identifiers: CLSID AND IID |
|
|
87 | (1) |
|
|
|
88 | (1) |
|
|
|
88 | (1) |
|
|
|
89 | (2) |
|
SEVEN An Introduction to MIDL |
|
|
91 | (16) |
|
Origins of the MIDL Compiler |
|
|
91 | (4) |
|
Precisely Defining Interfaces with the IDL Language |
|
|
92 | (2) |
|
|
|
94 | (1) |
|
Automatically Generated Proxy/Stub Modules |
|
|
94 | (1) |
|
Automatic Creation of Type Libraries |
|
|
95 | (1) |
|
|
|
95 | (8) |
|
Interfaces and Methods in IDL |
|
|
97 | (3) |
|
The Component Class in IDL |
|
|
100 | (2) |
|
|
|
102 | (1) |
|
|
|
103 | (2) |
|
|
|
105 | (2) |
|
EIGHT Defining and Using Interfaces |
|
|
107 | (18) |
|
|
|
108 | (1) |
|
|
|
109 | (3) |
|
|
|
112 | (1) |
|
|
|
113 | (1) |
|
|
|
113 | (6) |
|
|
|
119 | (2) |
|
Structures and Enumerations |
|
|
121 | (2) |
|
|
|
123 | (2) |
|
NINE OLE Automation and Dual Interfaces |
|
|
125 | (26) |
|
|
|
126 | (1) |
|
|
|
127 | (6) |
|
|
|
133 | (3) |
|
Using Type Libraries for Early Binding |
|
|
136 | (1) |
|
|
|
137 | (3) |
|
There is no Proxy/Stub DLL for Dispatch Interfaces |
|
|
140 | (1) |
|
|
|
140 | (2) |
|
Adding Properties with the Class Wizard |
|
|
142 | (2) |
|
|
|
144 | (1) |
|
The ISupportErrorInfo Interface |
|
|
144 | (5) |
|
|
|
149 | (2) |
|
|
|
151 | (16) |
|
Synchronization and Marshaling |
|
|
151 | (2) |
|
|
|
153 | (2) |
|
Apartment, Free, and Single Threads |
|
|
155 | (1) |
|
The ATL Wizard and Threading Models |
|
|
156 | (2) |
|
|
|
158 | (1) |
|
|
|
159 | (1) |
|
|
|
160 | (1) |
|
|
|
161 | (1) |
|
Marshaling Between Threads |
|
|
162 | (1) |
|
|
|
163 | (1) |
|
|
|
164 | (1) |
|
Testing the Different Models |
|
|
165 | (1) |
|
|
|
166 | (1) |
|
|
|
167 | (14) |
|
The COM Registry Structure |
|
|
168 | (3) |
|
|
|
171 | (1) |
|
|
|
172 | (2) |
|
|
|
174 | (1) |
|
Self-Registration in ATL Servers |
|
|
174 | (1) |
|
|
|
175 | (2) |
|
Automatic Registration of Remote Servers |
|
|
177 | (1) |
|
|
|
178 | (1) |
|
|
|
178 | (1) |
|
|
|
178 | (3) |
|
TWELVE Callback Interfaces |
|
|
181 | (32) |
|
Client and Server Confusion |
|
|
183 | (2) |
|
Custom Callback Interfaces |
|
|
183 | (2) |
|
|
|
185 | (2) |
|
|
|
185 | (1) |
|
Add a COM Object to the Server |
|
|
186 | (1) |
|
Adding the ICallBack Interface to IDL |
|
|
187 | (2) |
|
|
|
187 | (1) |
|
Adding the Advise Method to the Server |
|
|
188 | (1) |
|
Adding the UnAdvise Method |
|
|
189 | (2) |
|
Calling the Client from the Server |
|
|
189 | (2) |
|
|
|
191 | (5) |
|
Create the Client Dialog Application |
|
|
191 | (1) |
|
Adding the Callback COM Object |
|
|
192 | (2) |
|
Linking to the Server Headers |
|
|
194 | (1) |
|
|
|
194 | (1) |
|
Implementing the Callback Method |
|
|
195 | (1) |
|
|
|
195 | (1) |
|
|
|
196 | (5) |
|
|
|
199 | (1) |
|
|
|
199 | (2) |
|
|
|
201 | (2) |
|
|
|
203 | (2) |
|
Starting the Worker Thread |
|
|
205 | (1) |
|
Marshaling the Interface Between Threads |
|
|
206 | (1) |
|
Starting the Worker Thread: Part 2 |
|
|
207 | (4) |
|
A Simple Worker Thread Class |
|
|
208 | (1) |
|
Implementing the Worker Thread |
|
|
209 | (2) |
|
All Good Threads Eventually Die |
|
|
211 | (1) |
|
|
|
211 | (2) |
|
THIRTEEN Connection Points |
|
|
213 | (16) |
|
Modifying the Callback Server |
|
|
215 | (5) |
|
Adding Connection Points to the Client Program |
|
|
220 | (2) |
|
Add the Callback Object to the Client |
|
|
221 | (1) |
|
Modifying the CpClient Application |
|
|
221 | (1) |
|
Registering With the Server's Connection Point Interface |
|
|
222 | (4) |
|
Adding the Now and Later Buttons |
|
|
226 | (1) |
|
Using the Connection Point-the Server Side |
|
|
226 | (2) |
|
|
|
228 | (1) |
|
|
|
228 | (1) |
|
|
|
229 | (16) |
|
An Overview of Remote Connections |
|
|
229 | (2) |
|
Converting a Client for Remote Access |
|
|
231 | (3) |
|
|
|
234 | (1) |
|
|
|
234 | (1) |
|
|
|
235 | (1) |
|
|
|
236 | (1) |
|
|
|
237 | (1) |
|
|
|
237 | (1) |
|
|
|
238 | (1) |
|
|
|
239 | (1) |
|
|
|
239 | (3) |
|
|
|
242 | (1) |
|
Using the Registry for Remote Connections |
|
|
243 | (1) |
|
Installing the Server on a Remote Computer |
|
|
244 | (1) |
|
FIFTEEN ATL and Compiler Support |
|
|
245 | (18) |
|
|
|
245 | (1) |
|
|
|
246 | (1) |
|
ATL -- The Choice for Servers |
|
|
246 | (1) |
|
|
|
247 | (6) |
|
A Simple Template Example |
|
|
248 | (2) |
|
|
|
250 | (3) |
|
Native Compiler Directives |
|
|
253 | (7) |
|
|
|
253 | (1) |
|
|
|
254 | (1) |
|
|
|
255 | (1) |
|
|
|
256 | (1) |
|
Watch Out for Destructors |
|
|
257 | (1) |
|
Smart Pointer Error Handling |
|
|
258 | (2) |
|
How the IMPORT Directive Works |
|
|
260 | (1) |
|
|
|
260 | (1) |
|
|
|
261 | (2) |
|
|
|
263 | (14) |
|
|
|
263 | (4) |
|
|
|
265 | (1) |
|
|
|
265 | (1) |
|
Customer Code Flag and Reserved bits |
|
|
266 | (1) |
|
|
|
266 | (1) |
|
|
|
266 | (1) |
|
|
|
267 | (1) |
|
Displaying Error Messages |
|
|
267 | (2) |
|
|
|
268 | (1) |
|
Aggregation and Containment |
|
|
269 | (2) |
|
Building a COM Object with MFC |
|
|
271 | (6) |
|
Adding Code for the Nested Classes |
|
|
273 | (2) |
|
Accessing the Nested Class |
|
|
275 | (2) |
|
APPENDIX COM Error Handling |
|
|
277 | (14) |
|
|
|
278 | (1) |
|
|
|
279 | (6) |
|
|
|
285 | (4) |
|
|
|
285 | (1) |
|
|
|
286 | (1) |
|
Try Using a TCP/IP Address |
|
|
287 | (1) |
|
|
|
287 | (1) |
|
Windows 95/98 Systems Will Not Launch Servers |
|
|
288 | (1) |
|
|
|
288 | (1) |
|
Using the OLE/COM Object Viewer |
|
|
289 | (2) |
| Index |
|
291 | |