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.

94 lines
2.6 KiB

  1. //=======================================================================
  2. //
  3. // Copyright (C) Microsoft Corporation, 1995 - 1999 All Rights Reserved.
  4. //
  5. // File: CatHelp.cpp
  6. //
  7. // contains the Component Category helper functions.
  8. //
  9. //=======================================================================
  10. #include "stdafx.h"
  11. #include "comcat.h"
  12. EXTERN_C const CATID CATID_SafeForScripting;
  13. EXTERN_C const CATID CATID_SafeForInitializing;
  14. // Helper function to create a component category and associated description
  15. HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription)
  16. {
  17. ICatRegister* pcr = NULL ;
  18. HRESULT hr = S_OK ;
  19. hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
  20. NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
  21. if (FAILED(hr))
  22. return hr;
  23. // Make sure the HKCR\Component Categories\{..catid...}
  24. // key is registered
  25. CATEGORYINFO catinfo;
  26. catinfo.catid = catid;
  27. catinfo.lcid = 0x0409 ; // english
  28. // Make sure the provided description is not too long.
  29. // Only copy the first 127 characters if it is
  30. int len = wcslen(catDescription);
  31. if (len>127)
  32. len = 127;
  33. wcsncpy(catinfo.szDescription, catDescription, len);
  34. // Make sure the description is null terminated
  35. catinfo.szDescription[len] = '\0';
  36. hr = pcr->RegisterCategories(1, &catinfo);
  37. pcr->Release();
  38. return hr;
  39. }
  40. // Helper function to register a CLSID as belonging to a component category
  41. HRESULT RegisterCLSIDInCategory(REFCLSID clsid, CATID catid)
  42. {
  43. // Register your component categories information.
  44. ICatRegister* pcr = NULL ;
  45. HRESULT hr = S_OK ;
  46. hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
  47. NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
  48. if (SUCCEEDED(hr))
  49. {
  50. // Register this category as being "implemented" by
  51. // the class.
  52. CATID rgcatid[1] ;
  53. rgcatid[0] = catid;
  54. hr = pcr->RegisterClassImplCategories(clsid, 1, rgcatid);
  55. }
  56. if (pcr != NULL)
  57. pcr->Release();
  58. return hr;
  59. }
  60. // Helper function to unregister a CLSID as belonging to a component category
  61. HRESULT UnRegisterCLSIDInCategory(REFCLSID clsid, CATID catid)
  62. {
  63. ICatRegister* pcr = NULL ;
  64. HRESULT hr = S_OK ;
  65. hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
  66. NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
  67. if (SUCCEEDED(hr))
  68. {
  69. // Unregister this category as being "implemented" by
  70. // the class.
  71. CATID rgcatid[1] ;
  72. rgcatid[0] = catid;
  73. hr = pcr->UnRegisterClassImplCategories(clsid, 1, rgcatid);
  74. }
  75. if (pcr != NULL)
  76. pcr->Release();
  77. return hr;
  78. }
  79.