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.

693 lines
19 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: dinputdeviceobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #define DIRECTINPUT_VERSION 0x0500
  11. // dDrawColorControlObj.cpp : Implementation of CDirectApp and DLL registration.
  12. // DHF_DS entire file
  13. #include "stdafx.h"
  14. #include "Direct.h"
  15. #include "dms.h"
  16. #include "dienumDeviceObjectsObj.h"
  17. #include "dIEnumEffectsObj.h"
  18. #include "dInputdeviceObj.h"
  19. #include "dInputEffectObj.h"
  20. #include "didevInstObj.h"
  21. #include "didevObjInstObj.h"
  22. //TODO move to typlib enum
  23. #define dfDIKeyboard 1
  24. #define dfDIMouse 2
  25. #define dfDIJoystick 3
  26. #define dfDIJoystick2 4
  27. extern HRESULT FixUpCoverEffect(GUID g, DIEffect *cover,DIEFFECT *realEffect);
  28. extern HRESULT FixUpRealEffect(GUID g,DIEFFECT *realEffect,DIEffect *cover);
  29. extern HRESULT DINPUTBSTRtoGUID(LPGUID pGuid,BSTR str);
  30. extern BSTR DINPUTGUIDtoBSTR(LPGUID pg);
  31. HRESULT C_dxj_DirectInputDeviceObject::init()
  32. {
  33. nFormat=0;
  34. return S_OK;
  35. }
  36. HRESULT C_dxj_DirectInputDeviceObject::cleanup()
  37. {
  38. return S_OK;
  39. }
  40. CONSTRUCTOR(_dxj_DirectInputDevice, {init();});
  41. DESTRUCTOR(_dxj_DirectInputDevice, {cleanup();});
  42. //NOTE get set for Device object
  43. // must use QI to get at other objects.
  44. GETSET_OBJECT(_dxj_DirectInputDevice);
  45. STDMETHODIMP C_dxj_DirectInputDeviceObject::getDeviceObjectsEnum(
  46. /* [in] */ long flags,
  47. /* [retval][out] */ I_dxj_DIEnumDeviceObjects **ppret)
  48. {
  49. HRESULT hr;
  50. hr=C_dxj_DIEnumDeviceObjectsObject::create(m__dxj_DirectInputDevice,flags,ppret);
  51. return hr;
  52. }
  53. STDMETHODIMP C_dxj_DirectInputDeviceObject::acquire(){
  54. return m__dxj_DirectInputDevice->Acquire();
  55. }
  56. STDMETHODIMP C_dxj_DirectInputDeviceObject::getCapabilities(DIDevCaps *caps)
  57. {
  58. //DIDevCaps same in VB/Java as in C
  59. caps->lSize=sizeof(DIDEVCAPS);
  60. HRESULT hr=m__dxj_DirectInputDevice->GetCapabilities((DIDEVCAPS*)caps);
  61. return hr;
  62. }
  63. //VB cant return sucess codes so we will return an error code
  64. #define VB_DI_BUFFEROVERFLOW 0x80040260
  65. STDMETHODIMP C_dxj_DirectInputDeviceObject::getDeviceData(
  66. /* [in] */ SAFEARRAY __RPC_FAR * __RPC_FAR *deviceObjectDataArray,
  67. /* [in] */ long flags,
  68. long *ret)
  69. {
  70. HRESULT hr;
  71. if ((*deviceObjectDataArray)->cDims!=1) return E_INVALIDARG;
  72. if ((*deviceObjectDataArray)->cbElements!=sizeof(DIDEVICEOBJECTDATA)) return E_INVALIDARG;
  73. DWORD dwC= (*deviceObjectDataArray)->rgsabound[0].cElements;
  74. if (dwC==0) return E_INVALIDARG;
  75. LPDIDEVICEOBJECTDATA pobjData=(LPDIDEVICEOBJECTDATA)((SAFEARRAY*)*deviceObjectDataArray)->pvData;
  76. hr=m__dxj_DirectInputDevice->GetDeviceData(sizeof(DIDEVICEOBJECTDATA), pobjData, (DWORD*)&dwC,flags);
  77. *ret=dwC;
  78. if (hr==DI_BUFFEROVERFLOW) hr= VB_DI_BUFFEROVERFLOW;
  79. return hr;
  80. }
  81. STDMETHODIMP C_dxj_DirectInputDeviceObject::getDeviceInfo(
  82. /* [out] */ I_dxj_DirectInputDeviceInstance __RPC_FAR **info)
  83. {
  84. HRESULT hr;
  85. //DIDeviceInstance not the Same in C as VB/J
  86. DIDEVICEINSTANCE inst;
  87. ZeroMemory(&inst,sizeof(DIDEVICEINSTANCE));
  88. inst.dwSize=sizeof(DIDEVICEINSTANCE);
  89. hr=m__dxj_DirectInputDevice->GetDeviceInfo(&inst);
  90. if FAILED(hr) return hr;
  91. hr=C_dxj_DIDeviceInstanceObject::create(&inst,info);
  92. return hr;
  93. /* DEAD
  94. info->strGuidInstance=GUIDtoBSTR(&inst.guidInstance);
  95. info->strGuidProduct=GUIDtoBSTR(&inst.guidProduct);
  96. info->strGuidFFDriver=GUIDtoBSTR(&inst.guidFFDriver);
  97. info->lDevType=(long)inst.dwDevType;
  98. info->nUsagePage=(short)inst.wUsagePage;
  99. info->nUsage=(short)inst.wUsage;
  100. USES_CONVERSION;
  101. if (info->strProductName)
  102. DXALLOCBSTR(info->strProductName);
  103. if (info->strInstanceName)
  104. DXALLOCBSTR(info->strInstanceName);
  105. info->strInstanceName=NULL;
  106. info->strProductName=NULL;
  107. if (inst.tszProductName)
  108. info->strProductName=T2BSTR(inst.tszProductName);
  109. if (inst.tszInstanceName)
  110. info->strInstanceName=T2BSTR(inst.tszInstanceName);
  111. */
  112. return hr;
  113. }
  114. STDMETHODIMP C_dxj_DirectInputDeviceObject::getDeviceStateKeyboard(
  115. /* [out] */ DIKeyboardState __RPC_FAR *state)
  116. {
  117. HRESULT hr;
  118. if ((nFormat!= dfDIKeyboard) && (nFormat!=-1)) return DIERR_NOTINITIALIZED ;
  119. hr=m__dxj_DirectInputDevice->GetDeviceState(256,(void*)state->key);
  120. return hr;
  121. }
  122. STDMETHODIMP C_dxj_DirectInputDeviceObject::getDeviceStateMouse(
  123. /* [out] */ DIMouseState __RPC_FAR *state)
  124. {
  125. HRESULT hr;
  126. if ((nFormat!= dfDIMouse) && (nFormat!=-1)) return DIERR_NOTINITIALIZED;
  127. hr=m__dxj_DirectInputDevice->GetDeviceState(sizeof(DIMOUSESTATE),(void*)state);
  128. return hr;
  129. }
  130. STDMETHODIMP C_dxj_DirectInputDeviceObject::getDeviceStateJoystick(
  131. /* [out] */ DIJoyState __RPC_FAR *state)
  132. {
  133. HRESULT hr;
  134. //note Joystick1 or Joystick2 are valid formats since
  135. //one is a superset of the other
  136. if ((nFormat!= dfDIJoystick)&&(nFormat!= dfDIJoystick2) && (nFormat!=-1)) return DIERR_NOTINITIALIZED;
  137. hr=m__dxj_DirectInputDevice->GetDeviceState(sizeof(DIJOYSTATE),(void*)state);
  138. return hr;
  139. }
  140. STDMETHODIMP C_dxj_DirectInputDeviceObject::getDeviceStateJoystick2(
  141. /* [out] */ DIJoyState2 __RPC_FAR *state)
  142. {
  143. HRESULT hr;
  144. //only for format2
  145. if ((nFormat!= dfDIJoystick2) && (nFormat!=-1)) return DIERR_NOTINITIALIZED;
  146. hr=m__dxj_DirectInputDevice->GetDeviceState(sizeof(DIJOYSTATE2),(void*)state);
  147. return hr;
  148. }
  149. STDMETHODIMP C_dxj_DirectInputDeviceObject::getDeviceState(
  150. /* [in] */ long cb,
  151. /* [in] */ void *pFormat)
  152. {
  153. HRESULT hr;
  154. __try {
  155. hr=m__dxj_DirectInputDevice->GetDeviceState((DWORD) cb,(void*)pFormat);
  156. }
  157. __except(1,1){
  158. hr=E_INVALIDARG;
  159. }
  160. return hr;
  161. }
  162. STDMETHODIMP C_dxj_DirectInputDeviceObject::getObjectInfo(
  163. /* [in] */ long obj,
  164. /* [in] */ long how,
  165. I_dxj_DirectInputDeviceObjectInstance **ret)
  166. {
  167. DIDEVICEOBJECTINSTANCE inst;
  168. ZeroMemory(&inst,sizeof(DIDEVICEOBJECTINSTANCE));
  169. inst.dwSize=sizeof(DIDEVICEOBJECTINSTANCE);
  170. HRESULT hr;
  171. hr=m__dxj_DirectInputDevice->GetObjectInfo(&inst,(DWORD) obj,(DWORD)how);
  172. if FAILED(hr) return hr;
  173. hr=C_dxj_DIDeviceObjectInstanceObject::create(&inst,ret);
  174. return hr;
  175. /* DEAD
  176. //TODO - consider what is going on here carefully
  177. if (instCover->strGuidType) SysFreeString((BSTR)instCover->strGuidType);
  178. if (instCover->strName) SysFreeString((BSTR)instCover->strName);
  179. //TODO - consider localization
  180. if (inst.tszName){
  181. instCover->strName=T2BSTR(inst.tszName);
  182. }
  183. instCover->strGuidType=DINPUTGUIDtoBSTR(&inst.guidType);
  184. instCover->lOfs=inst.dwOfs;
  185. instCover->lType=inst.dwType;
  186. instCover->lFlags=inst.dwFlags;
  187. instCover->lFFMaxForce=inst.dwFFMaxForce;
  188. instCover->lFFForceResolution=inst.dwFFForceResolution;
  189. instCover->nCollectionNumber=inst.wCollectionNumber;
  190. instCover->nDesignatorIndex=inst.wDesignatorIndex;
  191. instCover->nUsagePage=inst.wUsagePage;
  192. instCover->nUsage=inst.wUsage;
  193. instCover->lDimension=inst.dwDimension;
  194. instCover->nExponent=inst.wExponent;
  195. instCover->nReserved=inst.wReserved;
  196. return hr;
  197. */
  198. }
  199. // NOTE: - current working implemtation promotes
  200. // code bloat
  201. // might want to revist this and do it in a more
  202. // tidy fasion
  203. //
  204. STDMETHODIMP C_dxj_DirectInputDeviceObject::getProperty(
  205. /* [in] */ BSTR str,
  206. /* [out] */ void __RPC_FAR *propertyInfo)
  207. {
  208. HRESULT hr;
  209. //DWORD g;
  210. if (!propertyInfo) return E_INVALIDARG;
  211. ((DIPROPHEADER*)propertyInfo)->dwHeaderSize=sizeof(DIPROPHEADER);
  212. if( 0==_wcsicmp(str,L"diprop_buffersize")){
  213. //g = (DWORD)&DIPROP_BUFFERSIZE;
  214. hr=m__dxj_DirectInputDevice->GetProperty(DIPROP_BUFFERSIZE,(DIPROPHEADER*)propertyInfo);
  215. }
  216. else if( 0==_wcsicmp(str,L"diprop_axismode")){
  217. //g = (DWORD)&DIPROP_AXISMODE;
  218. hr=m__dxj_DirectInputDevice->GetProperty(DIPROP_AXISMODE,(DIPROPHEADER*)propertyInfo);
  219. }
  220. else if( 0==_wcsicmp(str,L"diprop_granularity")){
  221. //g = (DWORD)&DIPROP_GRANULARITY;
  222. hr=m__dxj_DirectInputDevice->GetProperty(DIPROP_GRANULARITY,(DIPROPHEADER*)propertyInfo);
  223. }
  224. else if( 0==_wcsicmp(str,L"diprop_range")){
  225. //g = (DWORD)&DIPROP_RANGE;
  226. hr=m__dxj_DirectInputDevice->GetProperty(DIPROP_RANGE,(DIPROPHEADER*)propertyInfo);
  227. }
  228. else if( 0==_wcsicmp(str,L"diprop_deadzone")){
  229. //g = (DWORD)&DIPROP_DEADZONE;
  230. hr=m__dxj_DirectInputDevice->GetProperty(DIPROP_DEADZONE,(DIPROPHEADER*)propertyInfo);
  231. }
  232. else if( 0==_wcsicmp(str,L"diprop_ffgain")){
  233. //g = (DWORD)&DIPROP_FFGAIN;
  234. hr=m__dxj_DirectInputDevice->GetProperty(DIPROP_FFGAIN,(DIPROPHEADER*)propertyInfo);
  235. }
  236. else if( 0==_wcsicmp(str,L"diprop_saturation")){
  237. //g = (DWORD)&DIPROP_SATURATION;
  238. hr=m__dxj_DirectInputDevice->GetProperty(DIPROP_SATURATION,(DIPROPHEADER*)propertyInfo);
  239. }
  240. else if( 0==_wcsicmp(str,L"diprop_ffload")){
  241. //g = (DWORD)&DIPROP_FFLOAD;
  242. hr=m__dxj_DirectInputDevice->GetProperty(DIPROP_FFLOAD,(DIPROPHEADER*)propertyInfo);
  243. }
  244. else if( 0==_wcsicmp(str,L"diprop_autocenter")){
  245. //g = (DWORD)&DIPROP_AUTOCENTER;
  246. hr=m__dxj_DirectInputDevice->GetProperty(DIPROP_AUTOCENTER,(DIPROPHEADER*)propertyInfo);
  247. }
  248. else if( 0==_wcsicmp(str,L"diprop_calibrationmode")){
  249. //g = (DWORD)&DIPROP_CALIBRATIONMODE;
  250. hr=m__dxj_DirectInputDevice->GetProperty(DIPROP_CALIBRATIONMODE,(DIPROPHEADER*)propertyInfo);
  251. }
  252. else {
  253. return E_INVALIDARG;
  254. }
  255. /*
  256. __try{
  257. ((DIPROPHEADER*)propertyInfo)->dwHeaderSize=sizeof(DIPROPHEADER);
  258. hr=m__dxj_DirectInputDevice->GetProperty((REFGUID)g,(DIPROPHEADER*)propertyInfo);
  259. }
  260. __except(1,1){
  261. return E_INVALIDARG;
  262. }
  263. */
  264. return hr;
  265. }
  266. STDMETHODIMP C_dxj_DirectInputDeviceObject::runControlPanel(
  267. /* [in] */ long hwnd)
  268. {
  269. HRESULT hr;
  270. hr=m__dxj_DirectInputDevice->RunControlPanel((HWND) hwnd,(DWORD)0);
  271. return hr;
  272. }
  273. STDMETHODIMP C_dxj_DirectInputDeviceObject::setCooperativeLevel(
  274. /* [in] */ long hwnd,
  275. /* [in] */ long flags)
  276. {
  277. HRESULT hr;
  278. hr=m__dxj_DirectInputDevice->SetCooperativeLevel((HWND) hwnd,(DWORD)flags);
  279. return hr;
  280. }
  281. STDMETHODIMP C_dxj_DirectInputDeviceObject::poll()
  282. {
  283. HRESULT hr;
  284. hr=m__dxj_DirectInputDevice->Poll();
  285. return hr;
  286. }
  287. STDMETHODIMP C_dxj_DirectInputDeviceObject::setCommonDataFormat(
  288. /* [in] */ long format)
  289. {
  290. //variant so that when structs can be packed in VARIANTS we can take care of it
  291. HRESULT hr;
  292. //� c_dfDIKeyboard
  293. //� c_dfDIMouse
  294. //� c_dfDIJoystick
  295. //� c_dfDIJoystick2
  296. nFormat=format;
  297. switch(format){
  298. case dfDIKeyboard:
  299. hr=m__dxj_DirectInputDevice->SetDataFormat(&c_dfDIKeyboard);
  300. break;
  301. case dfDIMouse:
  302. hr=m__dxj_DirectInputDevice->SetDataFormat(&c_dfDIMouse);
  303. break;
  304. case dfDIJoystick:
  305. hr=m__dxj_DirectInputDevice->SetDataFormat(&c_dfDIJoystick);
  306. break;
  307. case dfDIJoystick2:
  308. hr=m__dxj_DirectInputDevice->SetDataFormat(&c_dfDIJoystick2);
  309. break;
  310. default:
  311. return E_INVALIDARG;
  312. }
  313. return hr;
  314. }
  315. STDMETHODIMP C_dxj_DirectInputDeviceObject::setDataFormat(
  316. /* [in] */ DIDataFormat __RPC_FAR *format,
  317. SAFEARRAY __RPC_FAR * __RPC_FAR *formatArray)
  318. {
  319. HRESULT hr;
  320. LPDIDATAFORMAT pFormat=(LPDIDATAFORMAT)format;
  321. LPGUID pGuid=NULL;
  322. LPGUID pGuidArray=NULL;
  323. DIObjectDataFormat *pDiDataFormat=NULL;
  324. if ((!format) || (!formatArray)) return E_INVALIDARG;
  325. if (!ISSAFEARRAY1D(formatArray,pFormat->dwNumObjs)) return E_INVALIDARG;
  326. pFormat->dwSize=sizeof(DIDATAFORMAT);
  327. pFormat->rgodf=NULL;
  328. pFormat->rgodf=(LPDIOBJECTDATAFORMAT)DXHEAPALLOC(pFormat->dwNumObjs*sizeof(DIOBJECTDATAFORMAT));
  329. if (!pFormat->rgodf) return E_OUTOFMEMORY;
  330. pGuidArray=(LPGUID)DXHEAPALLOC(pFormat->dwNumObjs*sizeof(GUID));
  331. if (!pGuidArray)
  332. {
  333. DXHEAPFREE(pFormat->rgodf);
  334. return E_OUTOFMEMORY;
  335. }
  336. __try {
  337. for (DWORD i=0; i< pFormat->dwNumObjs;i++){
  338. pGuid=&(pGuidArray[i]);
  339. pDiDataFormat=&(((DIObjectDataFormat*)((SAFEARRAY*)*formatArray)->pvData)[i]);
  340. hr=DINPUTBSTRtoGUID(pGuid, pDiDataFormat->strGuid);
  341. if FAILED(hr) {
  342. DXHEAPFREE(pGuidArray);
  343. DXHEAPFREE(pFormat->rgodf);
  344. pFormat->rgodf=NULL;
  345. }
  346. pFormat->rgodf[i].pguid=pGuid;
  347. pFormat->rgodf[i].dwOfs=pDiDataFormat->lOfs;
  348. pFormat->rgodf[i].dwType=pDiDataFormat->lType;
  349. pFormat->rgodf[i].dwFlags=pDiDataFormat->lFlags;
  350. }
  351. hr=m__dxj_DirectInputDevice->SetDataFormat(pFormat);
  352. DXHEAPFREE(pGuidArray);
  353. DXHEAPFREE(pFormat->rgodf);
  354. }
  355. __except(1,1){
  356. DXHEAPFREE(pGuidArray);
  357. DXHEAPFREE(pFormat->rgodf);
  358. return E_INVALIDARG;
  359. }
  360. //indicate we have a custom format
  361. nFormat=-1;
  362. return hr;
  363. }
  364. STDMETHODIMP C_dxj_DirectInputDeviceObject::setEventNotification(
  365. /* [in] */ long hEvent)
  366. {
  367. HRESULT hr=m__dxj_DirectInputDevice->SetEventNotification((HANDLE)hEvent);
  368. return hr;
  369. }
  370. STDMETHODIMP C_dxj_DirectInputDeviceObject::setProperty(
  371. /* [in] */ BSTR __RPC_FAR str,
  372. /* [out] */ void __RPC_FAR *propertyInfo)
  373. {
  374. HRESULT hr;
  375. //DWORD g;
  376. if (!propertyInfo) return E_INVALIDARG;
  377. ((DIPROPHEADER*)propertyInfo)->dwHeaderSize=sizeof(DIPROPHEADER);
  378. if( 0==_wcsicmp(str,L"diprop_buffersize")){
  379. //g = (DWORD)&DIPROP_BUFFERSIZE;
  380. hr=m__dxj_DirectInputDevice->SetProperty(DIPROP_BUFFERSIZE,(DIPROPHEADER*)propertyInfo);
  381. }
  382. else if( 0==_wcsicmp(str,L"diprop_axismode")){
  383. //g = (DWORD)&DIPROP_AXISMODE;
  384. hr=m__dxj_DirectInputDevice->SetProperty(DIPROP_AXISMODE,(DIPROPHEADER*)propertyInfo);
  385. }
  386. else if( 0==_wcsicmp(str,L"diprop_granularity")){
  387. //g = (DWORD)&DIPROP_GRANULARITY;
  388. hr=m__dxj_DirectInputDevice->SetProperty(DIPROP_GRANULARITY,(DIPROPHEADER*)propertyInfo);
  389. }
  390. else if( 0==_wcsicmp(str,L"diprop_range")){
  391. //g = (DWORD)&DIPROP_RANGE;
  392. hr=m__dxj_DirectInputDevice->SetProperty(DIPROP_RANGE,(DIPROPHEADER*)propertyInfo);
  393. }
  394. else if( 0==_wcsicmp(str,L"diprop_deadzone")){
  395. //g = (DWORD)&DIPROP_DEADZONE;
  396. hr=m__dxj_DirectInputDevice->SetProperty(DIPROP_DEADZONE,(DIPROPHEADER*)propertyInfo);
  397. }
  398. else if( 0==_wcsicmp(str,L"diprop_ffgain")){
  399. //g = (DWORD)&DIPROP_FFGAIN;
  400. hr=m__dxj_DirectInputDevice->SetProperty(DIPROP_FFGAIN,(DIPROPHEADER*)propertyInfo);
  401. }
  402. else if( 0==_wcsicmp(str,L"diprop_saturation")){
  403. //g = (DWORD)&DIPROP_SATURATION;
  404. hr=m__dxj_DirectInputDevice->SetProperty(DIPROP_SATURATION,(DIPROPHEADER*)propertyInfo);
  405. }
  406. else if( 0==_wcsicmp(str,L"diprop_ffload")){
  407. //g = (DWORD)&DIPROP_FFLOAD;
  408. hr=m__dxj_DirectInputDevice->SetProperty(DIPROP_FFLOAD,(DIPROPHEADER*)propertyInfo);
  409. }
  410. else if( 0==_wcsicmp(str,L"diprop_autocenter")){
  411. //g = (DWORD)&DIPROP_AUTOCENTER;
  412. hr=m__dxj_DirectInputDevice->SetProperty(DIPROP_AUTOCENTER,(DIPROPHEADER*)propertyInfo);
  413. }
  414. else if( 0==_wcsicmp(str,L"diprop_calibrationmode")){
  415. //g = (DWORD)&DIPROP_CALIBRATIONMODE;
  416. hr=m__dxj_DirectInputDevice->SetProperty(DIPROP_CALIBRATIONMODE,(DIPROPHEADER*)propertyInfo);
  417. }
  418. else {
  419. return E_INVALIDARG;
  420. }
  421. /*
  422. __try {
  423. ((DIPROPHEADER*)propertyInfo)->dwHeaderSize=sizeof(DIPROPHEADER);
  424. hr=m__dxj_DirectInputDevice->SetProperty((REFGUID)g,(DIPROPHEADER*)propertyInfo);
  425. }
  426. __except (1,1){
  427. return E_INVALIDARG;
  428. }
  429. */
  430. return hr;
  431. }
  432. STDMETHODIMP C_dxj_DirectInputDeviceObject::unacquire()
  433. {
  434. HRESULT hr=m__dxj_DirectInputDevice->Unacquire();
  435. return hr;
  436. }
  437. STDMETHODIMP C_dxj_DirectInputDeviceObject::createEffect(
  438. /* [in] */ BSTR effectGuid,
  439. /* [in] */ DIEffect __RPC_FAR *effectInfo,
  440. /* [retval][out] */ I_dxj_DirectInputEffect __RPC_FAR *__RPC_FAR *ret)
  441. {
  442. HRESULT hr;
  443. GUID g;
  444. DIEFFECT realEffect;
  445. LPDIRECTINPUTEFFECT pRealEffect=NULL;
  446. hr=DINPUTBSTRtoGUID(&g,effectGuid);
  447. if FAILED(hr) return hr;
  448. hr=FixUpRealEffect(g,&realEffect,effectInfo);
  449. if FAILED(hr) return hr;
  450. hr=m__dxj_DirectInputDevice->CreateEffect(g,&realEffect,&pRealEffect,NULL);
  451. if FAILED(hr) return hr;
  452. INTERNAL_CREATE(_dxj_DirectInputEffect,pRealEffect,ret)
  453. return hr;
  454. }
  455. STDMETHODIMP C_dxj_DirectInputDeviceObject::createCustomEffect(
  456. /* [in] */ DIEffect __RPC_FAR *effectInfo,
  457. /* [in] */ long channels,
  458. /* [in] */ long samplePeriod,
  459. /* [in] */ long nSamples,
  460. /* [in] */ SAFEARRAY __RPC_FAR * __RPC_FAR *sampledata,
  461. /* [retval][out] */ I_dxj_DirectInputEffect __RPC_FAR *__RPC_FAR *ret)
  462. {
  463. HRESULT hr;
  464. GUID g=GUID_CustomForce;
  465. DIEFFECT realEffect;
  466. LPDIRECTINPUTEFFECT pRealEffect=NULL;
  467. hr=FixUpRealEffect(g,&realEffect,effectInfo);
  468. if FAILED(hr) return hr;
  469. DICUSTOMFORCE customData;
  470. customData.cChannels =(DWORD)channels;
  471. customData.cSamples =(DWORD)nSamples;
  472. customData.dwSamplePeriod =(DWORD)samplePeriod;
  473. customData.rglForceData = (long*)(*sampledata)->pvData;
  474. realEffect.lpvTypeSpecificParams=&customData;
  475. realEffect.cbTypeSpecificParams=sizeof(DICUSTOMFORCE);
  476. __try {
  477. hr=m__dxj_DirectInputDevice->CreateEffect(g,&realEffect,&pRealEffect,NULL);
  478. }
  479. __except(1,1){
  480. return E_INVALIDARG;
  481. }
  482. if FAILED(hr) return hr;
  483. INTERNAL_CREATE(_dxj_DirectInputEffect,pRealEffect,ret)
  484. return hr;
  485. }
  486. STDMETHODIMP C_dxj_DirectInputDeviceObject::sendDeviceData(
  487. /* [in] */ long count,
  488. /* [in] */ SAFEARRAY __RPC_FAR * __RPC_FAR *data,
  489. /* [in] */ long flags,
  490. /* [retval][out] */ long __RPC_FAR *retcount)
  491. {
  492. DWORD dwCount=count;
  493. HRESULT hr;
  494. __try {
  495. hr=m__dxj_DirectInputDevice->SendDeviceData(
  496. sizeof(DIDEVICEOBJECTDATA),
  497. (DIDEVICEOBJECTDATA*)(*data)->pvData,
  498. &dwCount,
  499. (DWORD)flags);
  500. }
  501. __except(1,1){
  502. return E_INVALIDARG;
  503. }
  504. return hr;
  505. }
  506. STDMETHODIMP C_dxj_DirectInputDeviceObject::sendForceFeedbackCommand(
  507. /* [in] */ long flags)
  508. {
  509. HRESULT hr;
  510. hr=m__dxj_DirectInputDevice->SendForceFeedbackCommand((DWORD)flags);
  511. return hr;
  512. }
  513. STDMETHODIMP C_dxj_DirectInputDeviceObject::getForceFeedbackState(
  514. /* [retval][out] */ long __RPC_FAR *state)
  515. {
  516. if (!state) return E_INVALIDARG;
  517. HRESULT hr;
  518. hr=m__dxj_DirectInputDevice->GetForceFeedbackState((DWORD*)state);
  519. return hr;
  520. }
  521. STDMETHODIMP C_dxj_DirectInputDeviceObject::getEffectsEnum( long effType,
  522. I_dxj_DirectInputEnumEffects **ret)
  523. {
  524. HRESULT hr=C_dxj_DirectInputEnumEffectsObject::create(m__dxj_DirectInputDevice,effType,ret);
  525. return hr;
  526. }