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.

98 lines
3.0 KiB

  1. //=--------------------------------------------------------------------------=
  2. // CatHelp.Cpp
  3. //=--------------------------------------------------------------------------=
  4. // Copyright 1995-1996 Microsoft Corporation. All Rights Reserved.
  5. //
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  7. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  8. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  9. // PARTICULAR PURPOSE.
  10. //=--------------------------------------------------------------------------=
  11. //
  12. // contains the Component Category helper functions.
  13. //
  14. #include "stdafx.h"
  15. #include <comcat.h>
  16. //const CATID CATID_SafeForScripting = {0x7dd95801,0x9882,0x11cf,{0x9f,0xa9,0x00,0xaa,0x00,0x6c,0x42,0xc4}};
  17. //const CATID CATID_SafeForInitializing = {0x7dd95802,0x9882,0x11cf,{0x9f,0xa9,0x00,0xaa,0x00,0x6c,0x42,0xc4}};
  18. // Helper function to create a component category and associated description
  19. HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription)
  20. {
  21. ICatRegister* pcr = NULL ;
  22. HRESULT hr = S_OK ;
  23. hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
  24. NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
  25. if (FAILED(hr))
  26. return hr;
  27. // Make sure the HKCR\Component Categories\{..catid...}
  28. // key is registered
  29. CATEGORYINFO catinfo;
  30. catinfo.catid = catid;
  31. catinfo.lcid = 0x0409 ; // english
  32. // Make sure the provided description is not too long.
  33. // Only copy the first 127 characters if it is
  34. int len = wcslen(catDescription);
  35. if (len>127)
  36. len = 127;
  37. wcsncpy(catinfo.szDescription, catDescription, len);
  38. // Make sure the description is null terminated
  39. catinfo.szDescription[len] = '\0';
  40. hr = pcr->RegisterCategories(1, &catinfo);
  41. pcr->Release();
  42. return hr;
  43. }
  44. // Helper function to register a CLSID as belonging to a component category
  45. HRESULT RegisterCLSIDInCategory(REFCLSID clsid, CATID catid)
  46. {
  47. // Register your component categories information.
  48. ICatRegister* pcr = NULL ;
  49. HRESULT hr = S_OK ;
  50. hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
  51. NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
  52. if (SUCCEEDED(hr))
  53. {
  54. // Register this category as being "implemented" by
  55. // the class.
  56. CATID rgcatid[1] ;
  57. rgcatid[0] = catid;
  58. hr = pcr->RegisterClassImplCategories(clsid, 1, rgcatid);
  59. }
  60. if (pcr != NULL)
  61. pcr->Release();
  62. return hr;
  63. }
  64. // Helper function to unregister a CLSID as belonging to a component category
  65. HRESULT UnRegisterCLSIDInCategory(REFCLSID clsid, CATID catid)
  66. {
  67. ICatRegister* pcr = NULL ;
  68. HRESULT hr = S_OK ;
  69. hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
  70. NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
  71. if (SUCCEEDED(hr))
  72. {
  73. // Unregister this category as being "implemented" by
  74. // the class.
  75. CATID rgcatid[1] ;
  76. rgcatid[0] = catid;
  77. hr = pcr->UnRegisterClassImplCategories(clsid, 1, rgcatid);
  78. }
  79. if (pcr != NULL)
  80. pcr->Release();
  81. return hr;
  82. }