Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
4.0 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 2001 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: ClassFactory.cpp
  6. * Content: Base ClassFactory implementation
  7. *
  8. *
  9. * History:
  10. * Date By Reason
  11. * ==== == ======
  12. * 07/20/2001 masonb Created
  13. *
  14. ***************************************************************************/
  15. #include "dncmni.h"
  16. #include "fixedpool.h"
  17. #ifndef DPNBUILD_LIBINTERFACE
  18. // Globals
  19. extern CFixedPool g_fpClassFactories;
  20. #undef DPF_MODNAME
  21. #define DPF_MODNAME "DPCF_QueryInterface"
  22. STDMETHODIMP DPCF_QueryInterface(IClassFactory *pInterface, REFIID riid, LPVOID *ppv)
  23. {
  24. HRESULT hr = S_OK;
  25. DPFX(DPFPREP, 3,"Parameters: pInterface [0x%p], riid [0x%p], ppv [0x%p]", pInterface, riid, ppv);
  26. if (riid == IID_IUnknown)
  27. {
  28. DPFX(DPFPREP, 5,"riid = IID_IUnknown");
  29. *ppv = pInterface;
  30. pInterface->lpVtbl->AddRef( pInterface );
  31. }
  32. else if (riid == IID_IClassFactory)
  33. {
  34. DPFX(DPFPREP, 5,"riid = IID_IClassFactory");
  35. *ppv = pInterface;
  36. pInterface->lpVtbl->AddRef( pInterface );
  37. }
  38. else
  39. {
  40. DPFX(DPFPREP, 5,"riid not found !");
  41. *ppv = NULL;
  42. hr = E_NOINTERFACE;
  43. }
  44. DPFX(DPFPREP, 3,"Returning: hResultCode = [%lx], *ppv = [%p]", hr, *ppv);
  45. return hr;
  46. }
  47. #undef DPF_MODNAME
  48. #define DPF_MODNAME "DPCF_AddRef"
  49. STDMETHODIMP_(ULONG) DPCF_AddRef(IClassFactory *pInterface)
  50. {
  51. _IDirectPlayClassFactory* pDPClassFactory = (_IDirectPlayClassFactory*) pInterface;
  52. DPFX(DPFPREP, 3,"Parameters: pInterface [%p], New Ref Count[%d]", pInterface, pDPClassFactory->lRefCount + 1);
  53. return DNInterlockedIncrement( &pDPClassFactory->lRefCount );
  54. }
  55. #undef DPF_MODNAME
  56. #define DPF_MODNAME "DPCF_Release"
  57. STDMETHODIMP_(ULONG) DPCF_Release(IClassFactory *pInterface)
  58. {
  59. _IDirectPlayClassFactory* pDPClassFactory = (_IDirectPlayClassFactory*) pInterface;
  60. LONG lRefCount;
  61. DPFX(DPFPREP, 3,"Parameters: pInterface [%p], New Ref Count[%d]", pInterface, pDPClassFactory->lRefCount - 1);
  62. lRefCount = DNInterlockedDecrement( &pDPClassFactory->lRefCount );
  63. if( lRefCount == 0 )
  64. {
  65. DPFX(DPFPREP, 5,"Freeing class factory object: lpcfObj [%p]", pInterface);
  66. DNInterlockedDecrement(pDPClassFactory->plClassFacObjCount);
  67. g_fpClassFactories.Release(pDPClassFactory);
  68. }
  69. return lRefCount;
  70. }
  71. #undef DPF_MODNAME
  72. #define DPF_MODNAME "DPCF_LockServer"
  73. STDMETHODIMP DPCF_LockServer(IClassFactory *pInterface, BOOL fLock)
  74. {
  75. _IDirectPlayClassFactory* pDPClassFactory = (_IDirectPlayClassFactory*) pInterface;
  76. DPFX(DPFPREP, 3,"Parameters: lpv [%p], fLock [%lx]", pInterface, fLock);
  77. if (fLock)
  78. {
  79. DNInterlockedIncrement(pDPClassFactory->plClassFacObjCount);
  80. }
  81. else
  82. {
  83. DNInterlockedDecrement(pDPClassFactory->plClassFacObjCount);
  84. }
  85. return S_OK;
  86. }
  87. #undef DPF_MODNAME
  88. #define DPF_MODNAME "DPCFUtil_DllGetClassObject"
  89. HRESULT DPCFUtil_DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv, IClassFactoryVtbl* pVtbl, LONG* plClassFacObjCount)
  90. {
  91. HRESULT hr = S_OK;
  92. _PIDirectPlayClassFactory pClassFactory;
  93. DPFX(DPFPREP, 3,"Parameters: rclsid [%p], riid [%p], ppv [%p]", rclsid, riid, ppv);
  94. *ppv = NULL;
  95. // Allocate Class Factory object
  96. pClassFactory = (_IDirectPlayClassFactory*)g_fpClassFactories.Get();
  97. if (pClassFactory == NULL)
  98. {
  99. DPFERR("Out of memory allocating class factory");
  100. return E_OUTOFMEMORY;
  101. }
  102. DPFX(DPFPREP, 5,"pClassFactory = [%p]",pClassFactory);
  103. pClassFactory->lpVtbl = pVtbl;
  104. pClassFactory->lRefCount = 0;
  105. pClassFactory->clsid = rclsid;
  106. pClassFactory->plClassFacObjCount = plClassFacObjCount;
  107. // Query to find the interface
  108. hr = pClassFactory->lpVtbl->QueryInterface((IClassFactory*)pClassFactory, riid, ppv);
  109. if (hr != S_OK)
  110. {
  111. DPFERR("GetClassObject asked for unknown interface");
  112. DNFree(pClassFactory);
  113. }
  114. else
  115. {
  116. DNInterlockedIncrement(plClassFacObjCount);
  117. }
  118. DPFX(DPFPREP, 3,"Return: hr = [%lx], *ppv = [%p]", hr, *ppv);
  119. return hr;
  120. }
  121. #endif // ! DPNBUILD_LIBINTERFACE