home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2001 July / VPR0107B.BIN / DRIVER / CANOPUS / MVR32 / mvr32.exe / data1.cab / Development_Kit / Vc / Samples / MvrCtrl / cathelp.cpp next >
C/C++ Source or Header  |  2001-02-09  |  3KB  |  96 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 "stdafx.h"
  16. #include <comcat.h>
  17.  
  18.  
  19. // Helper function to create a component category and associated description
  20. HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription)
  21. {
  22.     ICatRegister* pcr = NULL ;
  23.     HRESULT hr = S_OK ;
  24.  
  25.     hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, 
  26.             NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
  27.     if (FAILED(hr))
  28.         return hr;
  29.  
  30.     // Make sure the HKCR\Component Categories\{..catid...}
  31.     // key is registered
  32.     CATEGORYINFO catinfo;
  33.     catinfo.catid = catid;
  34.     catinfo.lcid = 0x0411; // japan
  35.  
  36.     // Make sure the provided description is not too long.
  37.     // Only copy the first 127 characters if it is
  38.     int len = wcslen(catDescription);
  39.     if (len>127)
  40.         len = 127;
  41.     wcsncpy(catinfo.szDescription, catDescription, len);
  42.     // Make sure the description is null terminated
  43.     catinfo.szDescription[len] = '\0';
  44.  
  45.     hr = pcr->RegisterCategories(1, &catinfo);
  46.     pcr->Release();
  47.  
  48.     return hr;
  49. }
  50.  
  51. // Helper function to register a CLSID as belonging to a component category
  52. HRESULT RegisterCLSIDInCategory(REFCLSID clsid, CATID catid)
  53. {
  54. // Register your component categories information.
  55.     ICatRegister* pcr = NULL ;
  56.     HRESULT hr = S_OK ;
  57.     hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, 
  58.             NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
  59.     if (SUCCEEDED(hr))
  60.     {
  61.        // Register this category as being "implemented" by
  62.        // the class.
  63.        CATID rgcatid[1] ;
  64.        rgcatid[0] = catid;
  65.        hr = pcr->RegisterClassImplCategories(clsid, 1, rgcatid);
  66.     }
  67.  
  68.     if (pcr != NULL)
  69.         pcr->Release();
  70.   
  71.     return hr;
  72. }
  73.  
  74. // Helper function to unregister a CLSID as belonging to a component category
  75. HRESULT UnRegisterCLSIDInCategory(REFCLSID clsid, CATID catid)
  76. {
  77.     ICatRegister* pcr = NULL ;
  78.     HRESULT hr = S_OK ;
  79.     hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, 
  80.             NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
  81.     if (SUCCEEDED(hr))
  82.     {
  83.        // Unregister this category as being "implemented" by
  84.        // the class.
  85.        CATID rgcatid[1] ;
  86.        rgcatid[0] = catid;
  87.        hr = pcr->UnRegisterClassImplCategories(clsid, 1, rgcatid);
  88.     }
  89.  
  90.     if (pcr != NULL)
  91.         pcr->Release();
  92.   
  93.     return hr;
  94. }
  95.  
  96.