home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / activexcontrol / webimage / cathelp.cpp next >
C/C++ Source or Header  |  1997-10-09  |  3KB  |  94 lines

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