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.

267 lines
7.4 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: dinput1obj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // dDrawColorControlObj.cpp : Implementation of CDirectApp and DLL registration.
  11. // DHF_DS entire file
  12. #include "stdafx.h"
  13. #include "Direct.h"
  14. #include "dms.h"
  15. #include "dInput1Obj.h"
  16. #include "dInputDeviceObj.h"
  17. #include "dinput.h"
  18. #include "DIEnumDevicesObj.h"
  19. extern HRESULT BSTRtoGUID(LPGUID,BSTR);
  20. extern HRESULT DINPUTBSTRtoGUID(LPGUID,BSTR);
  21. CONSTRUCTOR(_dxj_DirectInput8, {});
  22. DESTRUCTOR(_dxj_DirectInput8, {});
  23. GETSET_OBJECT(_dxj_DirectInput8);
  24. HRESULT FillRealActionFormat(DIACTIONFORMATW *real, DIACTIONFORMAT_CDESC *cover, SAFEARRAY **actionArray,long ActionCount );
  25. STDMETHODIMP C_dxj_DirectInput8Object::createDevice(BSTR strGuid, I_dxj_DirectInputDevice8 **dev)
  26. {
  27. HRESULT hr = S_OK;
  28. GUID rguid;
  29. LPDIRECTINPUTDEVICE8W realdevice=NULL;
  30. hr = DINPUTBSTRtoGUID(&rguid,strGuid);
  31. if FAILED(hr) return hr;
  32. hr=m__dxj_DirectInput8->CreateDevice(rguid,&realdevice,NULL);
  33. if FAILED(hr) return hr;
  34. INTERNAL_CREATE(_dxj_DirectInputDevice8,realdevice,dev);
  35. if (*dev==NULL) {
  36. realdevice->Release();
  37. return E_OUTOFMEMORY;
  38. }
  39. if (0==_wcsicmp(strGuid,L"guid_syskeyboard")){
  40. hr=realdevice->SetDataFormat(&c_dfDIKeyboard);
  41. }
  42. else if (0==_wcsicmp(strGuid,L"guid_sysmouse")){
  43. hr=realdevice->SetDataFormat(&c_dfDIMouse);
  44. }
  45. else {
  46. hr=realdevice->SetDataFormat(&c_dfDIJoystick2);
  47. }
  48. return hr;
  49. }
  50. #ifdef _WIN64
  51. STDMETHODIMP C_dxj_DirectInput8Object::RunControlPanel( HWND hwndOwner )
  52. #else
  53. STDMETHODIMP C_dxj_DirectInput8Object::RunControlPanel( long hwndOwner )
  54. #endif
  55. {
  56. HRESULT hr;
  57. hr = m__dxj_DirectInput8->RunControlPanel((HWND)hwndOwner, (DWORD)0);
  58. return hr;
  59. }
  60. STDMETHODIMP C_dxj_DirectInput8Object::GetDeviceStatus( BSTR strGuid, VARIANT_BOOL *status){
  61. HRESULT hr;
  62. GUID g;
  63. hr = DINPUTBSTRtoGUID(&g,strGuid);
  64. if FAILED(hr) return hr;
  65. if (!status) return E_INVALIDARG;
  66. hr = m__dxj_DirectInput8->GetDeviceStatus((REFGUID)g);
  67. if (hr==DI_OK)
  68. *status=VARIANT_TRUE;
  69. else
  70. *status=VARIANT_FALSE;
  71. return S_OK;
  72. }
  73. STDMETHODIMP C_dxj_DirectInput8Object::getDIDevices(
  74. long deviceType, long flags, I_dxj_DIEnumDevices8 **ppRet)
  75. {
  76. HRESULT hr;
  77. hr = C_dxj_DIEnumDevicesObject::create(m__dxj_DirectInput8,deviceType,flags,ppRet);
  78. return hr;
  79. }
  80. STDMETHODIMP C_dxj_DirectInput8Object::getDevicesBySemantics(
  81. /* [in] */ BSTR str1,
  82. /* [in] */ DIACTIONFORMAT_CDESC __RPC_FAR *format,
  83. /* [in] */ long flags,
  84. /* [retval][out] */ I_dxj_DIEnumDevices8 __RPC_FAR *__RPC_FAR *ret)
  85. {
  86. HRESULT hr;
  87. hr = C_dxj_DIEnumDevicesObject::createSuitable(m__dxj_DirectInput8,str1,format,format->lActionCount,&format->ActionArray,flags,ret);
  88. return hr;
  89. }
  90. BOOL CALLBACK DIConfigureDevicesCallback(
  91. IUnknown FAR * lpDDSTarget,
  92. LPVOID pvRef
  93. )
  94. {
  95. HANDLE eventID=(HANDLE)pvRef;
  96. ::SetEvent((HANDLE)eventID); //CONSIDER 64 bit ramification of casting to a handle
  97. return TRUE;
  98. }
  99. STDMETHODIMP C_dxj_DirectInput8Object::ConfigureDevices (
  100. #ifdef _WIN64
  101. HANDLE hEvent,
  102. #else
  103. long hEvent,
  104. #endif
  105. DICONFIGUREDEVICESPARAMS_CDESC *CDParams,
  106. long flags
  107. )
  108. {
  109. HRESULT hr;
  110. BSTR bstr;
  111. long lElements;
  112. long i;
  113. DICONFIGUREDEVICESPARAMSW RealCDParams;
  114. if (CDParams->ActionFormats==0) return E_INVALIDARG;
  115. ZeroMemory(&RealCDParams,sizeof(DICONFIGUREDEVICESPARAMSW));
  116. RealCDParams.dwSize=sizeof(DICONFIGUREDEVICESPARAMSW);
  117. RealCDParams.dwcUsers=CDParams->UserCount;
  118. RealCDParams.dwcFormats=CDParams->FormatCount;
  119. RealCDParams.hwnd=(HWND)CDParams->hwnd;
  120. //CONSIDER if we need to ADDREF
  121. RealCDParams.lpUnkDDSTarget=CDParams->DDSTarget;
  122. memcpy(&RealCDParams.dics,&CDParams->dics,sizeof(DICOLORSET));
  123. lElements=(long)CDParams->UserNames->rgsabound[0].cElements;
  124. if (lElements==0){
  125. RealCDParams.lptszUserNames=NULL;
  126. }
  127. else {
  128. if (lElements < CDParams->UserCount) return E_INVALIDARG;
  129. DWORD dwMemSize=MAX_PATH*sizeof(WCHAR)*CDParams->UserCount;
  130. RealCDParams.lptszUserNames=(WCHAR*)malloc(dwMemSize);
  131. if (!RealCDParams.lptszUserNames) return E_OUTOFMEMORY;
  132. ZeroMemory(RealCDParams.lptszUserNames,dwMemSize);
  133. WCHAR *pCharbuff=RealCDParams.lptszUserNames;
  134. for (i=0;i<CDParams->UserCount;i++)
  135. {
  136. bstr=((BSTR*) (CDParams->UserNames->pvData))[i];
  137. if (bstr) wcscpy(pCharbuff,(WCHAR*)bstr);
  138. pCharbuff+=MAX_PATH; //advance 1024 wchars
  139. }
  140. }
  141. lElements=(long)CDParams->ActionFormats->rgsabound[0].cElements;
  142. if (lElements < CDParams->FormatCount) {
  143. if ( RealCDParams.lptszUserNames) free(RealCDParams.lptszUserNames);
  144. return E_INVALIDARG;
  145. }
  146. DIACTIONFORMATW *pRealActionFormats=(DIACTIONFORMATW*)malloc(CDParams->FormatCount*sizeof(DIACTIONFORMATW));
  147. if (!pRealActionFormats) {
  148. if ( RealCDParams.lptszUserNames) free(RealCDParams.lptszUserNames);
  149. return E_OUTOFMEMORY;
  150. }
  151. RealCDParams.lprgFormats=pRealActionFormats;
  152. DIACTIONFORMAT_CDESC *pCoverFormats=(DIACTIONFORMAT_CDESC *) (CDParams->ActionFormats->pvData);
  153. if (!pCoverFormats) {
  154. if (RealCDParams.lptszUserNames) free(RealCDParams.lptszUserNames);
  155. if (pRealActionFormats) free (pRealActionFormats);
  156. return E_INVALIDARG;
  157. }
  158. for (i=0;i<CDParams->FormatCount;i++)
  159. {
  160. FillRealActionFormat(
  161. &(pRealActionFormats[i]),
  162. &(pCoverFormats[i]),
  163. &(pCoverFormats[i].ActionArray),
  164. pCoverFormats[i].lActionCount);
  165. }
  166. if (hEvent)
  167. {
  168. hr = m__dxj_DirectInput8->ConfigureDevices(
  169. DIConfigureDevicesCallback,
  170. &RealCDParams,
  171. (DWORD)flags,
  172. (void*)hEvent);
  173. }
  174. else
  175. {
  176. hr = m__dxj_DirectInput8->ConfigureDevices(
  177. NULL,
  178. &RealCDParams,
  179. (DWORD)flags,
  180. NULL);
  181. }
  182. if ( RealCDParams.lptszUserNames) free(RealCDParams.lptszUserNames);
  183. //TODO make sure action format info is deallocated correctly
  184. if (pRealActionFormats) free (pRealActionFormats);
  185. return hr;
  186. }
  187. HRESULT FillRealActionFormat(DIACTIONFORMATW *real, DIACTIONFORMAT_CDESC *cover, SAFEARRAY **actionArray,long ActionCount )
  188. {
  189. HRESULT hr;
  190. ZeroMemory(real,sizeof(DIACTIONFORMATW));
  191. real->dwSize=sizeof(DIACTIONFORMATW);
  192. real->dwActionSize=sizeof(DIACTIONW);
  193. real->dwDataSize=(DWORD)ActionCount*sizeof(DWORD);
  194. real->dwGenre= (DWORD)cover->lGenre;
  195. real->lAxisMin= cover->lAxisMin;
  196. real->lAxisMax= cover->lAxisMax;
  197. real->dwBufferSize= (DWORD)cover->lBufferSize;
  198. real->dwNumActions=(DWORD)ActionCount;
  199. real->rgoAction= ((LPDIACTIONW) (*actionArray)->pvData);
  200. if (cover->ActionMapName)
  201. {
  202. wcscpy(real->tszActionMap,(WCHAR*)cover->ActionMapName);
  203. }
  204. hr=DINPUTBSTRtoGUID(&real->guidActionMap,cover->guidActionMap);
  205. if FAILED(hr) return hr;
  206. return S_OK;
  207. }