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.

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