Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

This tutorial is for people who are just....and I mean just starting to know COM. I have not gone into details of what COM is and how COM works because you will find plenty of such stuff all around the web. Instead what I have done here is to give you some simple walk through steps to be followed to create a very basic COM server and client application . The article is there because when I started with COM nothing so simple was there to get me started.

So, Guys follow me and step into COM. If you need my assistance or think that the article may better be written in your way rather than mine, just email me.


  1. Create a new project select ATL COM APPWIZARD, Select a appropraite name for the server i.e TESTSERVER.
  2. In ATL COM APPWIZARD select Executable(EXE) option as this is going to be an executable server.
  3. When the skeleton application is created, select Insert->New ATL object. The ATL Object Wizard will appear.
  4. Select Simple Object and press Next. The ATL Object Wizard Properties dialog will appear.
  5. Type in the short name for the object in the short name edit box like DosCom. Click Ok. CDosCom class is created for your simple ATL Object with an interface IDosCom.
  6. You can add methods to the IDosCom by right clicking on the IDosCom interface in the project window and selecting the Add Method option. The Add method to Interface dialog will appear.
  7. Type in the name of of the method as RunCmd and click Ok.
  8. Type in the following line into the method RunCmd():
    STDMETHODIMP CDosCom::RunCmd()
     system("dir | more");
     return S_OK;
  9. Compile the project and your simple server is ready.


  1. Create a new project select Win32 Console Application , Select a appropraite name for the client i.e TESTCLIENT.
  2. Inert the following files from the TESTSERVER directory into the TESTCLIENT project by selecting the Project->Add to Project->Files option from the main menu. The Insert files into project dialog box will appear where you need to select the following files from the TESTSERVER directory and click the OK button.
    • TestServer.h
    • TestServer_i.c
  3. Create a new .cpp file and insert it into the client project.
  4. Type in the following code into the file:
    #include <iostream.h>
    #include <conio.h>
    #include <stdio.h>
    #include <windows.h>
    #include "TestServer.h"
    int main(int argc, char** argv)
     char ch;
     cout<< "\n*** This is the test client ***\n" ;
     // interface pointers
     LPUNKNOWN	pUnk;
     IDosCom		*pDosCom;
     //IDemo2		*pDemo2;
     // com call results
     HRESULT		hr;
     // Initialise COM
     hr = CoInitialize(NULL);
     // create an instance and get IUnknown pointer
     hr = 
     (VOID FAR **) &pUnk);
     if (FAILED(hr))
      cout<<"\nCoCreate instance failed for the Demo Object";
      return -1;
     // query for the IDemo interface
     hr = pUnk->QueryInterface(IID_IDosCom,(LPVOID FAR*) &pDosCom );
     if (FAILED(hr))
      cout<<"\nQueryinterface failed for IDemo Interface";
      return -1;
     // call the interface method
     hr = pDosCom->RunCmd();
     cout<<"\nThe method call returned "<< hr;
     cout<<"\n\n\nPress any key....";
     // release interfaces
     // uninitialize DCOM.
     return 0;
  5. Compile the project and your simple client application is ready.
  6. Test the application by running the client application. The client will invoke the server and calls its methods to show us a directory of files in Dos window.


Download demo project - 18 Kb


  • Very Good

    Posted by poorni on 04/19/2004 10:47am

    I tried for the past two days in Net to find a beginner tutorial for COM and at last i found this one and is really good to start with...........

  • remove use of ch

    Posted by Legacy on 02/25/2004 08:00am

    Originally posted by: panda

    its not required.
    the program is not getting exit when you have cin>>ch, and not using later.

  • Will confuse beginners

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

    Originally posted by: Shil

    I think beginners should not be introduced to ATL, till they understand the concept of COM.

  • unexpected end of file error!!

    Posted by Legacy on 07/04/2003 07:00am

    Originally posted by: Umair

    d:\com\trial2\testserver\testserver_i.c(51) : fatal error C1010: unexpected end of file while looking for precompiled header directive

    I copied the exact code but I received the above error

    how on earth do I handle the above Error?
    Thanx 4 Ur Help

  • Made a great start with COM

    Posted by Legacy on 01/25/2003 08:00am

    Originally posted by: Jurs

    this really helped me understand COM a much better... hoping you can add using MFC dlls as well..

    thank a lot

  • Good!

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

    Originally posted by: ShakeWorld

    This article help begin com programing!
    Thank you!

  • Bravo ma ala care l-ai facut.

    Posted by Legacy on 08/12/2002 07:00am

    Originally posted by: Dan Lazar

    Un tutorial foarte bun.
    M-a ajutat sa inteleg cum e cu cacatul asta de ATL
    (pentru ca ATL asta e cam de cacat dupa parerea mea).
    Foarte bine facut tutorialul.

  • No such file or directory&

    Posted by Legacy on 07/25/2002 07:00am

    Originally posted by: soonsing

    fatal error C1083: Cannot open source file: 'C:\Documents and Settings\Administrator\desktop\TestServer\TestServer_i.c': No such file or directory
    Error executing cl.exe.

    TestClient.exe - 1 error(s), 0 warning(s)

    fatal error C1083: Cannot open source file: 'C:\Documents and Settings\Administrator\desktop\TestServer\TestServer_i.c': No such file or directory
    Error executing cl.exe.

    TestClient.exe - 1 error(s), 1 warning(s)

    c:\documents and settings\administrator\desktop\comtutorial\testserver.cpp(8) : fatal error C1083: Cannot open precompiled header file: 'Debug/TestServer.pch': No such file or directory
    Error executing cl.exe.

  • Good

    Posted by Legacy on 07/24/2002 07:00am

    Originally posted by: cyril

    The code is cool. But I had a little problem because I was in haste.

    In addition, how do I register a com in control panel services

  • Excellent ,but more good examples

    Posted by Legacy on 06/08/2002 07:00am

    Originally posted by: pavan

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

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

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date