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.

191 lines
4.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: dienumeffectsobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "Direct.h"
  12. #include "dms.h"
  13. #include "dIEnumEffectsObj.h"
  14. extern BSTR DINPUTGUIDtoBSTR(LPGUID pGuid);
  15. extern HRESULT DINPUTBSTRtoGUID(LPGUID pGuid,BSTR bstr);
  16. ////////////////////////////////////////////////////////////////////////////
  17. /*extern "C"*/ BOOL CALLBACK objEnumInputEffectsCallback(
  18. LPCDIEFFECTINFOW pdei,
  19. LPVOID lpArg
  20. )
  21. {
  22. DPF(1,"Entered objEnumInputEffectsCallback\r\n");
  23. if (!pdei) return FALSE;
  24. C_dxj_DirectInputEnumEffectsObject *pObj=(C_dxj_DirectInputEnumEffectsObject*)lpArg;
  25. if (pObj==NULL) return FALSE;
  26. if (pObj->m_nCount >= pObj->m_nMax)
  27. {
  28. pObj->m_nMax += 10;
  29. if (pObj->m_pList){
  30. void* tmp = realloc(pObj->m_pList,sizeof(DIEFFECTINFOW)* pObj->m_nMax);
  31. if (tmp)
  32. pObj->m_pList=(DIEFFECTINFOW*)tmp;
  33. else
  34. return FALSE;
  35. }
  36. else {
  37. pObj->m_pList=(DIEFFECTINFOW*)malloc( sizeof(DIEFFECTINFOW)* pObj->m_nMax);
  38. }
  39. if (pObj->m_pList==NULL)
  40. {
  41. pObj->m_bProblem=TRUE;
  42. return FALSE;
  43. }
  44. }
  45. memcpy(&(pObj->m_pList[pObj->m_nCount]),pdei,sizeof(DIEFFECTINFOW));
  46. DPF1(1,"objEnumInputEffects '%s'\n",pdei->tszName);
  47. pObj->m_nCount++;
  48. return TRUE;
  49. }
  50. C_dxj_DirectInputEnumEffectsObject::C_dxj_DirectInputEnumEffectsObject()
  51. {
  52. m_nMax=0;
  53. m_pList=NULL;
  54. m_nCount=0;
  55. m_bProblem=FALSE;
  56. }
  57. C_dxj_DirectInputEnumEffectsObject::~C_dxj_DirectInputEnumEffectsObject()
  58. {
  59. //empty list
  60. if (m_pList) free(m_pList);
  61. }
  62. HRESULT C_dxj_DirectInputEnumEffectsObject::create(LPDIRECTINPUTDEVICE8W pDI,long effectType,I_dxj_DirectInputEnumEffects **ppRet)
  63. {
  64. HRESULT hr;
  65. C_dxj_DirectInputEnumEffectsObject *pNew=NULL;
  66. *ppRet=NULL;
  67. pNew= new CComObject<C_dxj_DirectInputEnumEffectsObject>;
  68. if (!pNew) return E_OUTOFMEMORY;
  69. pNew->m_bProblem=FALSE;
  70. hr = pDI->EnumEffects(
  71. objEnumInputEffectsCallback,
  72. (void*)pNew,
  73. (DWORD) effectType);
  74. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  75. if FAILED(hr)
  76. {
  77. if (pNew->m_pList) free(pNew->m_pList);
  78. pNew->m_pList=NULL;
  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=SysAllocString(m_pList[index-1].tszName); //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. }