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.

131 lines
3.3 KiB

  1. /****************************************************************************/
  2. // factory.cpp
  3. //
  4. // TS Session Directory class factory code.
  5. //
  6. // Copyright (C) 2000 Microsoft Corporation
  7. /****************************************************************************/
  8. #include <windows.h>
  9. #include <ole2.h>
  10. #include <objbase.h>
  11. #include <comutil.h>
  12. #include <comdef.h>
  13. #include <adoid.h>
  14. #include <adoint.h>
  15. #include "tssdjet.h"
  16. #include "factory.h"
  17. #include "trace.h"
  18. extern long g_lObjects;
  19. extern long g_lLocks;
  20. /****************************************************************************/
  21. // CClassFactory::QueryInterface
  22. //
  23. // Standard COM IUnknown interface function.
  24. // Handles interface queries for the class factory only.
  25. /****************************************************************************/
  26. STDMETHODIMP CClassFactory::QueryInterface(REFIID riid, void **ppv)
  27. {
  28. if (riid == IID_IUnknown) {
  29. *ppv = (LPVOID)(IUnknown *)this;
  30. }
  31. else if(riid == IID_IClassFactory) {
  32. *ppv = (LPVOID)(IClassFactory *)this;
  33. }
  34. else {
  35. TRC2((TB,"ClassFactory: Unknown interface"));
  36. return E_NOINTERFACE;
  37. }
  38. ((IUnknown *)*ppv)->AddRef();
  39. return S_OK;
  40. }
  41. /****************************************************************************/
  42. // CClassFactory::AddRef
  43. //
  44. // Standard COM IUnknown function.
  45. /****************************************************************************/
  46. STDMETHODIMP_(ULONG) CClassFactory::AddRef()
  47. {
  48. return InterlockedIncrement(&m_RefCount);
  49. }
  50. /****************************************************************************/
  51. // CClassFactory::Release
  52. //
  53. // Standard COM IUnknown function.
  54. /****************************************************************************/
  55. STDMETHODIMP_(ULONG) CClassFactory::Release()
  56. {
  57. long Refs = InterlockedDecrement(&m_RefCount);
  58. if (Refs == 0)
  59. delete this;
  60. return Refs;
  61. }
  62. /****************************************************************************/
  63. // CClassFactory::CreateInstance
  64. //
  65. // IClassFactory creator function.
  66. /****************************************************************************/
  67. STDMETHODIMP CClassFactory::CreateInstance(
  68. IN IUnknown *pUnknownOuter,
  69. IN REFIID iid,
  70. OUT LPVOID *ppv)
  71. {
  72. HRESULT hr;
  73. CTSSessionDirectory *pTSSDI = NULL;
  74. *ppv = NULL;
  75. TRC2((TB,"ClassFactory::CreateInstance"));
  76. // We do not support aggregation
  77. if (pUnknownOuter != NULL)
  78. return CLASS_E_NOAGGREGATION;
  79. // Create the provider object
  80. pTSSDI = new CTSSessionDirectory;
  81. if (pTSSDI != NULL) {
  82. // Retrieve the requested interface.
  83. hr = pTSSDI->QueryInterface(iid, ppv);
  84. if (!FAILED(hr)) {
  85. return S_OK;
  86. }
  87. else {
  88. delete pTSSDI;
  89. return hr;
  90. }
  91. }
  92. else {
  93. return E_OUTOFMEMORY;
  94. }
  95. }
  96. /****************************************************************************/
  97. // CClassFactory::LockServer
  98. //
  99. // IClassFactory lock function.
  100. /****************************************************************************/
  101. STDMETHODIMP CClassFactory::LockServer(IN BOOL bLock)
  102. {
  103. if (bLock)
  104. InterlockedIncrement(&g_lLocks);
  105. else
  106. InterlockedDecrement(&g_lLocks);
  107. return S_OK;
  108. }