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.

171 lines
4.0 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. void* tmp = realloc(pObj->m_pList,sizeof(DIDEVICEOBJECTINSTANCE)* pObj->m_nMax);
  30. if (tmp)
  31. pObj->m_pList=(DIDEVICEOBJECTINSTANCE *)tmp;
  32. else
  33. return FALSE;
  34. }
  35. else {
  36. pObj->m_pList=(DIDEVICEOBJECTINSTANCE *)malloc(sizeof(DIDEVICEOBJECTINSTANCE)* pObj->m_nMax);
  37. }
  38. if (pObj->m_pList==NULL)
  39. {
  40. pObj->m_bProblem=TRUE;
  41. return FALSE;
  42. }
  43. }
  44. memcpy(&(pObj->m_pList[pObj->m_nCount]),lpddoi,sizeof(DIDEVICEOBJECTINSTANCE ));
  45. pObj->m_nCount++;
  46. return TRUE;
  47. }
  48. C_dxj_DIEnumDeviceObjectsObject::C_dxj_DIEnumDeviceObjectsObject()
  49. {
  50. m_nMax=0;
  51. m_pList=NULL;
  52. m_nCount=0;
  53. m_bProblem=FALSE;
  54. }
  55. C_dxj_DIEnumDeviceObjectsObject::~C_dxj_DIEnumDeviceObjectsObject()
  56. {
  57. //empty list
  58. if (m_pList) free(m_pList);
  59. }
  60. HRESULT C_dxj_DIEnumDeviceObjectsObject::create(LPDIRECTINPUTDEVICE pDI, long flags,I_dxj_DIEnumDeviceObjects **ppRet)
  61. {
  62. HRESULT hr;
  63. C_dxj_DIEnumDeviceObjectsObject *pNew=NULL;
  64. *ppRet=NULL;
  65. pNew= new CComObject<C_dxj_DIEnumDeviceObjectsObject>;
  66. if (!pNew) return E_OUTOFMEMORY;
  67. pNew->m_bProblem=FALSE;
  68. hr = pDI->EnumObjects(
  69. (LPDIENUMDEVICEOBJECTSCALLBACK )DIEnumDeviceObjectsProc,
  70. (void*)pNew,
  71. (DWORD) flags);
  72. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  73. if FAILED(hr)
  74. {
  75. if (pNew->m_pList) free(pNew->m_pList);
  76. delete pNew;
  77. return hr;
  78. }
  79. hr=pNew->QueryInterface(IID_I_dxj_DIEnumDeviceObjects,(void**)ppRet);
  80. return hr;
  81. }
  82. /* DEAD
  83. HRESULT C_dxj_DIEnumDeviceObjectsObject::getItem( long index, DIDeviceObjectInstance *instCover)
  84. {
  85. if (m_pList==NULL) return E_FAIL;
  86. if (index < 0) return E_INVALIDARG;
  87. if (index >= m_nCount) return E_INVALIDARG;
  88. //TODO - consider what is going on here carefully
  89. if (instCover->strGuidType) SysFreeString((BSTR)instCover->strGuidType);
  90. if (instCover->strName) SysFreeString((BSTR)instCover->strName);
  91. DIDEVICEOBJECTINSTANCE *inst=&m_pList[index];
  92. //TODO - consider localization
  93. if (inst->tszName){
  94. instCover->strName=T2BSTR(inst->tszName);
  95. }
  96. instCover->strGuidType=DINPUTGUIDtoBSTR(&inst->guidType);
  97. instCover->lOfs=inst->dwOfs;
  98. instCover->lType=inst->dwType;
  99. instCover->lFlags=inst->dwFlags;
  100. instCover->lFFMaxForce=inst->dwFFMaxForce;
  101. instCover->lFFForceResolution=inst->dwFFForceResolution;
  102. instCover->nCollectionNumber=inst->wCollectionNumber;
  103. instCover->nDesignatorIndex=inst->wDesignatorIndex;
  104. instCover->nUsagePage=inst->wUsagePage;
  105. instCover->nUsage=inst->wUsage;
  106. instCover->lDimension=inst->dwDimension;
  107. instCover->nExponent=inst->wExponent;
  108. instCover->nReserved=inst->wReserved;
  109. return S_OK;
  110. }
  111. */
  112. HRESULT C_dxj_DIEnumDeviceObjectsObject::getItem( long index, I_dxj_DirectInputDeviceObjectInstance **ret)
  113. {
  114. if (m_pList==NULL) return E_FAIL;
  115. if (index < 1) return E_INVALIDARG;
  116. if (index > m_nCount) return E_INVALIDARG;
  117. DIDEVICEOBJECTINSTANCE *inst=&m_pList[index-1];
  118. if (!inst) return E_INVALIDARG;
  119. HRESULT hr;
  120. hr=C_dxj_DIDeviceObjectInstanceObject::create(inst,ret);
  121. return hr;
  122. }
  123. HRESULT C_dxj_DIEnumDeviceObjectsObject::getCount(long *retVal)
  124. {
  125. *retVal=m_nCount;
  126. return S_OK;
  127. }