Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
4.7 KiB

  1. //------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000
  5. //
  6. // File: DllRegHelper.cpp
  7. //
  8. // Contents: helper classes to register COM components in DLLs
  9. //
  10. //------------------------------------------------------------------------
  11. #include "DllRegHelper.h"
  12. #pragma hdrstop
  13. #include <comcat.h>
  14. #include <advpub.h>
  15. #include "ccstock.h"
  16. #include "shlwapi.h"
  17. #include "debug.h"
  18. #include "mluisupp.h"
  19. #define _APLHA_ComCat_WorkAround // { ALPHA ComCat bug work-around on alpha, nuke this eventually?
  20. // ie40:63004: comcat does RegCloseKey(invalid) on checked
  21. // nt/alpha if the clsid doesn't exist (e.g. for QuickLinksOld)
  22. #if defined(_APLHA_ComCat_WorkAround)
  23. //------------------------------------------------------------------------
  24. //*** HasImplCat -- does "HKCR/CLSID/{clsid}/Implemented Categories" exist
  25. // NOTES
  26. // used for ComCat bug work-around on alpha
  27. BOOL HasImplCat(const CATID *pclsid)
  28. {
  29. HKEY hk;
  30. TCHAR szClass[GUIDSTR_MAX];
  31. TCHAR szImpl[MAX_PATH]; // "CLSID/{clsid}/Implemented Categories" < MAX_PATH
  32. // "CLSID/{clsid}/Implemented Categories"
  33. SHStringFromGUID(*pclsid, szClass, ARRAYSIZE(szClass));
  34. ASSERT(lstrlen(szClass) == GUIDSTR_MAX - 1);
  35. wnsprintf(szImpl, ARRAYSIZE(szImpl), TEXT("CLSID\\%s\\Implemented Categories"), szClass);
  36. if (RegOpenKeyEx(HKEY_CLASSES_ROOT, szImpl, 0, KEY_READ, &hk) == ERROR_SUCCESS) {
  37. RegCloseKey(hk);
  38. return TRUE;
  39. }
  40. else {
  41. TraceMsg(DM_WARNING, "HasImplCat: %s: ret 0", szImpl);
  42. return FALSE;
  43. }
  44. }
  45. #endif // }
  46. //------------------------------------------------------------------------
  47. //*** RegisterOneCategory -- [un]register ComCat implementor(s) and category
  48. // ENTRY/EXIT
  49. // eRegister CCR_REG, CCR_UNREG, CCR_UNREGIMP
  50. // CCR_REG, UNREG reg/unreg implementor(s) and category
  51. // CCR_UNREGIMP unreg implementor(s) only
  52. // pcatidCat e.g. CATID_DeskBand
  53. // idResCat e.g. IDS_CATDESKBAND
  54. // pcatidImpl e.g. c_DeskBandClasses
  55. HRESULT DRH_RegisterOneCategory(const CATID *pcatidCat, UINT idResCat, const CATID * const *pcatidImpl, enum DRH_REG_MODE eRegister)
  56. {
  57. ICatRegister* pcr;
  58. HRESULT hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL,
  59. CLSCTX_INPROC_SERVER, IID_PPV_ARG(ICatRegister, &pcr));
  60. if (SUCCEEDED(hr))
  61. {
  62. if (eRegister == CCR_REG)
  63. {
  64. // register the category
  65. CATEGORYINFO catinfo;
  66. catinfo.catid = *pcatidCat; // e.g. CATID_DESKBAND
  67. catinfo.lcid = LOCALE_USER_DEFAULT;
  68. MLLoadString(idResCat, catinfo.szDescription, ARRAYSIZE(catinfo.szDescription));
  69. hr = pcr->RegisterCategories(1, &catinfo);
  70. ASSERT(SUCCEEDED(hr));
  71. // register the classes that implement categories
  72. for ( ; *pcatidImpl != NULL; pcatidImpl++)
  73. {
  74. CLSID clsid = **pcatidImpl;
  75. CATID catid = *pcatidCat;
  76. hr = pcr->RegisterClassImplCategories(clsid, 1, &catid);
  77. ASSERT(SUCCEEDED(hr));
  78. }
  79. }
  80. else
  81. {
  82. // unregister the classes that implement categories
  83. for ( ; *pcatidImpl != NULL; pcatidImpl++)
  84. {
  85. CLSID clsid = **pcatidImpl;
  86. CATID catid = *pcatidCat;
  87. #if defined(_APLHA_ComCat_WorkAround) // { ALPHA ComCat bug work-around on alpha, nuke this eventually?
  88. // workaround comcat/alpha bug
  89. // n.b. we do this for non-alpha too to reduce testing impact
  90. // ie40:63004: comcat does RegCloseKey(invalid) on checked
  91. // nt/alpha if the clsid doesn't exist (e.g. for QuickLinksOld)
  92. if (!HasImplCat(&clsid))
  93. continue;
  94. #endif // }
  95. hr = pcr->UnRegisterClassImplCategories(clsid, 1, &catid);
  96. ASSERT(SUCCEEDED(hr));
  97. }
  98. if (eRegister == CCR_UNREG)
  99. {
  100. // Do we want to do this? other classes (e.g. 3rd party
  101. // ones) might still be using the category. however since we're
  102. // the component that added (and supports) the category, it
  103. // seems correct that we should remove it when we unregister.
  104. // unregister the category
  105. CATID catid = *pcatidCat;
  106. hr = pcr->UnRegisterCategories(1, &catid);
  107. ASSERT(SUCCEEDED(hr));
  108. }
  109. }
  110. pcr->Release();
  111. }
  112. return S_OK;
  113. }