home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / graphics / video / aviview / regobjs.cpp < prev    next >
C/C++ Source or Header  |  1997-10-05  |  3KB  |  167 lines

  1. /**************************************************************************
  2.  *
  3.  *  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4.  *  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5.  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6.  *  PURPOSE.
  7.  *
  8.  *  Copyright (C) 1993 - 1997  Microsoft Corporation.  All Rights Reserved.
  9.  *
  10.  **************************************************************************/
  11.  
  12. #define INC_OLE2
  13. #include <windows.h>
  14. #include <windowsx.h>
  15. #include <mmsystem.h>
  16. #ifndef WIN32
  17. #include <ole2.h>
  18. #endif
  19. #include <string.h>
  20. #include <vfw.h>
  21. #include "aviview.h"
  22. #include "regobjs.h"
  23.  
  24. /*
  25. ** The usage counter keeps track of the overall usage of objects based on
  26. ** implementations provided by the component. This allows one to determine
  27. ** when the implementation is no longer in use.
  28. */
  29.  
  30. UINT    uUseCount;
  31. BOOL    fLocked;
  32.  
  33.  
  34. IClassFactory FAR * gpCF;
  35. DWORD            gdwRegistered;
  36.  
  37. extern "C" BOOL RegisterObjects(void);
  38. extern "C" void RevokeObjects(void);
  39.  
  40. BOOL RegisterObjects(void)
  41. {
  42. #if 0
  43.     HRESULT hresult;
  44. #endif
  45.  
  46.     // OleInitialize(NULL);
  47. #if 0
  48.     CAppCF::MakeInst(CLSID_ACMCmprsStream, IID_IClassFactory,
  49.            (void FAR * FAR *) &gpCF);
  50.  
  51.     hresult = CoRegisterClassObject(CLSID_ACMCmprsStream,
  52.               gpCF,
  53.               CLSCTX_INPROC_SERVER,
  54.               REGCLS_MULTIPLEUSE,
  55.               &gdwRegistered);
  56.     if (FAILED(GetScode(hresult))) {
  57.     delete gpCF;
  58.     gpCF = NULL;
  59.     return FALSE;
  60.     }
  61. #endif
  62.     
  63.     return TRUE;
  64. }
  65.  
  66. void RevokeObjects(void)
  67. {
  68. #if 0
  69.     CoRevokeClassObject(gdwRegistered);
  70. #endif
  71.  
  72.     // OleUninitialize();
  73. }
  74. /*    -    -    -    -    -    -    -    -    */
  75.  
  76. HRESULT CAppCF::MakeInst(
  77.     const CLSID FAR&    rclsid,
  78.     const IID FAR&    riid,
  79.     void FAR* FAR*    ppv)
  80. {
  81.     CAppCF FAR*    pAppCF;
  82.     IUnknown FAR*    pUnknown;
  83.     HRESULT hresult;
  84.  
  85.     pAppCF = new FAR CAppCF(rclsid, &pUnknown);
  86.     if (pAppCF == NULL)
  87.         return ResultFromScode(E_OUTOFMEMORY);
  88.     hresult = pUnknown->QueryInterface(riid, ppv);
  89.     if (FAILED(GetScode(hresult)))
  90.         delete pAppCF;
  91.     return hresult;
  92. }
  93.  
  94. /*    -    -    -    -    -    -    -    -    */
  95.  
  96. CAppCF::CAppCF(
  97.     const CLSID FAR&    rclsid,
  98.     IUnknown FAR* FAR*    ppUnknown)
  99. {
  100.     m_clsid = rclsid;
  101.     m_refs = 0;
  102.     *ppUnknown = this;
  103. }
  104.  
  105. /*    -    -    -    -    -    -    -    -    */
  106.  
  107. STDMETHODIMP CAppCF::QueryInterface(
  108.     const IID FAR&    iid,
  109.     void FAR* FAR*    ppv)
  110. {
  111.     if (iid == IID_IUnknown)
  112.         *ppv = this;
  113.     else if (iid == IID_IClassFactory)
  114.         *ppv = this;
  115.     else
  116.         return ResultFromScode(E_NOINTERFACE);
  117.     AddRef();
  118.     return NULL;
  119. }
  120.  
  121. /*    -    -    -    -    -    -    -    -    */
  122.  
  123. STDMETHODIMP_(ULONG) CAppCF::AddRef()
  124. {
  125.     return ++m_refs;
  126. }
  127.  
  128. /*    -    -    -    -    -    -    -    -    */
  129.  
  130. STDMETHODIMP_(ULONG) CAppCF::Release()
  131. {
  132.     if (!--m_refs) {
  133.         delete this;
  134.         return 0;
  135.     }
  136.     return m_refs;
  137. }
  138.  
  139. /*    -    -    -    -    -    -    -    -    */
  140.  
  141. STDMETHODIMP CAppCF::CreateInstance(
  142.     IUnknown FAR*    pUnknownOuter,
  143.     const IID FAR&    riid,
  144.     void FAR* FAR*    ppv)
  145. {
  146. #if 0
  147.     if (IsEqualCLSID(m_clsid, CLSID_ACMCmprsStream)) {
  148.         return CACMCmpStream::MakeInst(pUnknownOuter, riid, ppv);
  149.     }
  150.     else
  151. #endif
  152.     {
  153.         return ResultFromScode(CO_E_CANTDETERMINECLASS); // !!!
  154.     }
  155. }
  156.  
  157. /*    -    -    -    -    -    -    -    -    */
  158.  
  159. STDMETHODIMP CAppCF::LockServer(
  160.     BOOL    fLock)
  161. {
  162.     fLocked = fLock;
  163.     return NULL;
  164. }
  165.  
  166. /*    -    -    -    -    -    -    -    -    */
  167.