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.

229 lines
5.2 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. void* tmp = realloc(pObj->m_pList,sizeof(DIDEVICEINSTANCEW)* pObj->m_nMax);
  41. if (tmp)
  42. pObj->m_pList=(DIDEVICEINSTANCEW*)tmp;
  43. else
  44. return FALSE;
  45. }
  46. else {
  47. pObj->m_pList=(DIDEVICEINSTANCEW*)malloc( sizeof(DIDEVICEINSTANCEW)* pObj->m_nMax);
  48. }
  49. if (pObj->m_pList==NULL)
  50. {
  51. pObj->m_bProblem=TRUE;
  52. return FALSE;
  53. }
  54. }
  55. memcpy(&(pObj->m_pList[pObj->m_nCount]),lpddi,sizeof(DIDEVICEINSTANCEW));
  56. pObj->m_nCount++;
  57. return TRUE;
  58. }
  59. BOOL _stdcall objEnumInputDevicesBySemanticsCallback(
  60. const struct DIDEVICEINSTANCEW * lpddi,
  61. IDirectInputDevice8W *pDev,
  62. unsigned long UnknownVar1,
  63. unsigned long UnknownVar2,
  64. LPVOID lpArg
  65. )
  66. {
  67. DPF(1,"Entered objEnumInputDevicesCallback\r\n");
  68. if (!lpddi) return FALSE;
  69. C_dxj_DIEnumDevicesObject *pObj=(C_dxj_DIEnumDevicesObject*)lpArg;
  70. if (pObj==NULL) return FALSE;
  71. if (pObj->m_nCount >= pObj->m_nMax)
  72. {
  73. pObj->m_nMax += 10;
  74. if (pObj->m_pList){
  75. void* tmp = realloc(pObj->m_pList,sizeof(DIDEVICEINSTANCEW)* pObj->m_nMax);
  76. if (tmp)
  77. pObj->m_pList=(DIDEVICEINSTANCEW*)tmp;
  78. else
  79. return FALSE;
  80. }
  81. else {
  82. pObj->m_pList=(DIDEVICEINSTANCEW*)malloc( sizeof(DIDEVICEINSTANCEW)* pObj->m_nMax);
  83. }
  84. if (pObj->m_pList==NULL)
  85. {
  86. pObj->m_bProblem=TRUE;
  87. return FALSE;
  88. }
  89. }
  90. memcpy(&(pObj->m_pList[pObj->m_nCount]),lpddi,sizeof(DIDEVICEINSTANCEW));
  91. pObj->m_nCount++;
  92. return TRUE;
  93. }
  94. C_dxj_DIEnumDevicesObject::C_dxj_DIEnumDevicesObject()
  95. {
  96. m_nMax=0;
  97. m_pList=NULL;
  98. m_nCount=0;
  99. m_bProblem=FALSE;
  100. }
  101. C_dxj_DIEnumDevicesObject::~C_dxj_DIEnumDevicesObject()
  102. {
  103. //empty list
  104. if (m_pList) free(m_pList);
  105. }
  106. HRESULT C_dxj_DIEnumDevicesObject::createSuitable(LPDIRECTINPUT8W pDI,BSTR str1, DIACTIONFORMAT_CDESC *format, long actionCount,SAFEARRAY **actionArray,long flags, I_dxj_DIEnumDevices8 **ppRet)
  107. {
  108. HRESULT hr;
  109. DIACTIONFORMATW frmt;
  110. C_dxj_DIEnumDevicesObject *pNew=NULL;
  111. *ppRet=NULL;
  112. pNew= new CComObject<C_dxj_DIEnumDevicesObject>;
  113. if (!pNew) return E_OUTOFMEMORY;
  114. pNew->m_bProblem=FALSE;
  115. hr=FillRealActionFormat(&frmt, format, actionArray,actionCount );
  116. if FAILED(hr) return hr;
  117. hr=pDI->EnumDevicesBySemantics((LPWSTR)str1,&frmt, objEnumInputDevicesBySemanticsCallback,pNew,(DWORD)flags);
  118. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  119. if FAILED(hr)
  120. {
  121. if (pNew->m_pList) free(pNew->m_pList);
  122. delete pNew;
  123. return hr;
  124. }
  125. hr=pNew->QueryInterface(IID_I_dxj_DIEnumDevices8,(void**)ppRet);
  126. return hr;
  127. }
  128. HRESULT C_dxj_DIEnumDevicesObject::create(LPDIRECTINPUT8W pDI,long deviceType, long flags,I_dxj_DIEnumDevices8 **ppRet)
  129. {
  130. HRESULT hr;
  131. C_dxj_DIEnumDevicesObject *pNew=NULL;
  132. *ppRet=NULL;
  133. pNew= new CComObject<C_dxj_DIEnumDevicesObject>;
  134. if (!pNew) return E_OUTOFMEMORY;
  135. pNew->m_bProblem=FALSE;
  136. hr = pDI->EnumDevices((DWORD)deviceType,
  137. objEnumInputDevicesCallback,
  138. (void*)pNew,
  139. (DWORD) flags);
  140. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  141. if FAILED(hr)
  142. {
  143. if (pNew->m_pList) free(pNew->m_pList);
  144. delete pNew;
  145. return hr;
  146. }
  147. hr=pNew->QueryInterface(IID_I_dxj_DIEnumDevices8,(void**)ppRet);
  148. return hr;
  149. }
  150. HRESULT C_dxj_DIEnumDevicesObject::getItem( long index, I_dxj_DirectInputDeviceInstance8 **ret)
  151. {
  152. if (m_pList==NULL) return E_FAIL;
  153. if (index < 1) return E_INVALIDARG;
  154. if (index > m_nCount) return E_INVALIDARG;
  155. HRESULT hr;
  156. hr=C_dxj_DIDeviceInstance8Object::create(&m_pList[index-1],ret);
  157. return hr;
  158. }
  159. HRESULT C_dxj_DIEnumDevicesObject::getCount(long *retVal)
  160. {
  161. *retVal=m_nCount;
  162. return S_OK;
  163. }