Source code of Windows XP (NT5)
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.

199 lines
3.1 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1997 - 1999
  3. Module Name:
  4. cfacchng.cxx
  5. Abstract:
  6. Implements the Class Factory for the IOleCommandTarget implementation
  7. in SENS.
  8. Author:
  9. Gopal Parupudi <GopalP>
  10. Notes:
  11. This can be merged with the Class Factory implementation in cfacchng.?xx
  12. Revision History:
  13. GopalP 11/17/1997 Start.
  14. --*/
  15. #include <precomp.hxx>
  16. //
  17. // Global counts for the number of objects in the server and the number of
  18. // locks.
  19. //
  20. ULONG g_cCmdCFObj = 0L;
  21. ULONG g_cCmdCFLock = 0L;
  22. //
  23. // Constructor and Destructor
  24. //
  25. CIOleCommandTargetCF::CIOleCommandTargetCF(
  26. void
  27. ) : m_cRef(1L)
  28. {
  29. }
  30. CIOleCommandTargetCF::~CIOleCommandTargetCF(
  31. void
  32. )
  33. {
  34. // Empty Destructor.
  35. }
  36. //
  37. // QI
  38. //
  39. STDMETHODIMP
  40. CIOleCommandTargetCF::QueryInterface(
  41. REFIID riid,
  42. LPVOID *ppv
  43. )
  44. {
  45. HRESULT hr = S_OK;
  46. *ppv = NULL; // To handle failure cases
  47. // IUnknown or IClassFactory
  48. if (IsEqualIID(riid, IID_IUnknown) ||
  49. IsEqualIID(riid, IID_IClassFactory))
  50. {
  51. *ppv = (LPUNKNOWN) this;
  52. }
  53. else
  54. {
  55. hr = E_NOINTERFACE;
  56. }
  57. if (NULL != *ppv)
  58. {
  59. ((LPUNKNOWN)*ppv)->AddRef();
  60. }
  61. return hr;
  62. }
  63. //
  64. // AddRef
  65. //
  66. STDMETHODIMP_(ULONG)
  67. CIOleCommandTargetCF::AddRef(
  68. void
  69. )
  70. {
  71. return InterlockedIncrement((PLONG) &m_cRef);
  72. }
  73. //
  74. // Release
  75. //
  76. STDMETHODIMP_(ULONG)
  77. CIOleCommandTargetCF::Release(
  78. void
  79. )
  80. {
  81. ULONG cRefT;
  82. cRefT = InterlockedDecrement((PLONG) &m_cRef);
  83. if (0 == m_cRef)
  84. {
  85. // Invoke the callback function.
  86. delete this;
  87. }
  88. return cRefT;
  89. }
  90. //
  91. // CreateInstance
  92. //
  93. STDMETHODIMP
  94. CIOleCommandTargetCF::CreateInstance(
  95. LPUNKNOWN pUnkOuter,
  96. REFIID riid,
  97. LPVOID *ppvObj
  98. )
  99. {
  100. LPCIMPIOLECOMMANDTARGET pObjCommand;
  101. HRESULT hr;
  102. DebugTraceGuid("CIOleCommandTargetCF:CreateInstance()", riid);
  103. hr = E_OUTOFMEMORY;
  104. *ppvObj = NULL;
  105. pObjCommand = NULL;
  106. //
  107. // Return the appropriate interface pointer.
  108. //
  109. if (IsEqualIID(riid, IID_IOleCommandTarget) ||
  110. IsEqualIID(riid, IID_IUnknown))
  111. {
  112. SensPrintA(SENS_INFO, ("\t| ClassFactory::CreateInstance(IOleCommandTarget)\n"));
  113. pObjCommand = new CImpIOleCommandTarget();
  114. if (NULL != pObjCommand)
  115. {
  116. hr = pObjCommand->QueryInterface(riid, ppvObj);
  117. SensPrintA(SENS_INFO, ("\t| QI on CImpIOleCommandTarget returned 0x%x\n", hr));
  118. }
  119. }
  120. else
  121. {
  122. hr = E_NOINTERFACE;
  123. }
  124. if (NULL != *ppvObj)
  125. {
  126. InterlockedIncrement((PLONG) &g_cCmdCFObj);
  127. }
  128. SensPrintA(SENS_INFO, ("\t| Returning 0x%x from CF:CreateInstance\n", hr));
  129. return hr;
  130. }
  131. //
  132. // LockServer
  133. //
  134. STDMETHODIMP
  135. CIOleCommandTargetCF::LockServer(
  136. BOOL fLock
  137. )
  138. {
  139. if (fLock)
  140. {
  141. InterlockedIncrement((PLONG) &g_cCmdCFLock);
  142. }
  143. else
  144. {
  145. InterlockedDecrement((PLONG) &g_cCmdCFLock);
  146. InterlockedIncrement((PLONG) &g_cCmdCFObj);
  147. }
  148. return NOERROR;
  149. }