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.

81 lines
2.1 KiB

  1. #include "header.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+1);
  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. // Register this category as being "implemented" by the class.
  39. CATID rgcatid[1] ;
  40. rgcatid[0] = catid;
  41. hr = pcr->RegisterClassImplCategories(clsid, 1, rgcatid);
  42. }
  43. if (pcr != NULL)
  44. pcr->Release();
  45. return hr;
  46. }
  47. // Helper function to unregister a CLSID as belonging to a component category
  48. HRESULT UnRegisterCLSIDInCategory(REFCLSID clsid, CATID catid)
  49. {
  50. ICatRegister* pcr = NULL ;
  51. HRESULT hr = S_OK ;
  52. hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
  53. NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
  54. if (SUCCEEDED(hr)) {
  55. // Unregister this category as being "implemented" by the class.
  56. CATID rgcatid[1] ;
  57. rgcatid[0] = catid;
  58. hr = pcr->UnRegisterClassImplCategories(clsid, 1, rgcatid);
  59. }
  60. if (pcr != NULL)
  61. pcr->Release();
  62. return hr;
  63. }