#pragma once
// '04.12.15 : 新規作成 (sug)
// '05.01.06 : テンプレート化 (sug)
#include <Msi.h>
#pragma comment (lib, "Msi.lib")
#include <MsiDefs.h>
#include <MsiQuery.h>
/////////////////////////////////////////////////////////////////////////////
// CMsiViewT
template <bool t_bManaged>
class CMsiViewT
{
public:
CMsiViewT()
{
m_hView = 0;
}
CMsiViewT(MSIHANDLE hView)
{
m_hView = hView;
}
virtual ~CMsiViewT()
{
if (t_bManaged && m_hView != 0)
{
this->CloseHandle();
}
}
public:
bool IsValid()
{
if (m_hView == 0)
{
return false;
}
return true;
}
public:
void Attach(MSIHANDLE hView)
{
ATLASSERT(m_hView == 0);
ATLASSERT(hView != 0);
m_hView = hView;
}
MSIHANDLE Detach()
{
ATLASSERT(m_hView != 0);
MSIHANDLE hView = m_hView;
m_hView = 0;
return hView;
}
public:
CMsiViewT& operator=(MSIHANDLE hView)
{
m_hView = hView;
return *this;
}
operator MSIHANDLE()
{
return m_hView;
}
public:
UINT CloseHandle()
{
ATLASSERT(m_hView != 0);
MSIHANDLE hView = m_hView;
m_hView = 0;
return ::MsiCloseHandle(hView);
}
public:
// 未テストです。
#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
MSIDBERROR GetError(CString& strColumnNameBuffer)
{
ATLASSERT(m_hView != 0);
strColumnNameBuffer.Empty();
DWORD dwBuff = 0;
MSIDBERROR dber = ::MsiViewGetError(m_hView, _T(""), &dwBuff);
if (dber != MSIDBERROR_MOREDATA)
{
return dber;
}
dwBuff += 1;
CString strTempBuf;
strTempBuf.GetBufferSetLength(dwBuff);
dber = ::MsiViewGetError(m_hView, strTempBuf.GetBuffer(), &dwBuff);
if (dber != MSIDBERROR_NOERROR)
{
strTempBuf.ReleaseBuffer();
return dber;
}
strTempBuf.ReleaseBuffer();
strColumnNameBuffer = strTempBuf;
return dber;
}
#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
MSIDBERROR GetError(LPSTR szColumnNameBuffer, DWORD* pcchBuf)
{
ATLASSERT(m_hView != 0);
return ::MsiViewGetError(m_hView, szColumnNameBuffer, pcchBuf);
}
UINT Close()
{
ATLASSERT(m_hView != 0);
return ::MsiViewClose(m_hView);
}
UINT Execute(MSIHANDLE hRecord)
{
ATLASSERT(m_hView != 0);
return ::MsiViewExecute(m_hView, hRecord);
}
UINT Fetch(MSIHANDLE* phRecord)
{
ATLASSERT(m_hView != 0);
return ::MsiViewFetch(m_hView, phRecord);
}
UINT Modify(MSIMODIFY eModifyMode, MSIHANDLE hRecord)
{
ATLASSERT(m_hView != 0);
return ::MsiViewModify(m_hView, eModifyMode, hRecord);
}
UINT GetColumnInfo(MSICOLINFO eColumnInfo, MSIHANDLE *phRecord)
{
ATLASSERT(m_hView != 0);
return ::MsiViewGetColumnInfo(m_hView, eColumnInfo, phRecord);
}
public:
MSIHANDLE m_hView;
};
typedef CMsiViewT<false> CMsiViewHandle;
typedef CMsiViewT<true> CMsiView;