#pragma once
// '04.12.21 : 新規作成 (sug)
// '05.01.06 : テンプレート化 (sug)
#include <Msi.h>
#pragma comment (lib, "Msi.lib")
#include <MsiDefs.h>
#include <MsiQuery.h>
/////////////////////////////////////////////////////////////////////////////
// CMsiPreviewT
template <bool t_bManaged>
class CMsiPreviewT
{
public:
CMsiPreviewT()
{
m_hPreview = 0;
}
CMsiPreviewT(MSIHANDLE hPreview)
{
m_hPreview = hPreview;
}
virtual ~CMsiPreviewT()
{
if (t_bManaged && m_hPreview != 0)
{
this->CloseHandle();
}
}
public:
bool IsValid()
{
if (m_hPreview == 0)
{
return false;
}
return true;
}
public:
void Attach(MSIHANDLE hPreview)
{
ATLASSERT(m_hPreview == 0);
ATLASSERT(hPreview != 0);
m_hPreview = hPreview;
}
MSIHANDLE Detach()
{
ATLASSERT(m_hPreview != 0);
MSIHANDLE hPreview = m_hPreview;
m_hPreview = 0;
return hPreview;
}
public:
CMsiPreviewT& operator=(MSIHANDLE hPreview)
{
m_hPreview = hPreview;
return *this;
}
operator MSIHANDLE()
{
return m_hPreview;
}
public:
UINT CloseHandle()
{
ATLASSERT(m_hPreview != 0);
MSIHANDLE hPreview = m_hPreview;
m_hPreview = 0;
return ::MsiCloseHandle(hPreview);
}
// Functions for rendering UI dialogs from the database representations.
public:
UINT PreviewDialog(LPCSTR szDialogName)
{
ATLASSERT(m_hPreview != 0);
return ::MsiPreviewDialog(m_hPreview, szDialogName);
}
INT PreviewBillboard(LPCSTR szControlName, LPCSTR szBillboard)
{
ATLASSERT(m_hPreview != 0);
return ::MsiPreviewBillboard(m_hPreview, szControlName, szBillboard);
}
public:
MSIHANDLE m_hPreview;
};
typedef CMsiPreviewT<false>CMsiPreviewHandle;
typedef CMsiPreviewT<true>CMsiPreview;