#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.
#include <vector>
#include <comcat.h>
_COM_SMARTPTR_TYPEDEF(ICatInformation, __uuidof(ICatInformation));
_COM_SMARTPTR_TYPEDEF(IEnumCATEGORYINFO, __uuidof(IEnumCATEGORYINFO));
_COM_SMARTPTR_TYPEDEF(IEnumCLSID, __uuidof(IEnumCLSID));
/////////////////////////////////////////////////////////////////////////////
// CCatHelper
class CCatHelper
{
protected:
typedef CCatHelper thisCLass;
protected:
CCatHelper(); // 実装しない
virtual ~CCatHelper();
public:
// カテゴリの列挙
static HRESULT EnumCatInfos(LCID lcid, std::vector<CATEGORYINFO>& catInfos)
{
HRESULT hr = S_OK;
catInfos.clear();
try
{
ICatInformationPtr spCatInformation;
hr = spCatInformation.CreateInstance(CLSID_StdComponentCategoriesMgr);
if (FAILED(hr))
{
return hr;
}
IEnumCATEGORYINFOPtr spEnumCategoryInfo;
hr = spCatInformation->EnumCategories(lcid, &spEnumCategoryInfo);
if (FAILED(hr))
{
return hr;
}
do
{
CATEGORYINFO CatInfo = { 0 };
ULONG lCeltFetched = 0;
hr = spEnumCategoryInfo->Next(1, &CatInfo, &lCeltFetched);
if (FAILED(hr))
{
return hr;
}
catInfos.push_back(CatInfo);
}
while (hr == S_OK);
}
catch (...)
{
return E_FAIL;
}
return S_OK;
}
// あるコテゴリのCLSIDの列挙
static HRESULT EnumClsIDs(const GUID& catID, std::vector<CLSID>& clsIDs)
{
HRESULT hr = S_OK;
clsIDs.clear();
try
{
ICatInformationPtr spCatInformation;
hr = spCatInformation.CreateInstance(CLSID_StdComponentCategoriesMgr);
if (FAILED(hr))
{
return hr;
}
IEnumCLSIDPtr spEnumCLSID;
hr = spCatInformation->EnumClassesOfCategories(1, (CATID*)&catID, 0, NULL, &spEnumCLSID);
if (FAILED(hr))
{
return hr;
}
do
{
CLSID clsid = GUID_NULL;
ULONG lCeltFetched = 0;
hr = spEnumCLSID->Next(1, &clsid, &lCeltFetched);
if (FAILED(hr))
{
return hr;
}
clsIDs.push_back(clsid);
}
while (hr == S_OK);
}
catch (...)
{
return E_FAIL;
}
return S_OK;
}
};