COM/ATL component without a factory class 
Author Message
 COM/ATL component without a factory class

I need to do this (create B from A in a standard way, and, from A, return a
reference to interface B).
I have allready done this with MFC. How to make it with ATL ?

IClassB : public IDispatch
{
     virtual get_value([in] int x);

Quote:
};

IClassA : public IDispatch
{
     virtual GetClassB([out, retval] IClassB * * pB;

Quote:
};

ClassA : public CComObjectRootEx<CComSingleThreadModel>,
             public CComCoClass<ClassA , &CLSID_A>,
             public IDispatchImpl<IClassA , &IID_IClassA,
&LIBID_MyProjectLib>
{
    HRESULT GetClassB( IClassB * * pB )
  {
      pIb = new ClassB(14);
//<------- this doesn't work
     *pB = (IClassB *)pIb;
  }

Quote:
};

ClassB :  public CComObjectRootEx<CComSingleThreadModel>,
              public CComCoClass<ClassB , &CLSID_B>,
//<------- should I remove this ???
              public IDispatchImpl<IClassB , &IID_IClassB,
&LIBID_MyProjectLib>
{
protected:
   int m_nA, m_nB;
public:
   ClassB(int nA)
   {
      m_nA = a;
   }
   HRESULT get_value(int nB)
  {
     m_nB = nB;
  }
Quote:
};



Wed, 23 Jun 2004 18:41:27 GMT  
 COM/ATL component without a factory class
HRESULT GetClassB( IClassB * * pB )
{
    if (!pB)
        return E_POINTER;
    *pB = 0;
    CComObject<ClassB> *pIb;
    HRESULT hr = CComObject<ClassB>::CreateInstance(&pIb);
    if (SUCCEEDED(hr))
    {
        pIb->Init(14); // two-phase construction needed
        hr = pIb->QueryInterface(pB);
    }
    if (FAILED(hr))
        delete pIb;
    return hr;

Quote:
}

--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Quote:
> I need to do this (create B from A in a standard way, and, from A,
return a
> reference to interface B).
> I have allready done this with MFC. How to make it with ATL ?

> IClassB : public IDispatch
> {
>      virtual get_value([in] int x);
> };
> IClassA : public IDispatch
> {
>      virtual GetClassB([out, retval] IClassB * * pB;
> };

> ClassA : public CComObjectRootEx<CComSingleThreadModel>,
>              public CComCoClass<ClassA , &CLSID_A>,
>              public IDispatchImpl<IClassA , &IID_IClassA,
> &LIBID_MyProjectLib>
> {
>     HRESULT GetClassB( IClassB * * pB )
>   {
>       pIb = new ClassB(14);
> //<------- this doesn't work
>      *pB = (IClassB *)pIb;
>   }
> };

> ClassB :  public CComObjectRootEx<CComSingleThreadModel>,
>               public CComCoClass<ClassB , &CLSID_B>,
> //<------- should I remove this ???
>               public IDispatchImpl<IClassB , &IID_IClassB,
> &LIBID_MyProjectLib>
> {
> protected:
>    int m_nA, m_nB;
> public:
>    ClassB(int nA)
>    {
>       m_nA = a;
>    }
>    HRESULT get_value(int nB)
>   {
>      m_nB = nB;
>   }
> };



Sat, 26 Jun 2004 00:57:26 GMT  
 
 [ 2 post ] 

 Relevant Pages 

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

2. One ATL Component 2 class factories

3. Class Factory in ATL COM Project ?

4. noncreatable ATL objects, the class factory, and VB

5. The Class Factory of ATL

6. class factory need in COM?

7. class factory need in COM

8. ByPass the ATL Class Factory

9. Multiplexing class factory in ATL?

10. Multithreaded Class Factory / COM Server with MFC

11. Multithreaded Class Factory / COM Server with MFC

12. Problem converting VC6 ATL component to a .NET 2003 VC ATL component

 

 
Powered by phpBB® Forum Software