CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: COM tutorial

  1. #1
    Join Date
    May 2015
    Posts
    500

    COM tutorial

    Hello All,
    I was trying to implement the following COM tutorial using the visual studio 2022.
    https://www.codeguru.com/soap/step-b...utorial/#Intro

    But getting some issues.
    Also the
    Download source – 114 Kb
    Download demo project – 101 Kb
    buttons arent working

    Could some experts, please refine the steps as per visual studio 2022. I just want to implement the bare minimal, for my own understanding.

    Thanks a lot
    pdk
    Last edited by pdk5; February 17th, 2023 at 06:17 AM.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: COM tutorial

    Did you try to download source or/and demo project?
    I cannot download either of them. I only get the
    404 Not Found error code.
    Victor Nijegorodov

  3. #3
    Join Date
    May 2015
    Posts
    500

    Re: COM tutorial

    Thankyou very much Victor for looking into this.

    Yes, even i couldnot download them, as i mentioned in my post. So I tried to cut paste the code to my VS and compiled. I could use the MIDL, and could generate the files from the IDL, but it is complaining later

  4. #4
    Join Date
    May 2015
    Posts
    500

    Re: COM tutorial

    I found one issue and fixed it:
    In the AddObj.cpp, the static_cast target type was missing and I added the following and made that file compile.
    Code:
    HRESULT __stdcall CAddObj::QueryInterface(
        REFIID riid,
        void** ppObj)
    {
       
        if (riid == IID_IUnknown)
        {
            delete this;
    
            *ppObj = static_cast<IUnknown *>(this);
            AddRef();
            return S_OK;
        }
    
        if (riid == IID_IAdd)
        {
            *ppObj = static_cast<IAdd *>(this);
            AddRef();
            return S_OK;
        }
    
        //
        //if control reaches here then , let the client know that
        //we do not satisfy the required interface
        //
    
        *ppObj = NULL;
        return E_NOINTERFACE;
    }//QueryInterface method
    But now it is complaining in the "AddObjFactory.cpp", looks like I need to add the The AddRef, Release and QueryInterface methods like to that of class CAddObj , as per the tutorial. I added these functions:

    Code:
    HRESULT __stdcall CAddFactory::QueryInterface(
        REFIID riid,
        void** ppObj)
    {
    
        if (riid == IID_IUnknown)
        {
            delete this;
    
            *ppObj = static_cast<IUnknown*>(this);
            AddRef();
            return S_OK;
        }
    
        if (riid == IID_IAdd)
        {
            *ppObj = static_cast<IAdd*>(this);
            AddRef();
            return S_OK;
        }
    
        //
        //if control reaches here then , let the client know that
        //we do not satisfy the required interface
        //
    
        *ppObj = NULL;
        return E_NOINTERFACE;
    }//QueryInterface method
    
    
    
    ULONG   __stdcall CAddFactory::AddRef()
    {
        return InterlockedIncrement(&m_nRefCount);
    }
    
    
    
    ULONG   __stdcall CAddFactory::Release()
    {
        long nRefCount = 0;
        nRefCount = InterlockedDecrement(&m_nRefCount);
        if (nRefCount == 0) delete this;
        return nRefCount;
    }
    Not sure if its correct. If somebody makes the link with the project downloads working i can crosscheck my implementation

  5. #5
    Join Date
    May 2015
    Posts
    500

    Re: COM tutorial

    Currently Im getting compile error, CLSID_AddObject not defined in the Exports.cpp file. :::

    I guess I know this answer, as I need to register the COM object.

    As per the instructions, the registering should happen when the project is run.

    It will be very helpful, if the owners of that document in this forum, please correct the link
    Last edited by pdk5; February 18th, 2023 at 09:23 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured