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.

173 lines
4.0 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. void* tmp = realloc(pObj->m_pList,sizeof(DIDEVICEINSTANCE)* pObj->m_nMax);
  33. if (tmp)
  34. pObj->m_pList=(DIDEVICEINSTANCE*)tmp;
  35. else
  36. return FALSE;
  37. }
  38. else {
  39. pObj->m_pList=(DIDEVICEINSTANCE*)malloc( sizeof(DIDEVICEINSTANCE)* pObj->m_nMax);
  40. }
  41. if (pObj->m_pList==NULL)
  42. {
  43. pObj->m_bProblem=TRUE;
  44. return FALSE;
  45. }
  46. }
  47. memcpy(&(pObj->m_pList[pObj->m_nCount]),lpddi,sizeof(DIDEVICEINSTANCE));
  48. pObj->m_nCount++;
  49. return TRUE;
  50. }
  51. C_dxj_DIEnumDevicesObject::C_dxj_DIEnumDevicesObject()
  52. {
  53. m_nMax=0;
  54. m_pList=NULL;
  55. m_nCount=0;
  56. m_bProblem=FALSE;
  57. }
  58. C_dxj_DIEnumDevicesObject::~C_dxj_DIEnumDevicesObject()
  59. {
  60. //empty list
  61. if (m_pList) free(m_pList);
  62. }
  63. HRESULT C_dxj_DIEnumDevicesObject::create(LPDIRECTINPUT pDI,long deviceType, long flags,I_dxj_DIEnumDevices **ppRet)
  64. {
  65. HRESULT hr;
  66. C_dxj_DIEnumDevicesObject *pNew=NULL;
  67. *ppRet=NULL;
  68. pNew= new CComObject<C_dxj_DIEnumDevicesObject>;
  69. if (!pNew) return E_OUTOFMEMORY;
  70. pNew->m_bProblem=FALSE;
  71. hr = pDI->EnumDevices((DWORD)deviceType,
  72. (LPDIENUMDEVICESCALLBACK)objEnumInputDevicesCallback,
  73. (void*)pNew,
  74. (DWORD) flags);
  75. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  76. if FAILED(hr)
  77. {
  78. if (pNew->m_pList) free(pNew->m_pList);
  79. delete pNew;
  80. return hr;
  81. }
  82. hr=pNew->QueryInterface(IID_I_dxj_DIEnumDevices,(void**)ppRet);
  83. return hr;
  84. }
  85. HRESULT C_dxj_DIEnumDevicesObject::getItem( long index, I_dxj_DirectInputDeviceInstance **ret)
  86. {
  87. if (m_pList==NULL) return E_FAIL;
  88. if (index < 1) return E_INVALIDARG;
  89. if (index > m_nCount) return E_INVALIDARG;
  90. HRESULT hr;
  91. hr=C_dxj_DIDeviceInstanceObject::create(&m_pList[index-1],ret);
  92. return hr;
  93. }
  94. /* DEAD
  95. HRESULT C_dxj_DIEnumDevicesObject::getItem( long index, DIDeviceInstance *info)
  96. {
  97. if (m_pList==NULL) return E_FAIL;
  98. if (index < 0) return E_INVALIDARG;
  99. if (index >= m_nCount) return E_INVALIDARG;
  100. if (info->strGuidInstance) SysFreeString((BSTR)info->strGuidInstance);
  101. if (info->strGuidProduct) SysFreeString((BSTR)info->strGuidProduct);
  102. if (info->strGuidFFDriver) SysFreeString((BSTR)info->strGuidFFDriver);
  103. info->strGuidInstance=GUIDtoBSTR(&((m_pList[index]).guidInstance));
  104. info->strGuidProduct=GUIDtoBSTR(&((m_pList[index]).guidProduct));
  105. info->strGuidFFDriver=GUIDtoBSTR(&((m_pList[index]).guidFFDriver));
  106. info->lDevType=(long)(m_pList[index]).dwDevType;
  107. info->nUsagePage=(short)(m_pList[index]).wUsagePage;
  108. info->nUsage=(short)(m_pList[index]).wUsage;
  109. USES_CONVERSION;
  110. if (info->strProductName)
  111. SysFreeString((BSTR)info->strProductName);
  112. if (info->strInstanceName)
  113. SysFreeString((BSTR)info->strInstanceName);
  114. info->strInstanceName=NULL;
  115. info->strProductName=NULL;
  116. if (m_pList[index].tszProductName)
  117. info->strProductName=T2BSTR(m_pList[index].tszProductName);
  118. if (m_pList[index].tszInstanceName)
  119. info->strInstanceName=T2BSTR(m_pList[index].tszInstanceName);
  120. return S_OK;
  121. }
  122. */
  123. HRESULT C_dxj_DIEnumDevicesObject::getCount(long *retVal)
  124. {
  125. *retVal=m_nCount;
  126. return S_OK;
  127. }