Newbie Q: Using a pointer to a COM class with in the ATL project 
Author Message
 Newbie Q: Using a pointer to a COM class with in the ATL project

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;
        }

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);
        }

        void FinalRelease()
        {
                m_pUnkMarshaler.Release();
        }

        CComPtr<IUnknown> m_pUnkMarshaler;

// ISupportsErrorInfo
        STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);

// ISimpleObj
public:
        STDMETHOD(CallFromClient)(/*[in]*/ BSTR sSomeString);
        void CallFromElseWhere();

Quote:
};

#endif //__SIMPLEOBJ_H_

**************************************************************************



Tue, 13 May 2003 03:00:00 GMT  
 Newbie Q: Using a pointer to a COM class with in the ATL project
Quote:
>Jerry J schrieb in Nachricht


Quote:

>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' :
Quote:
>undeclared identifier
>c:\vcproj\objectpointer\simpleobj.h(17) : fatal error C1903: unable to
recover
>from previous error(s); stopping compilation

These undeclared identifiers are declared in a header file that is generated
by the MIDL compiler processing the IDL-file. If you did not change the
default settings, the header is named PROJECTNAME.h. If you include this
header in CLocal's header ( local.h I guess), before you include
simpleobject.h your problem should be solved.

Regards
Harald



Wed, 14 May 2003 03:48:50 GMT  
 Newbie Q: Using a pointer to a COM class with in the ATL project

Harald,

Thank you for your reply!  I get so frustrated when I spend hours trying to
figure out something that I could have fixed in seconds!

I did what you suggested and it works.  

Thank You!

Jerry J

Quote:
-----Original Message-----
>Jerry J schrieb in Nachricht


Quote:

>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' :
Quote:
>undeclared identifier
>c:\vcproj\objectpointer\simpleobj.h(17) : fatal error C1903: unable to
recover
>from previous error(s); stopping compilation

These undeclared identifiers are declared in a header file that is generated
by the MIDL compiler processing the IDL-file. If you did not change the
default settings, the header is named PROJECTNAME.h. If you include this
header in CLocal's header ( local.h I guess), before you include
simpleobject.h your problem should be solved.

Regards
Harald

.



Wed, 14 May 2003 05:04:02 GMT  
 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_

**************************************************************************



Fri, 16 May 2003 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. ATL COM - Passing ATL COM classes through another ATL COM class in the same app

2. Newbie question on debugging a ATL COM Project

3. Class Factory in ATL COM Project ?

4. Problem using a VB COM object in ATL project

5. ATL and Base Class Pointers in COM

6. Using MFC classes in ATL project

7. COM/ATL novice:passing object pointers through methods on a COM interface

8. passing COM object pointers to another COM object in ATL

9. using ATL types in non-ATL project

10. Can't add more than one ATL object to an ATL project using wizard

11. Howto Expose a normal C++ class with methods via an Interface Class in ATL COM

12. ATL COM Class Final Construct dies with Member Accessor Class

 

 
Powered by phpBB® Forum Software