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.

169 lines
3.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: dienumdevicesobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #define DIRECTINPUT_VERSION 0x0500
  11. #include "stdafx.h"
  12. #include "Direct.h"
  13. #include "dms.h"
  14. #include "dIEnumDevicesObj.h"
  15. #include "diDevInstObj.h"
  16. extern BSTR GUIDtoBSTR(LPGUID pGuid);
  17. extern HRESULT BSTRtoGUID(LPGUID pGuid,BSTR bstr);
  18. /////////////////////////////////////////////////////////////////////////////
  19. extern "C" BOOL CALLBACK objEnumInputDevicesCallback(
  20. LPDIDEVICEINSTANCE lpddi,
  21. LPVOID lpArg
  22. )
  23. {
  24. DPF(1,"Entered objEnumInputDevicesCallback\r\n");
  25. if (!lpddi) return FALSE;
  26. C_dxj_DIEnumDevicesObject *pObj=(C_dxj_DIEnumDevicesObject*)lpArg;
  27. if (pObj==NULL) return FALSE;
  28. if (pObj->m_nCount >= pObj->m_nMax)
  29. {
  30. pObj->m_nMax += 10;
  31. if (pObj->m_pList){
  32. pObj->m_pList=(DIDEVICEINSTANCE*)realloc(pObj->m_pList,sizeof(DIDEVICEINSTANCE)* pObj->m_nMax);
  33. }
  34. else {
  35. pObj->m_pList=(DIDEVICEINSTANCE*)malloc( sizeof(DIDEVICEINSTANCE)* 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]),lpddi,sizeof(DIDEVICEINSTANCE));
  44. pObj->m_nCount++;
  45. return TRUE;
  46. }
  47. C_dxj_DIEnumDevicesObject::C_dxj_DIEnumDevicesObject()
  48. {
  49. m_nMax=0;
  50. m_pList=NULL;
  51. m_nCount=0;
  52. m_bProblem=FALSE;
  53. }
  54. C_dxj_DIEnumDevicesObject::~C_dxj_DIEnumDevicesObject()
  55. {
  56. //empty list
  57. if (m_pList) free(m_pList);
  58. }
  59. HRESULT C_dxj_DIEnumDevicesObject::create(LPDIRECTINPUT pDI,long deviceType, long flags,I_dxj_DIEnumDevices **ppRet)
  60. {
  61. HRESULT hr;
  62. C_dxj_DIEnumDevicesObject *pNew=NULL;
  63. *ppRet=NULL;
  64. pNew= new CComObject<C_dxj_DIEnumDevicesObject>;
  65. if (!pNew) return E_OUTOFMEMORY;
  66. pNew->m_bProblem=FALSE;
  67. hr = pDI->EnumDevices((DWORD)deviceType,
  68. (LPDIENUMDEVICESCALLBACK)objEnumInputDevicesCallback,
  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_DIEnumDevices,(void**)ppRet);
  79. return hr;
  80. }
  81. HRESULT C_dxj_DIEnumDevicesObject::getItem( long index, I_dxj_DirectInputDeviceInstance **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. HRESULT hr;
  87. hr=C_dxj_DIDeviceInstanceObject::create(&m_pList[index-1],ret);
  88. return hr;
  89. }
  90. /* DEAD
  91. HRESULT C_dxj_DIEnumDevicesObject::getItem( long index, DIDeviceInstance *info)
  92. {
  93. if (m_pList==NULL) return E_FAIL;
  94. if (index < 0) return E_INVALIDARG;
  95. if (index >= m_nCount) return E_INVALIDARG;
  96. if (info->strGuidInstance) SysFreeString(info->strGuidInstance);
  97. if (info->strGuidProduct) SysFreeString(info->strGuidProduct);
  98. if (info->strGuidFFDriver) SysFreeString(info->strGuidFFDriver);
  99. info->strGuidInstance=GUIDtoBSTR(&((m_pList[index]).guidInstance));
  100. info->strGuidProduct=GUIDtoBSTR(&((m_pList[index]).guidProduct));
  101. info->strGuidFFDriver=GUIDtoBSTR(&((m_pList[index]).guidFFDriver));
  102. info->lDevType=(long)(m_pList[index]).dwDevType;
  103. info->nUsagePage=(short)(m_pList[index]).wUsagePage;
  104. info->nUsage=(short)(m_pList[index]).wUsage;
  105. USES_CONVERSION;
  106. if (info->strProductName)
  107. SysFreeString(info->strProductName);
  108. if (info->strInstanceName)
  109. SysFreeString(info->strInstanceName);
  110. info->strInstanceName=NULL;
  111. info->strProductName=NULL;
  112. if (m_pList[index].tszProductName)
  113. info->strProductName=T2BSTR(m_pList[index].tszProductName);
  114. if (m_pList[index].tszInstanceName)
  115. info->strInstanceName=T2BSTR(m_pList[index].tszInstanceName);
  116. return S_OK;
  117. }
  118. */
  119. HRESULT C_dxj_DIEnumDevicesObject::getCount(long *retVal)
  120. {
  121. *retVal=m_nCount;
  122. return S_OK;
  123. }