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.

122 lines
3.0 KiB

  1. /*++
  2. Copyright (C) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. cathelp.cpp
  5. Abstract:
  6. Component category implementation.
  7. --*/
  8. #include "comcat.h"
  9. #include <strsafe.h>
  10. #define CATEGORY_DESCRIPTION_LEN 128
  11. // Helper function to create a component category and associated description
  12. HRESULT
  13. CreateComponentCategory (
  14. IN CATID catid,
  15. IN WCHAR* catDescription )
  16. {
  17. HRESULT hr = S_OK ;
  18. CATEGORYINFO catinfo;
  19. ICatRegister* pCatRegister = NULL ;
  20. hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
  21. NULL,
  22. CLSCTX_INPROC_SERVER,
  23. IID_ICatRegister,
  24. (void**)&pCatRegister);
  25. if (SUCCEEDED(hr)) {
  26. //
  27. // Make sure the HKCR\Component Categories\{..catid...}
  28. // key is registered
  29. //
  30. catinfo.catid = catid;
  31. catinfo.lcid = 0x0409 ; // english
  32. //
  33. // Make sure the provided description is not too long.
  34. // Only copy the first 127 characters if it is
  35. //
  36. StringCchCopy(catinfo.szDescription, CATEGORY_DESCRIPTION_LEN, catDescription);
  37. hr = pCatRegister->RegisterCategories(1, &catinfo);
  38. }
  39. if (pCatRegister != NULL) {
  40. pCatRegister->Release();
  41. }
  42. return hr;
  43. }
  44. // Helper function to register a CLSID as belonging to a component category
  45. HRESULT RegisterCLSIDInCategory(
  46. IN REFCLSID clsid,
  47. IN CATID catid
  48. )
  49. {
  50. ICatRegister* pCatRegister = NULL ;
  51. HRESULT hr = S_OK ;
  52. hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
  53. NULL,
  54. CLSCTX_INPROC_SERVER,
  55. IID_ICatRegister,
  56. (void**)&pCatRegister);
  57. if (SUCCEEDED(hr))
  58. {
  59. //
  60. // Register this category as being "implemented" by
  61. // the class.
  62. //
  63. CATID rgcatid[1] ;
  64. rgcatid[0] = catid;
  65. hr = pCatRegister->RegisterClassImplCategories(clsid, 1, rgcatid);
  66. }
  67. if (pCatRegister != NULL) {
  68. pCatRegister->Release();
  69. }
  70. return hr;
  71. }
  72. // Helper function to unregister a CLSID as belonging to a component category
  73. HRESULT UnRegisterCLSIDInCategory(
  74. REFCLSID clsid,
  75. CATID catid
  76. )
  77. {
  78. ICatRegister* pCatRegister = NULL ;
  79. HRESULT hr = S_OK ;
  80. hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
  81. NULL,
  82. CLSCTX_INPROC_SERVER,
  83. IID_ICatRegister,
  84. (void**)&pCatRegister);
  85. if (SUCCEEDED(hr))
  86. {
  87. // Unregister this category as being "implemented" by
  88. // the class.
  89. CATID rgcatid[1] ;
  90. rgcatid[0] = catid;
  91. hr = pCatRegister->UnRegisterClassImplCategories(clsid, 1, rgcatid);
  92. }
  93. if (pCatRegister != NULL) {
  94. pCatRegister->Release();
  95. }
  96. return hr;
  97. }