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.

178 lines
5.6 KiB

  1. /****************************************************************************
  2. MODULE: SW_OBJEC.CPP
  3. Tab Settings: 5 9
  4. Copyright 1995, 1996, Microsoft Corporation, All Rights Reserved.
  5. PURPOSE: IUnknown Method(s) for DirectInputEffectDriver Class objects
  6. FUNCTIONS:
  7. Author(s): Name:
  8. ---------- ----------------
  9. MEA Manolito E. Adan
  10. Revision History:
  11. -----------------
  12. Version Date Author Comments
  13. ------- ------ ----- -------------------------------------------
  14. 1.0 06-Feb-97 MEA original, Based on SWForce
  15. 23-Feb-97 MEA Modified for DirectInput FF Device Driver
  16. 21-Mar-99 waltw Removed unreferenced CreateDirectInputEffectDriver
  17. 21-Mar-99 waltw Moved CJoltMidi initialization from
  18. CDirectInputEffectDriver::Init to
  19. CImpIDirectInputEffectDriver::DeviceID
  20. ****************************************************************************/
  21. #include "SW_objec.hpp"
  22. #include <crtdbg.h>
  23. //
  24. // External Data
  25. //
  26. #ifdef _DEBUG
  27. extern char g_cMsg[160];
  28. #endif
  29. extern HANDLE g_hSWFFDataMutex;
  30. // ****************************************************************************
  31. // *** --- Member functions for base class CDirectInputEffectDriver
  32. //
  33. // ****************************************************************************
  34. //
  35. // ----------------------------------------------------------------------------
  36. // Function: CDirectInputEffectDriver::CDirectInputEffectDriver
  37. // Purpose: Constructor(s)/Destructor for CDirectInputEffectDriver Object
  38. // Parameters: LPUNKNOWN pUnkOuter - Ptr to a controlling unknown.
  39. // PFNDESTROYED pfnDestroy - Call when object is destroyed.
  40. // Returns:
  41. // Algorithm:
  42. // ----------------------------------------------------------------------------
  43. CDirectInputEffectDriver::CDirectInputEffectDriver(LPUNKNOWN pUnkOuter, PFNDESTROYED pfnDestroy)
  44. {
  45. #ifdef _DEBUG
  46. _RPT0(_CRT_WARN, "CDirectInputEffectDriver::CDirectInputEffectDriver()\r\n");
  47. #endif
  48. m_cRef=0;
  49. m_pImpIDirectInputEffectDriver=NULL;
  50. m_pUnkOuter=pUnkOuter;
  51. m_pfnDestroy=pfnDestroy;
  52. return;
  53. }
  54. CDirectInputEffectDriver::~CDirectInputEffectDriver(void)
  55. {
  56. #ifdef _DEBUG
  57. _RPT0(_CRT_WARN, "CDirectInputEffectDriver::~CDirectInputEffectDriver()\r\n");
  58. #endif
  59. //Delete the interface implementations created in Init
  60. DeleteInterfaceImp(m_pImpIDirectInputEffectDriver);
  61. return;
  62. }
  63. // ----------------------------------------------------------------------------
  64. // Function: CDirectInputEffectDriver::Init
  65. // Purpose: Instantiates the interface implementations for this object.
  66. // Parameters: none
  67. //
  68. // Returns: BOOL - TRUE if initialization succeeds, FALSE otherwise.
  69. // Algorithm:
  70. //
  71. // Note:
  72. // Creating the interfaces means creating instances of
  73. // the interface implementation classes. The constructor
  74. // parameters is a pointer to CDirectInputEffectDriver that has the
  75. // IUnknown functions to which the interface implementations
  76. // delegate.
  77. //
  78. // ----------------------------------------------------------------------------
  79. BOOL CDirectInputEffectDriver::Init(void)
  80. {
  81. #ifdef _DEBUG
  82. _RPT0(_CRT_WARN, "CDirectInputEffectDriver::Init\n");
  83. #endif
  84. m_pImpIDirectInputEffectDriver=new CImpIDirectInputEffectDriver(this);
  85. if (NULL==m_pImpIDirectInputEffectDriver)
  86. return FALSE;
  87. return (TRUE);
  88. }
  89. // ----------------------------------------------------------------------------
  90. // Function: CDirectInputEffectDriver::QueryInterface
  91. // Purpose: Manages the interfaces for this object which supports the
  92. // IUnknown, and IDirectInputEffectDriver interfaces.
  93. //
  94. // Parameters: REFIID riid - REFIID of the interface to return.
  95. // PPVOID ppv - PPVOID in which to store the pointer.
  96. //
  97. //
  98. // Returns: HRESULT NOERROR on success, E_NOINTERFACE if the
  99. // interface is not supported.
  100. //
  101. // Algorithm:
  102. //
  103. // Note:
  104. // IUnknown comes from CDirectInputEffectDriver. Note that here and in
  105. // the lines below we do not need to explicitly typecast
  106. // the object pointers into interface pointers because
  107. // the vtables are identical. If we had additional virtual
  108. // member functions in the object, we would have to cast
  109. // in order to set the right vtable. This is demonstrated
  110. // in the multiple-inheritance version, CObject3.
  111. //
  112. // ----------------------------------------------------------------------------
  113. STDMETHODIMP CDirectInputEffectDriver::QueryInterface(REFIID riid, PPVOID ppv)
  114. {
  115. //Always NULL the out-parameters
  116. *ppv=NULL;
  117. if (IID_IUnknown==riid)
  118. *ppv=this;
  119. //Other interfaces come from interface implementations
  120. if (IID_IDirectInputEffectDriver==riid)
  121. *ppv=m_pImpIDirectInputEffectDriver;
  122. if (NULL==*ppv)
  123. return ResultFromScode(E_NOINTERFACE);
  124. //AddRef any interface we'll return.
  125. ((LPUNKNOWN)*ppv)->AddRef();
  126. return NOERROR;
  127. }
  128. // ----------------------------------------------------------------------------
  129. // Function: CDirectInputEffectDriver::AddRef and CDirectInputEffectDriver::Release
  130. // Purpose: Reference counting members. When Release sees a zero count
  131. // the object destroys itself.
  132. //
  133. // Parameters: none
  134. //
  135. // Returns: DWORD m_cRef value
  136. //
  137. // Algorithm:
  138. //
  139. // Note:
  140. //
  141. // ----------------------------------------------------------------------------
  142. DWORD CDirectInputEffectDriver::AddRef(void)
  143. {
  144. return ++m_cRef;
  145. }
  146. DWORD CDirectInputEffectDriver::Release(void)
  147. {
  148. if (0!=--m_cRef) return m_cRef;
  149. delete this;
  150. return 0;
  151. }