MSIHANDLEを扱う単純なラッパクラス

PMSIHANDLEと同等
(2005.02.08)
#pragma once
 
// '05.01.12 : 新規作成 (sug)
 
#include <Msi.h>
 
 
/////////////////////////////////////////////////////////////////////////////
// CMsiHandleT
 
template <bool t_bManaged>
class CMsiHandleT
{
public:
    CMsiHandleT()
    {
        m_h = 0;
    }
    CMsiHandleT(MSIHANDLE h)
    {
        m_h = h;
    }
    virtual ~CMsiHandleT()
    {
        if (t_bManaged && m_h != 0)
        {
            this->CloseHandle();
        }
    }
 
public:
    bool IsValid()
    {
        if (m_h == 0)
        {
            return false;
        }
 
        return true;
    }
    
public:
    void Attach(MSIHANDLE h)
    {
        ATLASSERT(m_h == 0);
        ATLASSERT(h != 0);
        m_h = h;
    }
    MSIHANDLE Detach()
    {    
        ATLASSERT(m_h != 0);
        MSIHANDLE h = m_h;
        m_h = 0;
        return h;
    }
 
public:
    CMsiHandleT& operator =(MSIHANDLE h)
    {
        m_h = h;
        return *this;
    }
    operator MSIHANDLE()
    { 
        return m_h; 
    }
 
public:
    UINT CloseHandle()
    {
        ATLASSERT(m_h != 0);
        MSIHANDLE h = m_h;
        m_h = 0;
        return ::MsiCloseHandle(h);
    }
 
public:
   MSIHANDLE m_h;  
};
 
typedef CMsiHandleT<false>CMsiHandleHandle;
typedef CMsiHandleT<true>CMsiHandle;
一覧に戻る
© 2003 WAC.com All Right Reserved.