DCOM: Call COM Object in Windows NT Service from Multiple Clients
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 several parts:
- DrawServ The Windows NT service that implements the COM object.
- ATLDraw The client that connects to the DrawServ COM object.
- DrawCtl A control version of ATLDraw. It has a Connect method (that takes a machine name string parameter), a Disconnect method, and a Clear method.
- MFCCont An MFC container for DrawCtl. Enter the name of the (possibly remote) server without quotes or slashes.
- ATLCont An ATL container for DrawCtl. Enter the name of the (possibly remote) server without quotes or slashes.
All machines must be running Windows NT 4.0 Beta 2 or later for this sample to work.
To build and run the sample
- Build the DrawServ and ATLDraw samples.
- Copy Drawserv.exe and Atldraw.exe to each machine that you want to run the sample from. Register the server on each machine by running DrawServ with the command-line argument /RegServer or -RegServer (case-insensitive). For example:
DrawServ /RegServer
(Register.dll must be registered for this to work.) The reason you need to copy the server to each client is that the CLSID for the server and the server type library need to be registered on the client.
- Start the service on the server by using the Services icon in Control Panel.
- Using DCOMCNFG on each client, select the Properties of the DrawServ Class. From the Location tab, select Run application on the following computer, then enter the name of the computer that you are running the server object on. Clear the Run application on this computer check box.
- 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 also connected to the same server. You can also use the Color command from the View menu to change the color for each client.
- If there is any problem connecting to a remote server (for example, if Tstcon32.exe does not call CoInitializeSecurity), run DCOMCNFG on the client and open the tab Default Properties. Set Default Authentication Level to None and Default Impersonation Level to Anonymous.