ACDUAL Sample: Adds Dual Interfaces to an Automation Application

ACDual demonstrates how to add dual-interface support to an MFC-based Automation (formerly OLE Automation) application. The solution consists of the following projects:

  • ACDualDriv, containing a version of the automation client AUTODRIV project that lets you select whether to control the server application using the dispatch interface or using vtable binding.

  • ACDual, containing an actual version of the automation server AUTOCLIK project with dual-interface support.

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.

Building the Sample

To build the ACDual sample

  1. Open the solution acdual.sln, located in the acdual directory.

  2. On the Build menu, click Build.

  3. Run ACDual once as a stand-alone application so it can register itself with the system.

Running the Sample

After registering the ACDual application, you are ready to run the ACDualDriv application. Building the solution from the IDE will perform the ACDualDriv registration automatically before ACDualDriv is run. ACDualDriv launches the ACDual application and creates a Document object, which you can then manipulate using Automation via the ACDualDriv user interface. It also contains an additional check box that lets you select whether to use VTBL binding to communicate with the ACDual Document object.

The ACDual server uses AUTOCLIK as a starting point. New globally unique identifiers (GUID) were generated to prevent confusion with the original AUTOCLIK sample, and some resources strings were changed to clarify whether the ACDual server is running. All other changes to the sources are marked with comment blocks like this:

      // DUAL_SUPPORT_START
      ... modified code goes here
      // DUAL_SUPPORT_END

For more information about dual interfaces, object description language (ODL) scripts, and Automation error interfaces, see Technical Note 65.

Dual Interfaces

A dual interface allows you to implement an IDispatch interface or a VTBL interface. A dual interface is strongly recommended for all exposed Automation objects. Issues to consider when implementing a dual interface are discussed in Technical Note 65 and include:

  • Implementing dual-interface support for CCmdTarget-based classes

  • Passing dual-interface pointers

  • Enabling typesafe binding, including:

    • Registering the application's library type

    • Modifying project build settings to accommodate type library changes

    • Specifying the correct object class name in a type library

  • Handling exceptions and the automation error interface

For more information, see the ActiveX topics Overview of Automation, Dual Interfaces, Automation Type Description Interfaces, and the ODL reference entry on the dual attribute.

Note

Some samples, such as this one, have not been modified to reflect the changes in the Visual C++ wizards, libraries, and compiler, but still demonstrate how to complete your desired task.

Keywords

The ACDual sample demonstrates the following keywords:

AfxMessageBox; AfxOleInit; AfxOleLockApp; AfxOleUnlockApp; CCmdTarget::EnableAutomation; CCmdTarget::FromIDispatch; CCmdTarget::GetIDispatch; CCmdTarget::OnFinalRelease; CControlBar::EnableDocking; CControlBar::GetBarStyle; CControlBar::SetBarStyle; CDialog::DoModal; CDocument::GetFirstViewPosition; CDocument::GetNextView; CDocument::OnNewDocument; CDocument::SetModifiedFlag; CDocument::UpdateAllViews; CFrameWnd::ActivateFrame; CFrameWnd::DockControlBar; CFrameWnd::EnableDocking; CFrameWnd::LoadFrame; CObject::AssertValid; CObject::Dump; CObject::IsKindOf; CObject::Serialize; COleTemplateServer::ConnectTemplate; COleTemplateServer::UpdateRegistry; CStatusBar::Create; CStatusBar::SetIndicators; CToolBar::Create; CView::DoPreparePrinting; CView::GetDocument; CView::OnBeginPrinting; CView::OnDraw; CView::OnEndPrinting; CView::OnPreparePrinting; CWinApp::AddDocTemplate; CWinApp::EnableShellOpen; CWinApp::InitInstance; CWinApp::LoadStdProfileSettings; CWinApp::RegisterShellFileTypes; CWnd::DoDataExchange; CWnd::GetParentFrame; CWnd::OnCreate; CWnd::OnLButtonDown; CWnd::PreCreateWindow; CWnd::ShowWindow; CWnd::UpdateWindow; DragAcceptFiles; ShowWindow; TextOut

The ACDualDriv demonstrates the following keywords:

AfxGetApp; AfxMessageBox; AfxOleInit; CDC::DrawIcon; CDC::GetSafeHdc; CDialog::DoModal; CDialog::EndDialog; COleDispatchDriver::AttachDispatch; COleDispatchDriver::GetProperty; COleDispatchDriver::InvokeHelper; COleDispatchDriver::SetProperty; CRect::Height; CRect::Width; CWinApp::InitInstance; CWinApp::LoadStdProfileSettings; CWnd::DoDataExchange; CWnd::GetClientRect; CWnd::IsIconic; CWnd::OnClose; CWnd::OnCreate; CWnd::OnPaint; CWnd::OnQueryDragIcon; CWnd::SendMessage; CWnd::ShowWindow; CWnd::UpdateData; GetSystemMetrics; LoadIcon; ShowWindow

See Also

Other Resources

MFC Samples