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.

159 lines
4.0 KiB

  1. /*****************************************************************************
  2. *
  3. * Clsfact.c
  4. *
  5. * Copyright (c) 1999 Microsoft Corporation. All Rights Reserved.
  6. *
  7. *
  8. * Abstract:
  9. *
  10. * Class factory.
  11. *
  12. *****************************************************************************/
  13. #include "PIDpr.h"
  14. /*****************************************************************************
  15. *
  16. * CClassFactory_AddRef
  17. *
  18. * Optimization: Since the class factory is static, reference
  19. * counting can be shunted to the DLL itself.
  20. *
  21. *****************************************************************************/
  22. STDMETHODIMP_(ULONG)
  23. CClassFactory_AddRef(IClassFactory *pcf)
  24. {
  25. return DllAddRef();
  26. }
  27. /*****************************************************************************
  28. *
  29. * CClassFactory_Release
  30. *
  31. * Optimization: Since the class factory is static, reference
  32. * counting can be shunted to the DLL itself.
  33. *
  34. *****************************************************************************/
  35. STDMETHODIMP_(ULONG)
  36. CClassFactory_Release(IClassFactory *pcf)
  37. {
  38. return DllRelease();
  39. }
  40. /*****************************************************************************
  41. *
  42. * CClassFactory_QueryInterface
  43. *
  44. * Our QI is very simple because we support no interfaces beyond
  45. * ourselves.
  46. *
  47. *****************************************************************************/
  48. STDMETHODIMP
  49. CClassFactory_QueryInterface(IClassFactory *pcf, REFIID riid, LPVOID *ppvOut)
  50. {
  51. HRESULT hres;
  52. if (IsEqualIID(riid, &IID_IUnknown) ||
  53. IsEqualIID(riid, &IID_IClassFactory)) {
  54. CClassFactory_AddRef(pcf);
  55. *ppvOut = pcf;
  56. hres = S_OK;
  57. } else {
  58. *ppvOut = 0;
  59. hres = E_NOINTERFACE;
  60. }
  61. return hres;
  62. }
  63. /*****************************************************************************
  64. *
  65. * CClassFactory_CreateInstance
  66. *
  67. * Create the effect driver object itself.
  68. *
  69. *****************************************************************************/
  70. STDMETHODIMP
  71. CClassFactory_CreateInstance(IClassFactory *pcf, IUnknown *punkOuter,
  72. REFIID riid, LPVOID *ppvObj)
  73. {
  74. HRESULT hres;
  75. if (punkOuter == 0) {
  76. hres = PID_New(riid, ppvObj);
  77. } else {
  78. /*
  79. * We don't support aggregation.
  80. */
  81. hres = CLASS_E_NOAGGREGATION;
  82. }
  83. return hres;
  84. }
  85. /*****************************************************************************
  86. *
  87. * CClassFactory_LockServer
  88. *
  89. *****************************************************************************/
  90. STDMETHODIMP
  91. CClassFactory_LockServer(IClassFactory *pcf, BOOL fLock)
  92. {
  93. if (fLock) {
  94. DllAddRef();
  95. } else {
  96. DllRelease();
  97. }
  98. return S_OK;
  99. }
  100. /*****************************************************************************
  101. *
  102. * The VTBL for our Class Factory
  103. *
  104. *****************************************************************************/
  105. IClassFactoryVtbl CClassFactory_Vtbl = {
  106. CClassFactory_QueryInterface,
  107. CClassFactory_AddRef,
  108. CClassFactory_Release,
  109. CClassFactory_CreateInstance,
  110. CClassFactory_LockServer,
  111. };
  112. /*****************************************************************************
  113. *
  114. * Our static class factory.
  115. *
  116. *****************************************************************************/
  117. IClassFactory g_cf = { &CClassFactory_Vtbl };
  118. /*****************************************************************************
  119. *
  120. * CClassFactory_New
  121. *
  122. *****************************************************************************/
  123. STDMETHODIMP
  124. CClassFactory_New(REFIID riid, LPVOID *ppvOut)
  125. {
  126. HRESULT hres;
  127. /*
  128. * Attempt to obtain the desired interface. QueryInterface
  129. * will do an AddRef if it succeeds.
  130. */
  131. hres = CClassFactory_QueryInterface(&g_cf, riid, ppvOut);
  132. return hres;
  133. }