参照カウンタの管理を行わないCComObject (CFixedComObjectStackEx) [ATL]

クラスのメンバ変数等に利用すると便利です。
(2007.05.16)
#pragma once
 
// WAC.com Class Liblary for Visual C++
// Copyright (C) WAC.com Inc. All rights reserved.
//
// This file is a part of the WAC.com Class Liblary.
// The use and distribution terms for this software are covered by the
// Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
// which can be found in the file CPL.TXT at the root of this distribution.
// By using this software in any fashion, you are agreeing to be bound by
// the terms of this license. You must not remove this notice, or
// any other, from this software.
 
 
/////////////////////////////////////////////////////////////////////////////
// CComObjectStackEx (旧 : CComObjectNoManage)
// 参照カウンタの管理を行わないCComObject
//  → クラスのメンバ変数等に利用すると便利
 
#if _MSC_VER < 1400
template <class Base>
class CComObjectStackEx : public Base
{
public:
    typedef Base _BaseClass;
    CComObjectStackEx(void* = NULL){m_hResFinalConstruct = FinalConstruct();}
    ~CComObjectStackEx(){FinalRelease();}
 
    STDMETHOD_(ULONG, AddRef)() {return 0;}
    STDMETHOD_(ULONG, Release)(){return 0;}
    STDMETHOD(QueryInterface)(REFIID iid, void ** ppvObject)
    {return _InternalQueryInterface(iid, ppvObject);}
    HRESULT m_hResFinalConstruct;
};
#endif
 
/////////////////////////////////////////////////////////////////////////////
// CFixedComObjectStackEx
 
#if _MSC_VER < 1400
typedef CFixedComObjectStackEx                    CComObjectStackEx
#else
// Base must be derived from CComObjectRoot
template <class Base>
class CFixedComObjectStackEx : public Base
{
public:
    typedef Base _BaseClass;
 
    CFixedComObjectStackEx(void* = NULL) 
    { 
#ifdef _DEBUG
        m_dwRef = 0;
#endif
        m_hResFinalConstruct = _AtlInitialConstruct();
        if (SUCCEEDED(m_hResFinalConstruct))
            m_hResFinalConstruct = FinalConstruct(); 
    }
 
    virtual ~CFixedComObjectStackEx()
    {
        // This assert indicates mismatched ref counts.
        //
        // The ref count has no control over the
        // lifetime of this object, so you must ensure
        // by some other means that the object remains 
        // alive while clients have references to its interfaces.
/* Del sha '06.10.13
        ATLASSUME(m_dwRef == 0);
...Del sha '06.10.13 */
        FinalRelease();
#ifdef _ATL_DEBUG_INTERFACES
        _AtlDebugInterfacesModule.DeleteNonAddRefThunk(_GetRawUnknown());
#endif
    }
 
    STDMETHOD_(ULONG, AddRef)() throw()
    {
#ifdef _DEBUG
        return InternalAddRef();
#else
        return 0;
#endif
    }
 
    STDMETHOD_(ULONG, Release)() throw()
    {
#ifdef _DEBUG
        return InternalRelease();
#else
        return 0;
#endif
    }
 
    STDMETHOD(QueryInterface)(REFIID iid, void ** ppvObject) throw()
    {
        return _InternalQueryInterface(iid, ppvObject);
    }
 
    HRESULT m_hResFinalConstruct;
};
#endif
一覧に戻る
© 2003 WAC.com All Right Reserved.