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.

221 lines
4.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: dienumdevicesobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "Direct.h"
  12. #include "dms.h"
  13. #include "dIEnumDevicesObj.h"
  14. #include "diDevInstObj.h"
  15. extern BSTR DINPUTGUIDtoBSTR(LPGUID pGuid);
  16. extern HRESULT DINPUTBSTRtoGUID(LPGUID pGuid,BSTR bstr);
  17. extern HRESULT FillRealActionFormat(DIACTIONFORMATW *real, DIACTIONFORMAT_CDESC *cover, SAFEARRAY **actionArray,long ActionCount );
  18. //dienumdevicesobj.cpp(105) : error C2664: 'EnumDevicesBySemantics' : cannot convert parameter 3 from
  19. //'int (struct DIDEVICEINSTANCEW *const ,struct IDirectInputDevice8W *,unsigned long,unsigned long,void *)' to
  20. // 'int (__stdcall *)(const struct DIDEVICEINSTANCEW *,struct IDirectInputDevice8W *,unsigned long,unsigned long,void *)'
  21. //CALLBACK
  22. /////////////////////////////////////////////////////////////////////////////
  23. //extern "C"
  24. BOOL _stdcall objEnumInputDevicesCallback(
  25. const struct DIDEVICEINSTANCEW * lpddi,
  26. //IDirectInputDevice8W *pDev,
  27. //unsigned long UnknownVar1,
  28. //unsigned long UnknownVar2,
  29. LPVOID lpArg
  30. )
  31. {
  32. DPF(1,"Entered objEnumInputDevicesCallback\r\n");
  33. if (!lpddi) return FALSE;
  34. C_dxj_DIEnumDevicesObject *pObj=(C_dxj_DIEnumDevicesObject*)lpArg;
  35. if (pObj==NULL) return FALSE;
  36. if (pObj->m_nCount >= pObj->m_nMax)
  37. {
  38. pObj->m_nMax += 10;
  39. if (pObj->m_pList){
  40. pObj->m_pList=(DIDEVICEINSTANCEW*)realloc(pObj->m_pList,sizeof(DIDEVICEINSTANCEW)* pObj->m_nMax);
  41. }
  42. else {
  43. pObj->m_pList=(DIDEVICEINSTANCEW*)malloc( sizeof(DIDEVICEINSTANCEW)* pObj->m_nMax);
  44. }
  45. if (pObj->m_pList==NULL)
  46. {
  47. pObj->m_bProblem=TRUE;
  48. return FALSE;
  49. }
  50. }
  51. memcpy(&(pObj->m_pList[pObj->m_nCount]),lpddi,sizeof(DIDEVICEINSTANCEW));
  52. pObj->m_nCount++;
  53. return TRUE;
  54. }
  55. BOOL _stdcall objEnumInputDevicesBySemanticsCallback(
  56. const struct DIDEVICEINSTANCEW * lpddi,
  57. IDirectInputDevice8W *pDev,
  58. unsigned long UnknownVar1,
  59. unsigned long UnknownVar2,
  60. LPVOID lpArg
  61. )
  62. {
  63. DPF(1,"Entered objEnumInputDevicesCallback\r\n");
  64. if (!lpddi) return FALSE;
  65. C_dxj_DIEnumDevicesObject *pObj=(C_dxj_DIEnumDevicesObject*)lpArg;
  66. if (pObj==NULL) return FALSE;
  67. if (pObj->m_nCount >= pObj->m_nMax)
  68. {
  69. pObj->m_nMax += 10;
  70. if (pObj->m_pList){
  71. pObj->m_pList=(DIDEVICEINSTANCEW*)realloc(pObj->m_pList,sizeof(DIDEVICEINSTANCEW)* pObj->m_nMax);
  72. }
  73. else {
  74. pObj->m_pList=(DIDEVICEINSTANCEW*)malloc( sizeof(DIDEVICEINSTANCEW)* pObj->m_nMax);
  75. }
  76. if (pObj->m_pList==NULL)
  77. {
  78. pObj->m_bProblem=TRUE;
  79. return FALSE;
  80. }
  81. }
  82. memcpy(&(pObj->m_pList[pObj->m_nCount]),lpddi,sizeof(DIDEVICEINSTANCEW));
  83. pObj->m_nCount++;
  84. return TRUE;
  85. }
  86. C_dxj_DIEnumDevicesObject::C_dxj_DIEnumDevicesObject()
  87. {
  88. m_nMax=0;
  89. m_pList=NULL;
  90. m_nCount=0;
  91. m_bProblem=FALSE;
  92. }
  93. C_dxj_DIEnumDevicesObject::~C_dxj_DIEnumDevicesObject()
  94. {
  95. //empty list
  96. if (m_pList) free(m_pList);
  97. }
  98. HRESULT C_dxj_DIEnumDevicesObject::createSuitable(LPDIRECTINPUT8W pDI,BSTR str1, DIACTIONFORMAT_CDESC *format, long actionCount,SAFEARRAY **actionArray,long flags, I_dxj_DIEnumDevices8 **ppRet)
  99. {
  100. HRESULT hr;
  101. DIACTIONFORMATW frmt;
  102. C_dxj_DIEnumDevicesObject *pNew=NULL;
  103. *ppRet=NULL;
  104. pNew= new CComObject<C_dxj_DIEnumDevicesObject>;
  105. if (!pNew) return E_OUTOFMEMORY;
  106. pNew->m_bProblem=FALSE;
  107. hr=FillRealActionFormat(&frmt, format, actionArray,actionCount );
  108. if FAILED(hr) return hr;
  109. hr=pDI->EnumDevicesBySemantics((LPWSTR)str1,&frmt, objEnumInputDevicesBySemanticsCallback,pNew,(DWORD)flags);
  110. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  111. if FAILED(hr)
  112. {
  113. if (pNew->m_pList) free(pNew->m_pList);
  114. delete pNew;
  115. return hr;
  116. }
  117. hr=pNew->QueryInterface(IID_I_dxj_DIEnumDevices8,(void**)ppRet);
  118. return hr;
  119. }
  120. HRESULT C_dxj_DIEnumDevicesObject::create(LPDIRECTINPUT8W pDI,long deviceType, long flags,I_dxj_DIEnumDevices8 **ppRet)
  121. {
  122. HRESULT hr;
  123. C_dxj_DIEnumDevicesObject *pNew=NULL;
  124. *ppRet=NULL;
  125. pNew= new CComObject<C_dxj_DIEnumDevicesObject>;
  126. if (!pNew) return E_OUTOFMEMORY;
  127. pNew->m_bProblem=FALSE;
  128. hr = pDI->EnumDevices((DWORD)deviceType,
  129. objEnumInputDevicesCallback,
  130. (void*)pNew,
  131. (DWORD) flags);
  132. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  133. if FAILED(hr)
  134. {
  135. if (pNew->m_pList) free(pNew->m_pList);
  136. delete pNew;
  137. return hr;
  138. }
  139. hr=pNew->QueryInterface(IID_I_dxj_DIEnumDevices8,(void**)ppRet);
  140. return hr;
  141. }
  142. HRESULT C_dxj_DIEnumDevicesObject::getItem( long index, I_dxj_DirectInputDeviceInstance8 **ret)
  143. {
  144. if (m_pList==NULL) return E_FAIL;
  145. if (index < 1) return E_INVALIDARG;
  146. if (index > m_nCount) return E_INVALIDARG;
  147. HRESULT hr;
  148. hr=C_dxj_DIDeviceInstance8Object::create(&m_pList[index-1],ret);
  149. return hr;
  150. }
  151. HRESULT C_dxj_DIEnumDevicesObject::getCount(long *retVal)
  152. {
  153. *retVal=m_nCount;
  154. return S_OK;
  155. }