Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
0 out of 1 rated this helpful - Rate this topic

ATLDuck Sample: Uses Connection Points with ATL

The ATLDuck sample consists of four projects: atlduck, duck and their respective proxy/stub projects atlduckPS and duckPS. The duck project creates an instance of an object that implements the IDuckInt interface. This interface includes four member functions: Flap, Paddle, Quack, and Walk.

The second project, atlduck, has a connection point for the IDuckInt interface (that is, it knows how to use the interface but does not implement it). Only a single instance of this object will be created. Once the connection is established between the two applications, atlduck will call the functions in the IDuckInt interface for sinks that have called IConnectionPoint::Advise.

This sample also makes use of the marshaling code (through atlduckPS and duckPS) needed to connect interfaces in different processes.

The ATLDuck 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 this sample

  1. Open the atlduck.sln solution file.

  2. From the Build menu, click Build Solution. This will build all four projects and do the necessary registration. The following files will be created:

    • atlduck.exe, an EXE server

    • atlduckPS.dll, a marshalling DLL for the atlduck.exe server

    • duck.exe, an EXE client

    • duckPS.dll, a marshalling DLL for the duck.exe client

To run this sample

  1. Start one or more instances of duck.exe.

    NoteNote:

    Opening several instances of duck.exe demonstrates connection points most effectively.

  2. A dialog box appears. In the dialog box, click the button Create DoDuck Object. When you click this button, the application creates an instance of an object with class ID CLSID_DuckDoer, running atlduck.

  3. A new dialog box, issued by atlduck.exe, appears. This dialog box shows a button for each function in the IDuckInt interface, as well as a list box with the connections to active sinks, and their cookies. From the duck dialog boxes, you can either Advise or Unadvise the connection point. Depending on your choice, you will receive or not receive notifications from the sources. The notification, when you receive it, will show in the status edit field. Additionally, ATLDuck demonstrates the value of the cookie supplied by the connection point when the connection is advised.

The sample uses the following classes:

CDialog (MFC), CComObject (ATL), IConnectionPointImpl<CDuckDoer> (ATL)

This sample uses the following keywords:

_ASSERTE; _tcslen; _VERIFY; AddRef; Advise; BEGIN_COM_MAP; BEGIN_CONNECTION_POINT_MAP; BEGIN_MSG_MAP; BEGIN_OBJECT_MAP; CComCoClass; CComModule::Unlock; CComObjectRootEx; CDialogImpl; CenterWindow; CoInitialize; COM_INTERFACE_ENTRY; COM_INTERFACE_ENTRY_IMPL; COMMAND_HANDLER; COMMAND_ID_HANDLER; CONNECTION_POINT_ENTRY; CoSuspendClassObjects; CoUninitialize; Create; DECLARE_CLASSFACTORY_SINGLETON; DECLARE_NOT_AGGREGATABLE; DECLARE_REGISTRY_RESOURCEID; DestroyWindow; DispatchMessage; EnableWindow; END_COM_MAP; END_CONNECTION_POINT_MAP; END_MSG_MAP; END_OBJECT_MAP; ExitProcess; FindConnectionPoint; GetCommandLine; GetDC; GetDlgItem; GetMessage; GetTextExtentPoint32; IConnectionPointContainerImpl; IConnectionPointImpl; Init; IsWindowVisible; MESSAGE_HANDLER; MessageBox; OBJECT_ENTRY; OleInitializeCoCreateInstance; OnCancel; OnFlap; OnInitDialog; OnOK; OnPaddle; OnWalk; OnQuack; PostThreadMessage; QueryInterface; RecalcListboxExtent; RegisterClassObjects; RegisterServer; reinterpret_cast; ReleaseDC; RevokeClassObjects; SendMessage; SetOwner; SetWindowText; ShowStatus; ShowWindow; Unadvise; UnregisterServer; UNUSED_ALWAYS; UpdateRegistryFromResource; UpdateWindow; USES_CONVERSION

Other Resources

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft. All rights reserved.