Minimized Sample of DCOM Server

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:

  1. Open MiniDcom.dsw, which contains MiniDcom.idl, Server.cpp, Client.cpp and Client.vbs.
  2. Build Server.dsp to get Server.exe, which is the DCOM server.
  3. Build Proxy.dsp to get Proxy.dll, which is the DCOM proxy and stub.
  4. Build Client.dsp to get Client.exe, which is the VC client.
  5. Run server.exe to register this component.
  6. Run "regsvr32 proxy.dll" to register the dll.
  7. 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.
  8. Run another instance of client.exe and you can see the two clients share the single instance of the server.
  9. Run client.vbs, you can see that this DCOM server can be called by script language.
  10. Close all the three clients and the server should also disapear.
  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.

Architecture:

  1. 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.
  2. To serve VBScript clients, IDispatch has to be implemented. We get it done through Type Library, which can be created automatically from .idl file.
  3. We register the server and the proxy-stub DLL so that the system can locate them by the CLSID.

Downloads

Download demo project - 50 Kb
Download source - 8 Kb


Comments

  • Oz_Dingo

    Posted by Oz_Dingo on 12/29/2004 06:08pm

    How can I introduce MFC classes in this project ? Is it possible ? Can you tell me how ?

    Reply
  • How can i automatically create the proxy dll?

    Posted by T.Ephraim on 12/07/2004 06:09am

    Does 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

    Reply
  • How to use this program by Com+?

    Posted by Legacy on 02/05/2004 12:00am

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


    Reply
  • DCOM connection

    Posted by Legacy on 12/02/2003 12:00am

    Originally 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?

    Reply
  • ADD another method

    Posted by Legacy on 08/21/2003 12:00am

    Originally posted by: joseph

    Hi,
    
    I Add another method to server.exe.
    The interface like below.
    [id(2), helpstring("method Hello")] HRESULT SayHello(BSTR buf, [out, retval] int* retval);

    In client.exe
    How to Transfer char* to BSTR in order to call the method, SayHello(BSTR buf, int* retval);

    Reply
  • To run Server & Client in different machine, make sure:

    Posted by Legacy on 07/31/2003 12:00am

    Originally 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

    Reply
  • i think that this program is good.. but...

    Posted by Legacy on 05/31/2003 12:00am

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

    Reply
  • Server & Client.exe's HELP!

    Posted by Legacy on 05/01/2003 12:00am

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

    Reply
  • It works fine! Even the .vbs.

    Posted by Legacy on 06/21/2002 12:00am

    Originally posted by: dungo

    It works fine! Even the .vbs.

    Reply
  • Queryinterface failed?

    Posted by Legacy on 04/16/2002 12:00am

    Originally 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

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Packaged application development teams frequently operate with limited testing environments due to time and labor constraints. By virtualizing the entire application stack, packaged application development teams can deliver business results faster, at higher quality, and with lower risk.

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds