Environment: VC6 Win2K/NT/98
This out-of-process server can be called remotely by VC and VBScript clients through network. This 200-line full-featured DCOM project was built with pure Win32 API from scratch. The only function in this server is to double an integer.
For those who are not familiar with DCOM, in this sample, the client will call a function located on a remote machine in an exe file.
Steps to build and test the projects:
- Open MiniDcom.dsw, which contains MiniDcom.idl, Server.cpp, Client.cpp and Client.vbs.
- Build Server.dsp to get Server.exe, which is the DCOM server.
- Build Proxy.dsp to get Proxy.dll, which is the DCOM proxy and stub.
- Build Client.dsp to get Client.exe, which is the VC client.
- Run server.exe to register this component.
- Run “regsvr32 proxy.dll” to register the dll.
- Run client.exe. The client will call a function, which was implemented in server.exe and will be running in the server.exe’s process. Type in the machine name on which the server is located on (in this case, your computer’s name). Type in an integer and see the result. Please don’t close the client for now.
- Run another instance of client.exe and you can see the two clients share the single instance of the server.
- Run client.vbs, you can see that this DCOM server can be called by script language.
- Close all the three clients and the server should also disapear.
- If you want to run the client on a different machine, check the following:
- “Ping server-machine-name” is fine.
- Run dcomcnfg.exe on server machine to add the user account that runs the client.exe.
- Copy proxy.dll to the client machine and register it by regsvr32.exe.
- Since the caller and callee are running in different process even different machines, the call has to cross process boundary. This job is done by proxy.dll, which can be generated automatically from the .idl file.
- To serve VBScript clients, IDispatch has to be implemented. We get it done through Type Library, which can be created automatically from .idl file.
- We register the server and the proxy-stub DLL so that the system can locate them by the CLSID.