Attributes Tutorial
Using Visual C++ and attributes, you can speed up and simplify the process of COM programming. This tutorial uses attributes to implement both a client and a server application. During the course of this tutorial, you will use attributes and events.
The tutorial develops a singleton server object (an object that can have only one instance) that has its own dual interface and a dispatch interface used for firing off events. The server object takes data, given to it through the Send method of its dual interface, and transmits it to all connected components through the Transfer event on its dispatch interface.
In addition, the tutorial implements a client (an ActiveX control) that contains a server object. The control responds to the Transfer event fired by the server object and has its own dual interface that implements several methods: Connect, Send, and Disconnect. If the Transfer event is fired with a variant containing a BSTR, the string is displayed in the center of the control.
The tutorial is divided into seven steps, each building on the application developed in the previous step.
- Step 1: Creating the Projects
- Step 2: Adding the Server Object
- Step 3: Implementing the Server
- Step 4: Adding the Client Object
- Step 5: Adding the Client Interfaces
- Step 6: Implementing the Client
- Step 7: Using the Client Control
Note This tutorial creates similar source code as the source code for the DispSink sample. You can download the DispSink source code from the DispSink sample abstract. If you prefer to read the tutorial without creating your project, you can refer to the DispSink source code. You can also compare your code to the DispSink code if you run into any build errors during the tutorial.
See Also
Attributed Programming | ATL Article Overview | ATL Class Overview | ATL Samples | Attributes Samples