Minimized Sample of DCOM Server
Posted
by Walter Wang
on September 20th, 2001
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.
Architecture:
- 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.
Downloads
Download demo project - 50 KbDownload source - 8 Kb

Comments
Oz_Dingo
Posted by Oz_Dingo on 12/29/2004 06:08pmHow can I introduce MFC classes in this project ? Is it possible ? Can you tell me how ?
ReplyHow can i automatically create the proxy dll?
Posted by T.Ephraim on 12/07/2004 06:09amDoes anyone knows it? Or do i not really need the proxy.dll ... but how else can i connect from a remote machine to the server. Ciao Ephraim
ReplyHow to use this program by Com+?
Posted by Legacy on 02/05/2004 12:00amOriginally posted by: WenZhong He
I want to use the client and server application in different machines. I don't know how I use this program by Com+, if so, do I need register the proxy.dll in the client machine? and how do I set in the Component Service?
By the way, if I make a server application(DLL)myself by ATL
and check the Check box for Allow Merging of Proxy/Stub on the application setting page of ATL, do I need a single proxy.dll in the client machine?
I use Windows 2000 in the client and server computer.
Help me!
Thank you in advance.
ReplyDCOM connection
Posted by Legacy on 12/02/2003 12:00amOriginally posted by: seb.t
I have some problem with DCOM connection. When, the server PC is OFF for example, my thread is blocked when it try to connect during several minutes.... what could i do?
ReplyADD another method
Posted by Legacy on 08/21/2003 12:00amOriginally posted by: joseph
ReplyTo run Server & Client in different machine, make sure:
Posted by Legacy on 07/31/2003 12:00amOriginally posted by: bingle
author said:"
11. 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.
"
following the step, someone said:"When run client on different machine with server, client says 'CoCreateInstanceEx failed.' why?", me too at 1st.
the reason is we should not just "add the user account that runs the client.exe" using dcomcnfg.exe on the Server, we should check the following too:
If you logged in using a domain account and both machine Client and machine Server belong to that domain, then you can be authenticated on both machines. However, if you logged onto machine Client using a local account, then machine Server must have an identical local account (same user name and password), otherwise the activation request will fail.
see here: http://www.codeguru.com/activex/COMSecurity1.html
Replyi think that this program is good.. but...
Posted by Legacy on 05/31/2003 12:00amOriginally posted by: peios
i think that this program is good .
so i will use this my project works.
one computer is window2000 (client),other is window2000
(server)
but. i am worry about the bug ,i don't know anythings
Can you tell me a bug....???
ReplyServer & Client.exe's HELP!
Posted by Legacy on 05/01/2003 12:00amOriginally posted by: BulletProof
Hi all I am BulletProof. I wanted to know how can I make Server.exe in programming? Can you visually program one as in sample same with Client.exe? it would be helpful.
ReplyIt works fine! Even the .vbs.
Posted by Legacy on 06/21/2002 12:00amOriginally posted by: dungo
It works fine! Even the .vbs.
ReplyQueryinterface failed?
Posted by Legacy on 04/16/2002 12:00amOriginally posted by: Pathi
Hi
I changed CLSCTX_REMOTE_SERVER to CLSCTX_SERVER but getting the error as
"Queryinterface failed". I am using Win NT4.0.
Why tis prblem is coming?What settings are needed to run this remotely?
Please help me/
Thank you
Pathi
ReplyLoading, Please Wait ...