Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. ATL Objects

ATL Objects

Scheduled Pinned Locked Moved C / C++ / MFC
c++comquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bret Faller
    wrote on last edited by
    #1

    Hello, Is it possible to derive one ATL COM Object from another? I've been trying to do so but VC++ doesn't want to let me or when it does CoCreateInstance tells me class not available. Anyone know of any good leads, articles about this. Thanks in advance. Bret Faller Odyssey Computing, Inc.

    A 1 Reply Last reply
    0
    • B Bret Faller

      Hello, Is it possible to derive one ATL COM Object from another? I've been trying to do so but VC++ doesn't want to let me or when it does CoCreateInstance tells me class not available. Anyone know of any good leads, articles about this. Thanks in advance. Bret Faller Odyssey Computing, Inc.

      A Offline
      A Offline
      Aaron Schaefer
      wrote on last edited by
      #2

      Yes!! Well, sort of. You can't derive anything from the actual coclass, but you can achieve nearly the same effect. Separate all of the implementation code into a separate class, templated on the type of the implemented interface, and derive the coclass from that. Since the implementation classes are not COM coclasses, they can be extended like normal C++ classes, and you can arrange these in a heirarchy to suit your needs. The idea is to put absolutely no source code in the COM coclass, it should inherit ALL of its functionality from the impl classes. This might look something like this: // In your idl file: interace IA : IDispatch { HRESULT Method1([out,retval] double* pVal); } interface IB : IA { HRESULT Method2([out,retval] double* pVal); } // The definition of your coclass for A: class ATL_NO_VTABLE CA : public CComObjectRootEx, public CComCoClass, public IDispatchImpl, &IID_IA, &LIBID_ABCDLib> { // etc. } // The definition of the coclass for B: class ATL_NO_VTABLE CB : public CComObjectRootEx, public CComCoClass, public IDispatchImpl, &IID_IB, &LIBID_ABCDLib> { // etc. } // The definition of the implementation class for A: template class IAImpl : public Base { public: IAImpl(); ~IAImpl(); // Methods of IA STDMETHOD(Method1)(/*[out, retval]*/ double* pVal); }; // Implement the methods and stuff here . . . // The definition of the implementation for B: // B inherits stuff from A template class IBImpl : public IAImpl { public: IBImpl(); ~IBImpl(); // Methods of IB STDMETHOD(Method2)(/*[out, retval]*/ double* pVal); }; // Implement methods of B here Anyway, one implementation can inherit stuff from another, and implementations of generic stuff can be put into base classes, etc., etc. Someone else may be able to suggest other methods; this one has worked well for me. Good Luck!

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups