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.

80 lines
2.3 KiB

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