DCOM: Demonstrates Remotely Calling a COM Object

Click to open or copy the DCOM project files.

This sample demonstrates how to call a COM object implemented in a Windows NT service from multiple clients running on different machines. It is composed of three parts:

Running the Sample

For this sample to work, all machines must be running Windows NT 4.0 or later.

  1. Build the DrawServ, ATLDraw, and DrawCtl samples.

  2. Copy the DrawServ.exe and ATLDraw.exe or DrawCtl.dll to each machine on which you want to run the sample. Register the server on each machine 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.

  3. Start the service on the server by using the Services icon in Control Panel.

  4. Using DCOMCNFG on each client, 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.

  5. 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, you would change a line containing the following:

InprocServer32 = s %MODULE%

to the following:

InprocServer32 = s '%MODULE%'

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(nFlags, point);; CView::PreCreateWindow; CWinApp::AddDocTemplate; CWinApp::Enable3dControls; CWinApp::Enable3dControlsStatic; 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