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.
This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.
To get samples and instructions for installing them:
To access samples from Visual Studio
On the Help menu, click Samples.
By default, these samples are installed in drive:\Program Files\Microsoft Visual Studio 10.0\Samples\.
For the most recent version of this sample and a list of other samples, see Visual Studio Samples on the MSDN Web site.
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.
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
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.
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