FACTORY.CPP
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:5k
源码类别:

Windows编程

开发平台:

Visual C++

  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) 1992 - 1997 Microsoft Corporation.  All Rights Reserved.
  9.  *
  10.  **************************************************************************/
  11. #define _INC_OLE
  12. #include <windows.h>
  13. #include <windowsx.h>
  14. #include <mmsystem.h>
  15. #include <string.h>
  16. #include <ole2.h>
  17. #define INITGUID
  18. #include <initguid.h>
  19. // Bring in the external GUIDs we need....
  20. //DEFINE_OLEGUID(IID_IUnknown,            0x00000000L, 0, 0);
  21. //DEFINE_OLEGUID(IID_IClassFactory,       0x00000001L, 0, 0);
  22. //DEFINE_OLEGUID(IID_IMarshal,            0x00000003L, 0, 0);
  23. #include <vfw.h>
  24. #include "handler.h"
  25. HMODULE ghModule = NULL;        // global HMODULE/HINSTANCE for resource access
  26. /*      -       -       -       -       -       -       -       -       */
  27. EXTERN_C BOOL APIENTRY DllMain(HANDLE, DWORD, LPVOID);
  28. EXTERN_C BOOL APIENTRY DllMain(
  29. HANDLE hModule,
  30. DWORD dwReason,
  31. LPVOID lpReserved )
  32. {
  33.         switch( dwReason)
  34.         {
  35.                 case DLL_PROCESS_ATTACH:
  36.                         if(ghModule == NULL)
  37.                                 ghModule = (HMODULE)hModule;
  38.                         break;
  39.                 case DLL_THREAD_ATTACH:
  40.                         break;
  41.                 case DLL_THREAD_DETACH:
  42.                         break;
  43.                 case DLL_PROCESS_DETACH:
  44.                         break;
  45.         }
  46.         return TRUE;
  47. }
  48. /*      -       -       -       -       -       -       -       -       */
  49. EXTERN_C BOOL FAR PASCAL WEP(
  50.         BOOL    fSystemExit)
  51. {
  52.         return TRUE;
  53. }
  54. /*      -       -       -       -       -       -       -       -       */
  55. STDAPI DllCanUnloadNow(
  56.         void)
  57. {
  58.         return ResultFromScode((fLocked || uUseCount) ? S_FALSE : S_OK);
  59. }
  60. /*      -       -       -       -       -       -       -       -       */
  61. STDAPI DllGetClassObject(
  62.         const CLSID FAR&        rclsid,
  63.         const IID FAR&  riid,
  64.         void FAR* FAR*  ppv)
  65. {
  66.         HRESULT hresult;
  67.         hresult = CAVIFileCF::Create(rclsid, riid, ppv);
  68.         return hresult;
  69. }
  70. /*      -       -       -       -       -       -       -       -       */
  71. HRESULT CAVIFileCF::Create(
  72.         const CLSID FAR&        rclsid,
  73.         const IID FAR&  riid,
  74.         void FAR* FAR*  ppv)
  75. {
  76.         CAVIFileCF FAR* pAVIFileCF;
  77.         IUnknown FAR*   pUnknown;
  78.         HRESULT hresult;
  79.         pAVIFileCF = new FAR CAVIFileCF(rclsid, &pUnknown);
  80.         if (pAVIFileCF == NULL)
  81.                 return ResultFromScode(E_OUTOFMEMORY);
  82.         hresult = pUnknown->QueryInterface(riid, ppv);
  83.         if (FAILED(GetScode(hresult)))
  84.                 delete pAVIFileCF;
  85.         return hresult;
  86. }
  87. /*      -       -       -       -       -       -       -       -       */
  88. CAVIFileCF::CAVIFileCF(
  89.         const CLSID FAR&        rclsid,
  90.         IUnknown FAR* FAR*      ppUnknown)
  91. {
  92.         m_clsid = rclsid;
  93.         m_refs = 0;
  94.         *ppUnknown = this;
  95. }
  96. /*      -       -       -       -       -       -       -       -       */
  97. STDMETHODIMP CAVIFileCF::QueryInterface(
  98.         const IID FAR&  iid,
  99.         void FAR* FAR*  ppv)
  100. {
  101.         if (iid == IID_IUnknown)
  102.                 *ppv = this;
  103.         else if (iid == IID_IClassFactory)
  104.                 *ppv = this;
  105.         else
  106.                 return ResultFromScode(E_NOINTERFACE);
  107.         AddRef();
  108.         return NULL;
  109. }
  110. /*      -       -       -       -       -       -       -       -       */
  111. STDMETHODIMP_(ULONG) CAVIFileCF::AddRef()
  112. {
  113.         return ++m_refs;
  114. }
  115. /*      -       -       -       -       -       -       -       -       */
  116. STDMETHODIMP_(ULONG) CAVIFileCF::Release()
  117. {
  118.         if (!--m_refs) {
  119.                 delete this;
  120.                 return 0;
  121.         }
  122.         return m_refs;
  123. }
  124. /*      -       -       -       -       -       -       -       -       */
  125. STDMETHODIMP CAVIFileCF::CreateInstance(
  126.         IUnknown FAR*   pUnknownOuter,
  127.         const IID FAR&  riid,
  128.         void FAR* FAR*  ppv)
  129. {
  130.         HRESULT hresult;
  131.         // Actually create a real object using the CAVIFile class....
  132.         // !!! We should really make sure they're using IAVIFile or IMarshal!
  133.         if (m_clsid == CLSID_DIBSEQFileReader) {
  134.                 hresult = CAVIFile::Create(pUnknownOuter, riid, ppv);
  135.                 return hresult;
  136.         } else {
  137.                 return ResultFromScode(E_UNEXPECTED);
  138.         }
  139. }
  140. /*      -       -       -       -       -       -       -       -       */
  141. STDMETHODIMP CAVIFileCF::LockServer(
  142.         BOOL    fLock)
  143. {
  144.         fLocked = fLock;
  145.         return NULL;
  146. }
  147. /*      -       -       -       -       -       -       -       -       */