DispSink Sample: Handles Events Fired from a Singleton COM Server Through a Dispatch Interface
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

DispSink Sample: Handles Events Fired from a Singleton COM Server Through a Dispatch Interface

The DispSink sample demonstrates 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 DispSink attributes sample is the attributed version of this sample.

Security noteSecurity Note:

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

To get samples and instructions for installing them:

  • On the Visual Studio Help menu, click Samples.

    For more information, see Visual Studio Samples.

  • The most recent version and complete list of samples is available online from the Visual Studio 2008 Samples page.

  • You can also locate samples on your computer's hard disk. By default, samples and a Readme file are copied into a folder under \Program Files\Visual Studio 9.0\Samples\. For Express editions of Visual Studio, all samples are located online.

To build and run this sample

  1. Open the solution file DispSink.sln.

  2. From the Build menu, click Build Solution.

  3. Open two or more instances of the ActiveX Control Test Container and insert the client control, DispCtl, into each instance. See Testing Properties and Events with Test Container for information on how to access the test container.

  4. Invoke the Connectmethod on all of the controls.

  5. Invoke the Send method on one of the controls. Change the Parameter Type field of the Invoke Methods dialog box to VT_BSTR and then type any string into the Parameter Value box. Click the Invoke button. The string will be displayed in the center of all connected controls.

  6. Invoke the Disconnect method on all controls prior to deleting them.

The server is a singleton object that has its own dual interface as well as a dispatch interface used for firing off events. The server object receives data through its dual interface Send method and transmits it to all connected components through the Transfer event on its dispatch interface.

The client is an ActiveX control that contains a server object. The control responds to the Transfer event fired by the server object. It has a dual interface that has Connect, Send, and Disconnect methods. If the Transfer event is fired with a variant containing a BSTR, the string is displayed in the center of the control.

This sample uses the following keywords:

#import; CComAutoThreadModule; CComSimpleThreadAllocator; CoCreateInstance; DECLARE_CLASSFACTORY_AUTO_THREAD; FireViewChange

Other Resources

© 2015 Microsoft