1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
ATLINLINE ATLAPI AtlRegisterClassCategoriesHelper( REFCLSID clsid,
const struct _ATL_CATMAP_ENTRY* pCatMap, BOOL bRegister )
{
CComPtr< ICatRegister > pCatRegister;
HRESULT hResult;
const struct _ATL_CATMAP_ENTRY* pEntry;
CATID catid;
if( pCatMap == NULL )
{
return( S_OK );
}
if (InlineIsEqualGUID(clsid, GUID_NULL))
{
ATLASSERT(0 && _T("Use OBJECT_ENTRY_NON_CREATEABLE_EX macro if you want to register class categories for non creatable objects."));
return S_OK;
}
hResult = CoCreateInstance( CLSID_StdComponentCategoriesMgr, NULL,
CLSCTX_INPROC_SERVER, __uuidof(ICatRegister), (void**)&pCatRegister );
if( FAILED( hResult ) )
{
// Since not all systems have the category manager installed, we'll allow
// the registration to succeed even though we didn't register our
// categories. If you really want to register categories on a system
// without the category manager, you can either manually add the
// appropriate entries to your registry script (.rgs), or you can
// redistribute comcat.dll.
return( S_OK );
}
hResult = S_OK;
pEntry = pCatMap;
while( pEntry->iType != _ATL_CATMAP_ENTRY_END )
{
catid = *pEntry->pcatid;
if( bRegister )
{
if( pEntry->iType == _ATL_CATMAP_ENTRY_IMPLEMENTED )
{
hResult = pCatRegister->RegisterClassImplCategories( clsid, 1,
&catid );
}
else
{
ATLASSERT( pEntry->iType == _ATL_CATMAP_ENTRY_REQUIRED );
hResult = pCatRegister->RegisterClassReqCategories( clsid, 1,
&catid );
}
if( FAILED( hResult ) )
{
return( hResult );
}
}
else
{
if( pEntry->iType == _ATL_CATMAP_ENTRY_IMPLEMENTED )
{
pCatRegister->UnRegisterClassImplCategories( clsid, 1, &catid );
}
else
{
ATLASSERT( pEntry->iType == _ATL_CATMAP_ENTRY_REQUIRED );
pCatRegister->UnRegisterClassReqCategories( clsid, 1, &catid );
}
}
pEntry++;
}
// When unregistering remove "Implemented Categories" and "Required Categories" subkeys if they are empty.
if (!bRegister)
{
OLECHAR szGUID[64];
::StringFromGUID2(clsid, szGUID, 64);
USES_CONVERSION_EX;
TCHAR* pszGUID = OLE2T_EX(szGUID, _ATL_SAFE_ALLOCA_DEF_THRESHOLD);
if (pszGUID != NULL)
{
TCHAR szKey[128];
#ifdef UNICODE
Checked::wcscpy_s(szKey, _countof(szKey), _T("CLSID\\"));
Checked::wcscat_s(szKey, _countof(szKey), pszGUID);
Checked::wcscat_s(szKey, _countof(szKey), _T("\\Required Categories"));
#else
Checked::strcpy_s(szKey, _countof(szKey), _T("CLSID\\"));
Checked::strcat_s(szKey, _countof(szKey), pszGUID);
Checked::strcat_s(szKey, _countof(szKey), _T("\\Required Categories"));
#endif
CRegKey root(HKEY_CLASSES_ROOT);
CRegKey key;
DWORD cbSubKeys = 0;
LRESULT lRes = key.Open(root, szKey, KEY_READ);
if (lRes == ERROR_SUCCESS)
{
lRes = RegQueryInfoKey(key, NULL, NULL, NULL, &cbSubKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
key.Close();
if (lRes == ERROR_SUCCESS && cbSubKeys == 0)
{
root.DeleteSubKey(szKey);
}
}
#ifdef UNICODE
Checked::wcscpy_s(szKey, _countof(szKey), _T("CLSID\\"));
Checked::wcscat_s(szKey, _countof(szKey), pszGUID);
Checked::wcscat_s(szKey, _countof(szKey), _T("\\Implemented Categories"));
#else
Checked::strcpy_s(szKey, _countof(szKey), _T("CLSID\\"));
Checked::strcat_s(szKey, _countof(szKey), pszGUID);
Checked::strcat_s(szKey, _countof(szKey), _T("\\Implemented Categories"));
#endif
lRes = key.Open(root, szKey, KEY_READ);
if (lRes == ERROR_SUCCESS)
{
lRes = RegQueryInfoKey(key, NULL, NULL, NULL, &cbSubKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
key.Close();
if (lRes == ERROR_SUCCESS && cbSubKeys == 0)
{
root.DeleteSubKey(szKey);
}
}
}
}
return( S_OK );
}
#endif // _ATL_DLL |
Partager