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.

128 lines
2.6 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: dienumdeviceobjectsobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "Direct.h"
  12. #include "dms.h"
  13. #include "DIEnumDeviceObjectsObj.h"
  14. #include "didevObjInstOBj.h"
  15. extern BSTR DINPUTGUIDtoBSTR(LPGUID pGuid);
  16. extern "C" BOOL CALLBACK DIEnumDeviceObjectsProc(
  17. LPCDIDEVICEOBJECTINSTANCEW lpddoi,
  18. LPVOID lpArg
  19. )
  20. {
  21. if (!lpddoi) return FALSE;
  22. C_dxj_DIEnumDeviceObjectsObject *pObj=(C_dxj_DIEnumDeviceObjectsObject*)lpArg;
  23. if (pObj==NULL) return FALSE;
  24. if (pObj->m_nCount >= pObj->m_nMax)
  25. {
  26. pObj->m_nMax += 10;
  27. if (pObj->m_pList){
  28. pObj->m_pList=(DIDEVICEOBJECTINSTANCEW *)realloc(pObj->m_pList,sizeof(DIDEVICEOBJECTINSTANCEW)* pObj->m_nMax);
  29. }
  30. else {
  31. pObj->m_pList=(DIDEVICEOBJECTINSTANCEW *)malloc(sizeof(DIDEVICEOBJECTINSTANCEW)* pObj->m_nMax);
  32. }
  33. if (pObj->m_pList==NULL)
  34. {
  35. pObj->m_bProblem=TRUE;
  36. return FALSE;
  37. }
  38. }
  39. memcpy(&(pObj->m_pList[pObj->m_nCount]),lpddoi,sizeof(DIDEVICEOBJECTINSTANCEW));
  40. pObj->m_nCount++;
  41. return TRUE;
  42. }
  43. C_dxj_DIEnumDeviceObjectsObject::C_dxj_DIEnumDeviceObjectsObject()
  44. {
  45. m_nMax=0;
  46. m_pList=NULL;
  47. m_nCount=0;
  48. m_bProblem=FALSE;
  49. }
  50. C_dxj_DIEnumDeviceObjectsObject::~C_dxj_DIEnumDeviceObjectsObject()
  51. {
  52. //empty list
  53. if (m_pList) free(m_pList);
  54. }
  55. HRESULT C_dxj_DIEnumDeviceObjectsObject::create(LPDIRECTINPUTDEVICE8W pDI, long flags,I_dxj_DIEnumDeviceObjects **ppRet)
  56. {
  57. HRESULT hr;
  58. C_dxj_DIEnumDeviceObjectsObject *pNew=NULL;
  59. *ppRet=NULL;
  60. pNew= new CComObject<C_dxj_DIEnumDeviceObjectsObject>;
  61. if (!pNew) return E_OUTOFMEMORY;
  62. pNew->m_bProblem=FALSE;
  63. hr = pDI->EnumObjects(
  64. (LPDIENUMDEVICEOBJECTSCALLBACKW)DIEnumDeviceObjectsProc,
  65. (void*)pNew,
  66. (DWORD) flags);
  67. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  68. if FAILED(hr)
  69. {
  70. if (pNew->m_pList) free(pNew->m_pList);
  71. delete pNew;
  72. return hr;
  73. }
  74. hr=pNew->QueryInterface(IID_I_dxj_DIEnumDeviceObjects,(void**)ppRet);
  75. return hr;
  76. }
  77. HRESULT C_dxj_DIEnumDeviceObjectsObject::getItem( long index, I_dxj_DirectInputDeviceObjectInstance **ret)
  78. {
  79. if (m_pList==NULL) return E_FAIL;
  80. if (index < 1) return E_INVALIDARG;
  81. if (index > m_nCount) return E_INVALIDARG;
  82. DIDEVICEOBJECTINSTANCEW *inst=&m_pList[index-1];
  83. if (!inst) return E_INVALIDARG;
  84. HRESULT hr;
  85. hr=C_dxj_DIDeviceObjectInstanceObject::create(inst,ret);
  86. return hr;
  87. }
  88. HRESULT C_dxj_DIEnumDeviceObjectsObject::getCount(long *retVal)
  89. {
  90. *retVal=m_nCount;
  91. return S_OK;
  92. }