How to access a member variable of a class from other class 
Author Message
 How to access a member variable of a class from other class

Hi all...

To state simply the problem. I have an ATL object that has 2 interfaces,
each one has the corresponding class, for example,

CObject_1
IObject_1
CObject_2
IObject_2

CObject_1 need to access a public member variable in CObject_2, how can I do
it? I tried declaring in CObject_1 an object of type CObject_2 but it didn't
compile because of the definition of the CObject_2 class... for instance:

class ATL_NO_VTABLE CObject_2 :
 public CComObjectRootEx<CComSingleThreadModel>,
 public CComCoClass<CObject_2, &CLSID_Object_2>,
 public IDispatchImpl<IObject_2, &IID_IObject_2, &LIBID_ICFILELib>
{

DECLARE_NO_REGISTRY()
DECLARE_NOT_AGGREGATABLE(CObject_2)
DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CObject_2)
 COM_INTERFACE_ENTRY(IObject_2)
 COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()

Quote:
};

CObject_1 has the same skeleton

Any one can help?
Thanks a los in advance

Jaime



Thu, 19 Aug 2004 08:58:18 GMT  
 How to access a member variable of a class from other class
Use an interface property to expose your member variable. With COM, every
single piece of communication is done via interfaces. There is no other
communication mechanism.

--
Frederic Claux



Quote:
> Hi all...

> To state simply the problem. I have an ATL object that has 2 interfaces,
> each one has the corresponding class, for example,

> CObject_1
> IObject_1
> CObject_2
> IObject_2

> CObject_1 need to access a public member variable in CObject_2, how can I
do
> it? I tried declaring in CObject_1 an object of type CObject_2 but it
didn't
> compile because of the definition of the CObject_2 class... for instance:

> class ATL_NO_VTABLE CObject_2 :
>  public CComObjectRootEx<CComSingleThreadModel>,
>  public CComCoClass<CObject_2, &CLSID_Object_2>,
>  public IDispatchImpl<IObject_2, &IID_IObject_2, &LIBID_ICFILELib>
> {

> DECLARE_NO_REGISTRY()
> DECLARE_NOT_AGGREGATABLE(CObject_2)
> DECLARE_PROTECT_FINAL_CONSTRUCT()

> BEGIN_COM_MAP(CObject_2)
>  COM_INTERFACE_ENTRY(IObject_2)
>  COM_INTERFACE_ENTRY(IDispatch)
> END_COM_MAP()
> };

> CObject_1 has the same skeleton

> Any one can help?
> Thanks a los in advance

> Jaime



Fri, 20 Aug 2004 16:37:34 GMT  
 How to access a member variable of a class from other class
You need to declare your CObject_2 like this:
CComObject<CObject_2> *pObject2;

Then create it in CObject_1::FinalConstruct like this:
CComObject<CObject_2>::CreateInstance(&pObject2);
pObject2->AddRef();

Don't forget to free it in CObject_1::FinalRelease
pObject2->Release();

After this pObject2 can be used as an ordinary
C++ pointer.

  /claes


Quote:
> Hi all...

> To state simply the problem. I have an ATL object that has 2 interfaces,
> each one has the corresponding class, for example,

> CObject_1
> IObject_1
> CObject_2
> IObject_2

> CObject_1 need to access a public member variable in CObject_2, how can I
do
> it? I tried declaring in CObject_1 an object of type CObject_2 but it
didn't
> compile because of the definition of the CObject_2 class... for instance:

> class ATL_NO_VTABLE CObject_2 :
>  public CComObjectRootEx<CComSingleThreadModel>,
>  public CComCoClass<CObject_2, &CLSID_Object_2>,
>  public IDispatchImpl<IObject_2, &IID_IObject_2, &LIBID_ICFILELib>
> {

> DECLARE_NO_REGISTRY()
> DECLARE_NOT_AGGREGATABLE(CObject_2)
> DECLARE_PROTECT_FINAL_CONSTRUCT()

> BEGIN_COM_MAP(CObject_2)
>  COM_INTERFACE_ENTRY(IObject_2)
>  COM_INTERFACE_ENTRY(IDispatch)
> END_COM_MAP()
> };

> CObject_1 has the same skeleton

> Any one can help?
> Thanks a los in advance

> Jaime



Fri, 20 Aug 2004 17:47:40 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Classes as member variables of another class

2. Accessing a member variable directly in another class

3. Getting access to member variables of CView class

4. Accessing a member variable of the application class

5. Using a class as a member variable in the document class

6. PropertySheet and member variables of one Class visible for other classes

7. Accessing member variables in CView derived class from a Modeless Dialog Box

8. Problem in Multithread access the Class member variable?

9. Accessing COM class members when passed in to a COM class

10. mutual class include problem: accessing members from one class from inside another

11. form class accessing view class members?

12. Accessing public variables in Document class from a Dialog Class

 

 
Powered by phpBB® Forum Software