Leaked source code of windows server 2003
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.

131 lines
4.9 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 <shlwapi.h>
  16. #include "ccstock.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. HRESULT hr = StringCchPrintf(szImpl, ARRAYSIZE(szImpl), TEXT("CLSID\\%s\\Implemented Categories"), szClass);
  36. if (FAILED(hr))
  37. {
  38. return FALSE;
  39. }
  40. if (RegOpenKeyEx(HKEY_CLASSES_ROOT, szImpl, 0, KEY_QUERY_VALUE, &hk) == ERROR_SUCCESS) {
  41. RegCloseKey(hk);
  42. return TRUE;
  43. }
  44. else {
  45. TraceMsg(DM_WARNING, "HasImplCat: %s: ret 0", szImpl);
  46. return FALSE;
  47. }
  48. }
  49. #endif // }
  50. //------------------------------------------------------------------------
  51. //*** RegisterOneCategory -- [un]register ComCat implementor(s) and category
  52. // ENTRY/EXIT
  53. // eRegister CCR_REG, CCR_UNREG, CCR_UNREGIMP
  54. // CCR_REG, UNREG reg/unreg implementor(s) and category
  55. // CCR_UNREGIMP unreg implementor(s) only
  56. // pcatidCat e.g. CATID_DeskBand
  57. // idResCat e.g. IDS_CATDESKBAND
  58. // pcatidImpl e.g. c_DeskBandClasses
  59. HRESULT DRH_RegisterOneCategory(const CATID *pcatidCat, UINT idResCat, const CATID * const *pcatidImpl, enum DRH_REG_MODE eRegister)
  60. {
  61. ICatRegister* pcr;
  62. HRESULT hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL,
  63. CLSCTX_INPROC_SERVER, IID_PPV_ARG(ICatRegister, &pcr));
  64. if (SUCCEEDED(hr))
  65. {
  66. if (eRegister == CCR_REG)
  67. {
  68. // register the category
  69. CATEGORYINFO catinfo;
  70. catinfo.catid = *pcatidCat; // e.g. CATID_DESKBAND
  71. catinfo.lcid = LOCALE_USER_DEFAULT;
  72. MLLoadString(idResCat, catinfo.szDescription, ARRAYSIZE(catinfo.szDescription));
  73. hr = pcr->RegisterCategories(1, &catinfo);
  74. ASSERT(SUCCEEDED(hr));
  75. // register the classes that implement categories
  76. for ( ; *pcatidImpl != NULL; pcatidImpl++)
  77. {
  78. CLSID clsid = **pcatidImpl;
  79. CATID catid = *pcatidCat;
  80. hr = pcr->RegisterClassImplCategories(clsid, 1, &catid);
  81. ASSERT(SUCCEEDED(hr));
  82. }
  83. }
  84. else
  85. {
  86. // unregister the classes that implement categories
  87. for ( ; *pcatidImpl != NULL; pcatidImpl++)
  88. {
  89. CLSID clsid = **pcatidImpl;
  90. CATID catid = *pcatidCat;
  91. #if defined(_APLHA_ComCat_WorkAround) // { ALPHA ComCat bug work-around on alpha, nuke this eventually?
  92. // workaround comcat/alpha bug
  93. // n.b. we do this for non-alpha too to reduce testing impact
  94. // ie40:63004: comcat does RegCloseKey(invalid) on checked
  95. // nt/alpha if the clsid doesn't exist (e.g. for QuickLinksOld)
  96. if (!HasImplCat(&clsid))
  97. continue;
  98. #endif // }
  99. hr = pcr->UnRegisterClassImplCategories(clsid, 1, &catid);
  100. ASSERT(SUCCEEDED(hr));
  101. }
  102. if (eRegister == CCR_UNREG)
  103. {
  104. // Do we want to do this? other classes (e.g. 3rd party
  105. // ones) might still be using the category. however since we're
  106. // the component that added (and supports) the category, it
  107. // seems correct that we should remove it when we unregister.
  108. // unregister the category
  109. CATID catid = *pcatidCat;
  110. hr = pcr->UnRegisterCategories(1, &catid);
  111. ASSERT(SUCCEEDED(hr));
  112. }
  113. }
  114. pcr->Release();
  115. }
  116. return S_OK;
  117. }