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.

190 lines
3.9 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. void* tmp = realloc(pObj->m_pList,sizeof(DIEFFECTINFO)* pObj->m_nMax);
  32. if (tmp)
  33. pObj->m_pList=(DIEFFECTINFO*)tmp;
  34. else
  35. return FALSE;
  36. }
  37. else {
  38. pObj->m_pList=(DIEFFECTINFO*)malloc( sizeof(DIEFFECTINFO)* pObj->m_nMax);
  39. }
  40. if (pObj->m_pList==NULL)
  41. {
  42. pObj->m_bProblem=TRUE;
  43. return FALSE;
  44. }
  45. }
  46. memcpy(&(pObj->m_pList[pObj->m_nCount]),pdei,sizeof(DIEFFECTINFO));
  47. DPF1(1,"objEnumInputEffects '%s'\n",pdei->tszName);
  48. pObj->m_nCount++;
  49. return TRUE;
  50. }
  51. C_dxj_DirectInputEnumEffectsObject::C_dxj_DirectInputEnumEffectsObject()
  52. {
  53. m_nMax=0;
  54. m_pList=NULL;
  55. m_nCount=0;
  56. m_bProblem=FALSE;
  57. }
  58. C_dxj_DirectInputEnumEffectsObject::~C_dxj_DirectInputEnumEffectsObject()
  59. {
  60. //empty list
  61. if (m_pList) free(m_pList);
  62. }
  63. HRESULT C_dxj_DirectInputEnumEffectsObject::create(LPDIRECTINPUTDEVICE2 pDI,long effectType,I_dxj_DirectInputEnumEffects **ppRet)
  64. {
  65. HRESULT hr;
  66. C_dxj_DirectInputEnumEffectsObject *pNew=NULL;
  67. *ppRet=NULL;
  68. pNew= new CComObject<C_dxj_DirectInputEnumEffectsObject>;
  69. if (!pNew) return E_OUTOFMEMORY;
  70. pNew->m_bProblem=FALSE;
  71. hr = pDI->EnumEffects(
  72. objEnumInputEffectsCallback,
  73. (void*)pNew,
  74. (DWORD) effectType);
  75. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  76. if FAILED(hr)
  77. {
  78. if (pNew->m_pList) free(pNew->m_pList);
  79. delete pNew;
  80. return hr;
  81. }
  82. hr=pNew->QueryInterface(IID_I_dxj_DirectInputEnumEffects,(void**)ppRet);
  83. return hr;
  84. }
  85. HRESULT C_dxj_DirectInputEnumEffectsObject::getEffectGuid( long index, BSTR *ret)
  86. {
  87. if (m_pList==NULL) return E_FAIL;
  88. if (index < 1) return E_INVALIDARG;
  89. if (index > m_nCount) return E_INVALIDARG;
  90. *ret=DINPUTGUIDtoBSTR(&(m_pList[index-1].guid));
  91. return S_OK;
  92. }
  93. HRESULT C_dxj_DirectInputEnumEffectsObject::getName( long index, BSTR *ret)
  94. {
  95. if (m_pList==NULL) return E_FAIL;
  96. if (index < 1) return E_INVALIDARG;
  97. if (index > m_nCount) return E_INVALIDARG;
  98. USES_CONVERSION;
  99. *ret=T2BSTR(m_pList[index-1].tszName);
  100. return S_OK;
  101. }
  102. HRESULT C_dxj_DirectInputEnumEffectsObject::getType( long index, long *ret)
  103. {
  104. if (m_pList==NULL) return E_FAIL;
  105. if (index < 1) return E_INVALIDARG;
  106. if (index > m_nCount) return E_INVALIDARG;
  107. *ret=(long)m_pList[index-1].dwEffType;
  108. return S_OK;
  109. }
  110. HRESULT C_dxj_DirectInputEnumEffectsObject::getStaticParams( long index, long *ret)
  111. {
  112. if (m_pList==NULL) return E_FAIL;
  113. if (index < 1) return E_INVALIDARG;
  114. if (index > m_nCount) return E_INVALIDARG;
  115. *ret=(long)m_pList[index-1].dwStaticParams;
  116. return S_OK;
  117. }
  118. HRESULT C_dxj_DirectInputEnumEffectsObject::getDynamicParams( long index, long *ret)
  119. {
  120. if (m_pList==NULL) return E_FAIL;
  121. if (index < 1) return E_INVALIDARG;
  122. if (index > m_nCount) return E_INVALIDARG;
  123. *ret=(long)m_pList[index-1].dwDynamicParams;
  124. return S_OK;
  125. }
  126. HRESULT C_dxj_DirectInputEnumEffectsObject::getCount(long *retVal)
  127. {
  128. *retVal=m_nCount;
  129. return S_OK;
  130. }