home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / oleaut / browseh / browsecf.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-31  |  2.7 KB  |  123 lines

  1. /*************************************************************************
  2. **
  3. **  This is a part of the Microsoft Source Code Samples.
  4. **
  5. **  Copyright (C) 1992-1997 Microsoft Corporation. All rights reserved.
  6. **
  7. **  This source code is only intended as a supplement to Microsoft Development
  8. **  Tools and/or WinHelp documentation.  See these sources for detailed
  9. **  information regarding the Microsoft samples programs.
  10. **
  11. **  OLE Automation TypeLibrary Browse Helper Sample
  12. **
  13. **  BrowseHelpercf.cpp
  14. **
  15. **  CBrowseHelperCF (class factory) implementation
  16. **
  17. **  Written by Microsoft Product Support Services, Windows Developer Support
  18. **
  19. *************************************************************************/
  20. #include <windows.h>
  21. #include <windowsx.h>
  22. #ifdef WIN16   
  23.   #include <ole2.h>
  24.   #include <compobj.h>    
  25.   #include <dispatch.h> 
  26.   #include <variant.h>
  27.   #include <olenls.h>  
  28. #endif         
  29. #include "browseh.h" 
  30.  
  31. CBrowseHelperCF::CBrowseHelperCF(void)
  32. {    
  33.     m_cRef = 0; 
  34. }
  35.  
  36. /*
  37.  * CBrowseHelperCF::QueryInterface, AddRef, Release
  38.  *
  39.  * Purpose:
  40.  *  Implements IUnknown::QueryInterface, AddRef, Release
  41.  *
  42.  */
  43. STDMETHODIMP
  44. CBrowseHelperCF::QueryInterface(REFIID iid, void FAR* FAR* ppv) 
  45. {   
  46.     *ppv = NULL;
  47.     
  48.     if (iid == IID_IUnknown || iid == IID_IClassFactory)
  49.         *ppv = this;
  50.     else 
  51.         return E_NOINTERFACE; 
  52.  
  53.     AddRef();
  54.     return NOERROR;    
  55. }
  56.  
  57.  
  58. STDMETHODIMP_(ULONG)
  59. CBrowseHelperCF::AddRef(void)
  60. {
  61.     return ++m_cRef;
  62. }
  63.  
  64.  
  65. STDMETHODIMP_(ULONG)
  66. CBrowseHelperCF::Release(void)
  67. {   
  68.     if(--m_cRef == 0)
  69.     {
  70.         delete this;
  71.         return 0;
  72.     }
  73.     return m_cRef;
  74. }
  75.  
  76. /*
  77.  * CBrowseHelperCF::CreateInstance, LockServer
  78.  *
  79.  * Purpose:
  80.  *  Implements IClassFactory::CreateInstance, LockServer
  81.  *
  82.  */
  83. STDMETHODIMP
  84. CBrowseHelperCF::CreateInstance(IUnknown FAR* punkOuter,
  85.                          REFIID riid,
  86.                          void FAR* FAR* ppv)
  87. {    
  88.     CBrowseHelper FAR* pBrowseHelper;
  89.     HRESULT hr;
  90.     
  91.     *ppv = NULL;
  92.     
  93.     // This implementation does not allow aggregation
  94.     if (punkOuter)
  95.         return CLASS_E_NOAGGREGATION;
  96.  
  97.     // Create an instance of the BrowseHelper automation object. 
  98.     hr = CBrowseHelper::Create(&pBrowseHelper);       
  99.     if (FAILED(hr))
  100.         return hr;    
  101.              
  102.     hr = pBrowseHelper->QueryInterface(riid, ppv);
  103.     if (FAILED(hr)) 
  104.     {
  105.         delete pBrowseHelper;
  106.         return hr;
  107.     }  
  108.     return NOERROR;
  109. }
  110.  
  111. STDMETHODIMP
  112. CBrowseHelperCF::LockServer(BOOL fLock)
  113. {
  114.     extern ULONG g_cLock;
  115.     
  116.     if (fLock)
  117.         g_cLock++;
  118.     else
  119.         g_cLock--;
  120.  
  121.     return NOERROR;       
  122. }
  123.