This documentation is archived and is not being maintained.

DCOM Sample: Demonstrates Remotely Calling a COM Object

Visual Studio 2008

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 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.

For this sample to work, all computers must be running Windows 2000 or later.

To build and run the sample

  1. Open the solution DCOM.sln.

  2. From the Build menu, click Build Solution.

  3. 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.

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

  5. 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.

  6. 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%'

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

Other Resources