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.

186 lines
3.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: dienumeffectsobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #define DIRECTINPUT_VERSION 0x0500
  11. #include "stdafx.h"
  12. #include "Direct.h"
  13. #include "dms.h"
  14. #include "dIEnumEffectsObj.h"
  15. extern BSTR DINPUTGUIDtoBSTR(LPGUID pGuid);
  16. extern HRESULT DINPUTBSTRtoGUID(LPGUID pGuid,BSTR bstr);
  17. ////////////////////////////////////////////////////////////////////////////
  18. extern "C" BOOL CALLBACK objEnumInputEffectsCallback(
  19. LPCDIEFFECTINFO pdei,
  20. LPVOID lpArg
  21. )
  22. {
  23. DPF(1,"Entered objEnumInputEffectsCallback\r\n");
  24. if (!pdei) return FALSE;
  25. C_dxj_DirectInputEnumEffectsObject *pObj=(C_dxj_DirectInputEnumEffectsObject*)lpArg;
  26. if (pObj==NULL) return FALSE;
  27. if (pObj->m_nCount >= pObj->m_nMax)
  28. {
  29. pObj->m_nMax += 10;
  30. if (pObj->m_pList){
  31. pObj->m_pList=(DIEFFECTINFO*)realloc(pObj->m_pList,sizeof(DIEFFECTINFO)* pObj->m_nMax);
  32. }
  33. else {
  34. pObj->m_pList=(DIEFFECTINFO*)malloc( sizeof(DIEFFECTINFO)* pObj->m_nMax);
  35. }
  36. if (pObj->m_pList==NULL)
  37. {
  38. pObj->m_bProblem=TRUE;
  39. return FALSE;
  40. }
  41. }
  42. memcpy(&(pObj->m_pList[pObj->m_nCount]),pdei,sizeof(DIEFFECTINFO));
  43. DPF1(1,"objEnumInputEffects '%s'\n",pdei->tszName);
  44. pObj->m_nCount++;
  45. return TRUE;
  46. }
  47. C_dxj_DirectInputEnumEffectsObject::C_dxj_DirectInputEnumEffectsObject()
  48. {
  49. m_nMax=0;
  50. m_pList=NULL;
  51. m_nCount=0;
  52. m_bProblem=FALSE;
  53. }
  54. C_dxj_DirectInputEnumEffectsObject::~C_dxj_DirectInputEnumEffectsObject()
  55. {
  56. //empty list
  57. if (m_pList) free(m_pList);
  58. }
  59. HRESULT C_dxj_DirectInputEnumEffectsObject::create(LPDIRECTINPUTDEVICE2 pDI,long effectType,I_dxj_DirectInputEnumEffects **ppRet)
  60. {
  61. HRESULT hr;
  62. C_dxj_DirectInputEnumEffectsObject *pNew=NULL;
  63. *ppRet=NULL;
  64. pNew= new CComObject<C_dxj_DirectInputEnumEffectsObject>;
  65. if (!pNew) return E_OUTOFMEMORY;
  66. pNew->m_bProblem=FALSE;
  67. hr = pDI->EnumEffects(
  68. objEnumInputEffectsCallback,
  69. (void*)pNew,
  70. (DWORD) effectType);
  71. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  72. if FAILED(hr)
  73. {
  74. if (pNew->m_pList) free(pNew->m_pList);
  75. delete pNew;
  76. return hr;
  77. }
  78. hr=pNew->QueryInterface(IID_I_dxj_DirectInputEnumEffects,(void**)ppRet);
  79. return hr;
  80. }
  81. HRESULT C_dxj_DirectInputEnumEffectsObject::getEffectGuid( long index, BSTR *ret)
  82. {
  83. if (m_pList==NULL) return E_FAIL;
  84. if (index < 1) return E_INVALIDARG;
  85. if (index > m_nCount) return E_INVALIDARG;
  86. *ret=DINPUTGUIDtoBSTR(&(m_pList[index-1].guid));
  87. return S_OK;
  88. }
  89. HRESULT C_dxj_DirectInputEnumEffectsObject::getName( long index, BSTR *ret)
  90. {
  91. if (m_pList==NULL) return E_FAIL;
  92. if (index < 1) return E_INVALIDARG;
  93. if (index > m_nCount) return E_INVALIDARG;
  94. USES_CONVERSION;
  95. *ret=T2BSTR(m_pList[index-1].tszName);
  96. return S_OK;
  97. }
  98. HRESULT C_dxj_DirectInputEnumEffectsObject::getType( long index, long *ret)
  99. {
  100. if (m_pList==NULL) return E_FAIL;
  101. if (index < 1) return E_INVALIDARG;
  102. if (index > m_nCount) return E_INVALIDARG;
  103. *ret=(long)m_pList[index-1].dwEffType;
  104. return S_OK;
  105. }
  106. HRESULT C_dxj_DirectInputEnumEffectsObject::getStaticParams( long index, long *ret)
  107. {
  108. if (m_pList==NULL) return E_FAIL;
  109. if (index < 1) return E_INVALIDARG;
  110. if (index > m_nCount) return E_INVALIDARG;
  111. *ret=(long)m_pList[index-1].dwStaticParams;
  112. return S_OK;
  113. }
  114. HRESULT C_dxj_DirectInputEnumEffectsObject::getDynamicParams( long index, long *ret)
  115. {
  116. if (m_pList==NULL) return E_FAIL;
  117. if (index < 1) return E_INVALIDARG;
  118. if (index > m_nCount) return E_INVALIDARG;
  119. *ret=(long)m_pList[index-1].dwDynamicParams;
  120. return S_OK;
  121. }
  122. HRESULT C_dxj_DirectInputEnumEffectsObject::getCount(long *retVal)
  123. {
  124. *retVal=m_nCount;
  125. return S_OK;
  126. }