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
2.4 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. // Helper function to create a component category and associated description
  10. HRESULT
  11. CreateComponentCategory (
  12. CATID catid,
  13. WCHAR* catDescription )
  14. {
  15. CATEGORYINFO catinfo;
  16. ICatRegister* pcr = NULL ;
  17. HRESULT hr = S_OK ;
  18. SIZE_T len;
  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. catinfo.catid = catid;
  26. catinfo.lcid = 0x0409 ; // english
  27. // Make sure the provided description is not too long.
  28. // Only copy the first 127 characters if it is
  29. len = wcslen(catDescription);
  30. if (len>127)
  31. len = 127;
  32. wcsncpy(catinfo.szDescription, catDescription, len);
  33. // Make sure the description is null terminated
  34. catinfo.szDescription[len] = '\0';
  35. hr = pcr->RegisterCategories(1, &catinfo);
  36. pcr->Release();
  37. return hr;
  38. }
  39. // Helper function to register a CLSID as belonging to a component category
  40. HRESULT RegisterCLSIDInCategory(REFCLSID clsid, CATID catid)
  41. {
  42. // Register your component categories information.
  43. ICatRegister* pcr = NULL ;
  44. HRESULT hr = S_OK ;
  45. hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
  46. NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
  47. if (SUCCEEDED(hr))
  48. {
  49. // Register this category as being "implemented" by
  50. // the class.
  51. CATID rgcatid[1] ;
  52. rgcatid[0] = catid;
  53. hr = pcr->RegisterClassImplCategories(clsid, 1, rgcatid);
  54. }
  55. if (pcr != NULL)
  56. pcr->Release();
  57. return hr;
  58. }
  59. // Helper function to unregister a CLSID as belonging to a component category
  60. HRESULT UnRegisterCLSIDInCategory(REFCLSID clsid, CATID catid)
  61. {
  62. ICatRegister* pcr = NULL ;
  63. HRESULT hr = S_OK ;
  64. hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
  65. NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
  66. if (SUCCEEDED(hr))
  67. {
  68. // Unregister this category as being "implemented" by
  69. // the class.
  70. CATID rgcatid[1] ;
  71. rgcatid[0] = catid;
  72. hr = pcr->UnRegisterClassImplCategories(clsid, 1, rgcatid);
  73. }
  74. if (pcr != NULL)
  75. pcr->Release();
  76. return hr;
  77. }