
Newbie Q: Using a pointer to a COM class with in the ATL project
Define a C++ interface (an abstract base class all of whose methods
are pure virtual) and implement it on your ATL object. The CLocal
class needs only to know about the interface class, not about the
ATL COM class that implements it.
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
I have a feeling I am doing something dumb, if I am, please set me
straight...
I created a very simple ATL project with 1 com class called "CSimpleObject".
Besides this one public com object, the ATL application defines one local
class
(plain old C++ class not available to clients) called "CLocal".
When one of the public methods of CSimpleObject gets called from a client,
it
will create a CLocal object. I want a function contained in CLocal object
to
take the "This" pointer so it can call back to a non-public member function
of
CSimpleObject.
My problem is that I can't include "CSimpleObject.h" in the .cpp file of
CLocal
because I get compiler errors:
Compiling...
allingObj.cpp
c:\vcproj\objectpointer\simpleobj.h(13) : error C2065: 'CLSID_SimpleObj' :
undeclared identifier
c:\vcproj\objectpointer\simpleobj.h(16) : error C2065: 'ISimpleObj' :
undeclared
identifier
c:\vcproj\objectpointer\simpleobj.h(16) : error C2065: 'IID_ISimpleObj' :
undeclared identifier
c:\vcproj\objectpointer\simpleobj.h(16) : error C2065:
'LIBID_OBJECTPOINTERLib' :
undeclared identifier
c:\vcproj\objectpointer\simpleobj.h(17) : fatal error C1903: unable to
recover
from previous error(s); stopping compilation
Am I trying to do something illegal? How do I fix this?
Please Help if you can!
Hear is the mostly MFC generated header file for CSimpleObject...
**************************************************************************
// SimpleObj.h : Declaration of the CSimpleObj
#ifndef __SIMPLEOBJ_H_
#define __SIMPLEOBJ_H_
#include "resource.h" // main symbols
////////////////////////////////////////////////////////////////////////////
/
// CSimpleObj
class ATL_NO_VTABLE CSimpleObj :
public CComObjectRootEx<CComMultiThreadModel>,
public CComCoClass<CSimpleObj, &CLSID_SimpleObj>,
public ISupportErrorInfo,
public IConnectionPointContainerImpl<CSimpleObj>,
public IDispatchImpl<ISimpleObj, &IID_ISimpleObj, &LIBID_OBJECTPOINTERLib>
{
public:
CSimpleObj()
{
m_pUnkMarshaler = NULL;
Quote:
}
DECLARE_REGISTRY_RESOURCEID(IDR_SIMPLEOBJ)
DECLARE_GET_CONTROLLING_UNKNOWN()
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(CSimpleObj)
COM_INTERFACE_ENTRY(ISimpleObj)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
COM_INTERFACE_ENTRY(IConnectionPointContainer)
COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
END_COM_MAP()
BEGIN_CONNECTION_POINT_MAP(CSimpleObj)
END_CONNECTION_POINT_MAP()
HRESULT FinalConstruct()
{
return CoCreateFreeThreadedMarshaler(
GetControllingUnknown(), &m_pUnkMarshaler.p);
Quote:
}
void FinalRelease()
{
m_pUnkMarshaler.Release();
Quote:
}
CComPtr<IUnknown> m_pUnkMarshaler;
// ISupportsErrorInfo
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
// ISimpleObj
public:
STDMETHOD(CallFromClient)(/*[in]*/ BSTR sSomeString);
void CallFromElseWhere();
Quote:
};
#endif //__SIMPLEOBJ_H_
**************************************************************************