DCOM Sample: Demonstrates Remotely Calling a COM Object
The DCOM sample demonstrates how to call a COM object implemented in a Windows service from multiple clients running on different machines. It is composed of three parts:
DrawServ — The Windows service that implements the COM object.
ATLDraw — The client that connects to the DrawServ COM object.
DrawCtl — A control version of ATLDraw.
Security Note |
---|
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.
Building and Running the Sample
For this sample to work, all computers must be running Windows 2000 or later.
To build and run the sample
Open the solution DCOM.sln.
From the Build menu, click Build Solution.
Copy DrawServ.exe and ATLDraw.exe or DrawCtl.dll to each computer on which you want to run the sample. Register the server on each computer by running DrawServ with the command-line argument /RegServer or -RegServer (this is case-insensitive). For example:
C:\ATL> DrawServ /RegServer
(ATL.DLL must be registered for this to work.) You must copy the server to each client to register the CLSID for the server and the server type library on each client.
Start the service on the server by using the Services icon in Control Panel.
Using the DCOMCNFG utility on each client (run it from a command line), select the Properties of the DrawServ Class. From the Location tab, select Run application on the following computer. Enter the name of the computer on which you are running the server object.
Run ATLDraw and select Server Connect from the menu on each client. Draw on the client window by holding the left mouse button down and dragging a line. The drawn line should appear on each client that is connected to the same server. You can also use the View/Color menu option to change the color for each client.
The DrawServ sample will not register correctly when its path contains spaces. One solution to this problem is to edit the corresponding .rgs file and add single quotes around all occurrences of %MODULE%. For example, change a line containing the following:
InprocServer32 = s %MODULE%
to the following:
InprocServer32 = s '%MODULE%'
Keywords
This sample uses the following keywords:
AfxMessageBox; ASSERT_VALID; ATLASSERT; AtlUnadvise; BEGIN_COM_MAP; BEGIN_CONNECTION_POINT_MAP; BEGIN_INTERFACE_MAP; BEGIN_MSG_MAP; BEGIN_OBJECT_MAP; CComCoClass; CComControl; CComModule::GetClassObject; CComModule::GetLockCount; CComModule::Init; CComModule::RegisterServer; CComModule::Term; CComModule::Unlock; CComModule::UnregisterServer; CComModule::UpdateRegistryFromResource; CComObjectRoot; CDocument::OnNewDocument; CFrameWnd::AssertValid; CFrameWnd::DockControlBar; CFrameWnd::Dump; CFrameWnd::EnableDocking; CFrameWnd::OnCreate; CFrameWnd::PreCreateWindow; CloseServiceHandle; CoCreateInstance; CoCreateInstanceEx; CoInitialize; CoInitializeSecurity; COM_INTERFACE_ENTRY; COM_INTERFACE_ENTRY_IMPL; COM_INTERFACE_ENTRY_IMPL_IID; COM_INTERFACE_ENTRY2; CONNECTION_POINT_ENTRY; ConnectSink; ControlService; CoUninitialize; CProxyIDrawServ; CreatePen; CreateService; CStatusBar::SetIndicators; CToolBar::EnableDocking; CToolBar::LoadToolBar; CView::DoPreparePrinting; CView::OnLButtonUp; CView::PreCreateWindow; CWinApp::AddDocTemplate; CWinApp::LoadStdProfileSettings; CWinApp::ParseCommandLine; CWinApp::ProcessShellCommand; CWindow::SetCapture; DECLARE_GET_CONTROLLING_UNKNOWN; DECLARE_REGISTRY_RESOURCEID; DeleteObject; DeregisterEventSource; DisableThreadLibraryCalls; Disconnect; DisconnectSink; END_COM_MAP; END_CONNECTION_POINT_MAP; END_INTERFACE_MAP; END_OBJECT_MAP; GetModuleFileName; IConnectionPointContainerImpl; IDataObjectImpl; IDispatchImpl; IMPLEMENT_DYNCREATE; Install; INTERFACE_PART; IObjectSafetyImpl; IOleControlImpl; IOleInPlaceActiveObjectImpl; IOleInPlaceObjectWindowlessImpl; IOleObjectImpl; IPersistStorageImpl; IPersistStreamInitImpl; IProvideClassInfo2Impl; IQuickActivateImpl; ISupportErrorInfo; IViewObjectExImpl; IViewObjectExImpl::Draw; LineTo; LoadString; LogEvent; MESSAGE_HANDLER; MessageBox; MoveToEx; OBJECT_ENTRY; OffsetRect; OpenSCManager; OpenService; PostThreadMessage; PtInRect; QueryInterface; RegisterEventSource; ReleaseDC; ReportEvent; SelectObject; SetCapture; SetServiceStatus; SetWindowOrgEx; StartServiceCtrlDispatcher; Uninstall