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.

132 lines
2.8 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. void* tmp = realloc(pObj->m_pList,sizeof(DIDEVICEOBJECTINSTANCEW)* pObj->m_nMax);
  29. if (tmp)
  30. pObj->m_pList=(DIDEVICEOBJECTINSTANCEW *)tmp;
  31. else
  32. return FALSE;
  33. }
  34. else {
  35. pObj->m_pList=(DIDEVICEOBJECTINSTANCEW *)malloc(sizeof(DIDEVICEOBJECTINSTANCEW)* pObj->m_nMax);
  36. }
  37. if (pObj->m_pList==NULL)
  38. {
  39. pObj->m_bProblem=TRUE;
  40. return FALSE;
  41. }
  42. }
  43. memcpy(&(pObj->m_pList[pObj->m_nCount]),lpddoi,sizeof(DIDEVICEOBJECTINSTANCEW));
  44. pObj->m_nCount++;
  45. return TRUE;
  46. }
  47. C_dxj_DIEnumDeviceObjectsObject::C_dxj_DIEnumDeviceObjectsObject()
  48. {
  49. m_nMax=0;
  50. m_pList=NULL;
  51. m_nCount=0;
  52. m_bProblem=FALSE;
  53. }
  54. C_dxj_DIEnumDeviceObjectsObject::~C_dxj_DIEnumDeviceObjectsObject()
  55. {
  56. //empty list
  57. if (m_pList) free(m_pList);
  58. }
  59. HRESULT C_dxj_DIEnumDeviceObjectsObject::create(LPDIRECTINPUTDEVICE8W pDI, long flags,I_dxj_DIEnumDeviceObjects **ppRet)
  60. {
  61. HRESULT hr;
  62. C_dxj_DIEnumDeviceObjectsObject *pNew=NULL;
  63. *ppRet=NULL;
  64. pNew= new CComObject<C_dxj_DIEnumDeviceObjectsObject>;
  65. if (!pNew) return E_OUTOFMEMORY;
  66. pNew->m_bProblem=FALSE;
  67. hr = pDI->EnumObjects(
  68. (LPDIENUMDEVICEOBJECTSCALLBACKW)DIEnumDeviceObjectsProc,
  69. (void*)pNew,
  70. (DWORD) flags);
  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_DIEnumDeviceObjects,(void**)ppRet);
  79. return hr;
  80. }
  81. HRESULT C_dxj_DIEnumDeviceObjectsObject::getItem( long index, I_dxj_DirectInputDeviceObjectInstance **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. DIDEVICEOBJECTINSTANCEW *inst=&m_pList[index-1];
  87. if (!inst) return E_INVALIDARG;
  88. HRESULT hr;
  89. hr=C_dxj_DIDeviceObjectInstanceObject::create(inst,ret);
  90. return hr;
  91. }
  92. HRESULT C_dxj_DIEnumDeviceObjectsObject::getCount(long *retVal)
  93. {
  94. *retVal=m_nCount;
  95. return S_OK;
  96. }