Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

COM class and inheritance

harman03harman03 Member Posts: 2
Hi, I am new to COM programming and I am having difficulty creating derived COM classes that uses other COM class as a base class.

I am trying to write class in the C++ end to be used in Visual Basic. I am writing COM ATL class in a DLL and referencing it in VB. I am able to create "regular" COM class use it in the VB end. But when I create a COM class derived from another COM class (in the same DLL), the compiler throws errors, which I have traced to lines 26, 43, and 51 (see code below).

I got around the problem by commenting out those lines, and it would compile fine. The problem is when I start creating the classes. I am able to create the base class, but I am unable to create the derived class.

I have been trying to figure out why I am having a problem and how I can fix it, but I just don't know enough about COM.

e.g.,

This is the base class:

1 class ATL_NO_VTABLE CBaseClass :
2 public CComObjectRootEx,
3 public CComCoClass,
4 public IDispatchImpl
6 {
7 public:
8 CBaseClass()
9 {
10 }
11
12 DECLARE_REGISTRY_RESOURCEID(IDR_BASECLASS)
13
14 DECLARE_PROTECT_FINAL_CONSTRUCT()
15
16 BEGIN_COM_MAP(CBaseClass)
17 COM_INTERFACE_ENTRY(IBaseClass)
18 COM_INTERFACE_ENTRY(IDispatch)
19 END_COM_MAP()
20
21 // IBaseClass
22 public:
23 };


This is the derived class:

24 class ATL_NO_VTABLE CDerivedClass :
25 public CBaseClass,
26 public CComObjectRootEx,
27 public CComCoClass,
28 public IDispatchImpl
30 {
31 public:
32 CDerivedClass()
33 : CBaseClass()
34 {
35 }
36
37 DECLARE_REGISTRY_RESOURCEID(IDR_DERIVEDCLASS)
38
39 DECLARE_PROTECT_FINAL_CONSTRUCT()
40
41 BEGIN_COM_MAP(CDerivedClass)
42 COM_INTERFACE_ENTRY(IDerivedClass)
43 COM_INTERFACE_ENTRY(IDispatch)
44 END_COM_MAP()
45
46 // IDerivedClass
47 public:
48 };

This is code from testcom.cpp (the name of the project/DLL):

49 BEGIN_OBJECT_MAP(ObjectMap)
50 OBJECT_ENTRY(CLSID_BaseClass, CBaseClass)
51 OBJECT_ENTRY(CLSID_DerivedClass, CDerivedClass)
52 END_OBJECT_MAP()

Comments

  • matrixhasyoumatrixhasyou Member Posts: 1
    Did you find the reason I am looking for the same thing?

    Thank you


    Baris


    : Hi, I am new to COM programming and I am having difficulty creating derived COM classes that uses other COM class as a base class.
    :
    : I am trying to write class in the C++ end to be used in Visual Basic. I am writing COM ATL class in a DLL and referencing it in VB. I am able to create "regular" COM class use it in the VB end. But when I create a COM class derived from another COM class (in the same DLL), the compiler throws errors, which I have traced to lines 26, 43, and 51 (see code below).
    :
    : I got around the problem by commenting out those lines, and it would compile fine. The problem is when I start creating the classes. I am able to create the base class, but I am unable to create the derived class.
    :
    : I have been trying to figure out why I am having a problem and how I can fix it, but I just don't know enough about COM.
    :
    : e.g.,
    :
    : This is the base class:
    :
    : 1 class ATL_NO_VTABLE CBaseClass :
    : 2 public CComObjectRootEx,
    : 3 public CComCoClass,
    : 4 public IDispatchImpl
    : 6 {
    : 7 public:
    : 8 CBaseClass()
    : 9 {
    : 10 }
    : 11
    : 12 DECLARE_REGISTRY_RESOURCEID(IDR_BASECLASS)
    : 13
    : 14 DECLARE_PROTECT_FINAL_CONSTRUCT()
    : 15
    : 16 BEGIN_COM_MAP(CBaseClass)
    : 17 COM_INTERFACE_ENTRY(IBaseClass)
    : 18 COM_INTERFACE_ENTRY(IDispatch)
    : 19 END_COM_MAP()
    : 20
    : 21 // IBaseClass
    : 22 public:
    : 23 };
    :
    :
    : This is the derived class:
    :
    : 24 class ATL_NO_VTABLE CDerivedClass :
    : 25 public CBaseClass,
    : 26 public CComObjectRootEx,
    : 27 public CComCoClass,
    : 28 public IDispatchImpl
    : 30 {
    : 31 public:
    : 32 CDerivedClass()
    : 33 : CBaseClass()
    : 34 {
    : 35 }
    : 36
    : 37 DECLARE_REGISTRY_RESOURCEID(IDR_DERIVEDCLASS)
    : 38
    : 39 DECLARE_PROTECT_FINAL_CONSTRUCT()
    : 40
    : 41 BEGIN_COM_MAP(CDerivedClass)
    : 42 COM_INTERFACE_ENTRY(IDerivedClass)
    : 43 COM_INTERFACE_ENTRY(IDispatch)
    : 44 END_COM_MAP()
    : 45
    : 46 // IDerivedClass
    : 47 public:
    : 48 };
    :
    : This is code from testcom.cpp (the name of the project/DLL):
    :
    : 49 BEGIN_OBJECT_MAP(ObjectMap)
    : 50 OBJECT_ENTRY(CLSID_BaseClass, CBaseClass)
    : 51 OBJECT_ENTRY(CLSID_DerivedClass, CDerivedClass)
    : 52 END_OBJECT_MAP()
    :
    :

Sign In or Register to comment.