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.

167 lines
3.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: dienumdeviceobjectsobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #define DIRECTINPUT_VERSION 0x0500
  11. #include "stdafx.h"
  12. #include "Direct.h"
  13. #include "dms.h"
  14. #include "DIEnumDeviceObjectsObj.h"
  15. #include "didevObjInstOBj.h"
  16. extern BSTR DINPUTGUIDtoBSTR(LPGUID pGuid);
  17. extern "C" BOOL CALLBACK DIEnumDeviceObjectsProc(
  18. LPCDIDEVICEOBJECTINSTANCE lpddoi,
  19. LPVOID lpArg
  20. )
  21. {
  22. if (!lpddoi) return FALSE;
  23. C_dxj_DIEnumDeviceObjectsObject *pObj=(C_dxj_DIEnumDeviceObjectsObject*)lpArg;
  24. if (pObj==NULL) return FALSE;
  25. if (pObj->m_nCount >= pObj->m_nMax)
  26. {
  27. pObj->m_nMax += 10;
  28. if (pObj->m_pList){
  29. pObj->m_pList=(DIDEVICEOBJECTINSTANCE *)realloc(pObj->m_pList,sizeof(DIDEVICEOBJECTINSTANCE)* pObj->m_nMax);
  30. }
  31. else {
  32. pObj->m_pList=(DIDEVICEOBJECTINSTANCE *)malloc(sizeof(DIDEVICEOBJECTINSTANCE)* pObj->m_nMax);
  33. }
  34. if (pObj->m_pList==NULL)
  35. {
  36. pObj->m_bProblem=TRUE;
  37. return FALSE;
  38. }
  39. }
  40. memcpy(&(pObj->m_pList[pObj->m_nCount]),lpddoi,sizeof(DIDEVICEOBJECTINSTANCE ));
  41. pObj->m_nCount++;
  42. return TRUE;
  43. }
  44. C_dxj_DIEnumDeviceObjectsObject::C_dxj_DIEnumDeviceObjectsObject()
  45. {
  46. m_nMax=0;
  47. m_pList=NULL;
  48. m_nCount=0;
  49. m_bProblem=FALSE;
  50. }
  51. C_dxj_DIEnumDeviceObjectsObject::~C_dxj_DIEnumDeviceObjectsObject()
  52. {
  53. //empty list
  54. if (m_pList) free(m_pList);
  55. }
  56. HRESULT C_dxj_DIEnumDeviceObjectsObject::create(LPDIRECTINPUTDEVICE pDI, long flags,I_dxj_DIEnumDeviceObjects **ppRet)
  57. {
  58. HRESULT hr;
  59. C_dxj_DIEnumDeviceObjectsObject *pNew=NULL;
  60. *ppRet=NULL;
  61. pNew= new CComObject<C_dxj_DIEnumDeviceObjectsObject>;
  62. if (!pNew) return E_OUTOFMEMORY;
  63. pNew->m_bProblem=FALSE;
  64. hr = pDI->EnumObjects(
  65. (LPDIENUMDEVICEOBJECTSCALLBACK )DIEnumDeviceObjectsProc,
  66. (void*)pNew,
  67. (DWORD) flags);
  68. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  69. if FAILED(hr)
  70. {
  71. if (pNew->m_pList) free(pNew->m_pList);
  72. delete pNew;
  73. return hr;
  74. }
  75. hr=pNew->QueryInterface(IID_I_dxj_DIEnumDeviceObjects,(void**)ppRet);
  76. return hr;
  77. }
  78. /* DEAD
  79. HRESULT C_dxj_DIEnumDeviceObjectsObject::getItem( long index, DIDeviceObjectInstance *instCover)
  80. {
  81. if (m_pList==NULL) return E_FAIL;
  82. if (index < 0) return E_INVALIDARG;
  83. if (index >= m_nCount) return E_INVALIDARG;
  84. //TODO - consider what is going on here carefully
  85. if (instCover->strGuidType) SysFreeString(instCover->strGuidType);
  86. if (instCover->strName) SysFreeString(instCover->strName);
  87. DIDEVICEOBJECTINSTANCE *inst=&m_pList[index];
  88. //TODO - consider localization
  89. if (inst->tszName){
  90. instCover->strName=T2BSTR(inst->tszName);
  91. }
  92. instCover->strGuidType=DINPUTGUIDtoBSTR(&inst->guidType);
  93. instCover->lOfs=inst->dwOfs;
  94. instCover->lType=inst->dwType;
  95. instCover->lFlags=inst->dwFlags;
  96. instCover->lFFMaxForce=inst->dwFFMaxForce;
  97. instCover->lFFForceResolution=inst->dwFFForceResolution;
  98. instCover->nCollectionNumber=inst->wCollectionNumber;
  99. instCover->nDesignatorIndex=inst->wDesignatorIndex;
  100. instCover->nUsagePage=inst->wUsagePage;
  101. instCover->nUsage=inst->wUsage;
  102. instCover->lDimension=inst->dwDimension;
  103. instCover->nExponent=inst->wExponent;
  104. instCover->nReserved=inst->wReserved;
  105. return S_OK;
  106. }
  107. */
  108. HRESULT C_dxj_DIEnumDeviceObjectsObject::getItem( long index, I_dxj_DirectInputDeviceObjectInstance **ret)
  109. {
  110. if (m_pList==NULL) return E_FAIL;
  111. if (index < 1) return E_INVALIDARG;
  112. if (index > m_nCount) return E_INVALIDARG;
  113. DIDEVICEOBJECTINSTANCE *inst=&m_pList[index-1];
  114. if (!inst) return E_INVALIDARG;
  115. HRESULT hr;
  116. hr=C_dxj_DIDeviceObjectInstanceObject::create(inst,ret);
  117. return hr;
  118. }
  119. HRESULT C_dxj_DIEnumDeviceObjectsObject::getCount(long *retVal)
  120. {
  121. *retVal=m_nCount;
  122. return S_OK;
  123. }