dinput: Fix processing of custom format.
[wine/testsucceed.git] / dlls / dinput / device.c
blobfd38baa3c10549b4c6b81d940118d849de0e8449
1 /* DirectInput Device
3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998,1999 Lionel Ulmer
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 /* This file contains all the Device specific functions that can be used as stubs
23 by real device implementations.
25 It also contains all the helper functions.
27 #include "config.h"
29 #include <stdarg.h>
30 #include <string.h>
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
33 #include "windef.h"
34 #include "winbase.h"
35 #include "winuser.h"
36 #include "winerror.h"
37 #include "dinput.h"
38 #include "device_private.h"
39 #include "dinput_private.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
43 /******************************************************************************
44 * Various debugging tools
46 void _dump_cooperativelevel_DI(DWORD dwFlags) {
47 if (TRACE_ON(dinput)) {
48 unsigned int i;
49 static const struct {
50 DWORD mask;
51 const char *name;
52 } flags[] = {
53 #define FE(x) { x, #x}
54 FE(DISCL_BACKGROUND),
55 FE(DISCL_EXCLUSIVE),
56 FE(DISCL_FOREGROUND),
57 FE(DISCL_NONEXCLUSIVE),
58 FE(DISCL_NOWINKEY)
59 #undef FE
61 for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++)
62 if (flags[i].mask & dwFlags)
63 DPRINTF("%s ",flags[i].name);
64 DPRINTF("\n");
68 void _dump_EnumObjects_flags(DWORD dwFlags) {
69 if (TRACE_ON(dinput)) {
70 unsigned int i;
71 DWORD type, instance;
72 static const struct {
73 DWORD mask;
74 const char *name;
75 } flags[] = {
76 #define FE(x) { x, #x}
77 FE(DIDFT_RELAXIS),
78 FE(DIDFT_ABSAXIS),
79 FE(DIDFT_PSHBUTTON),
80 FE(DIDFT_TGLBUTTON),
81 FE(DIDFT_POV),
82 FE(DIDFT_COLLECTION),
83 FE(DIDFT_NODATA),
84 FE(DIDFT_FFACTUATOR),
85 FE(DIDFT_FFEFFECTTRIGGER),
86 FE(DIDFT_OUTPUT),
87 FE(DIDFT_VENDORDEFINED),
88 FE(DIDFT_ALIAS),
89 FE(DIDFT_OPTIONAL)
90 #undef FE
92 type = (dwFlags & 0xFF0000FF);
93 instance = ((dwFlags >> 8) & 0xFFFF);
94 DPRINTF("Type:");
95 if (type == DIDFT_ALL) {
96 DPRINTF(" DIDFT_ALL");
97 } else {
98 for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++) {
99 if (flags[i].mask & type) {
100 type &= ~flags[i].mask;
101 DPRINTF(" %s",flags[i].name);
104 if (type) {
105 DPRINTF(" (unhandled: %08x)", type);
108 DPRINTF(" / Instance: ");
109 if (instance == ((DIDFT_ANYINSTANCE >> 8) & 0xFFFF)) {
110 DPRINTF("DIDFT_ANYINSTANCE");
111 } else {
112 DPRINTF("%3d", instance);
117 void _dump_DIPROPHEADER(LPCDIPROPHEADER diph) {
118 if (TRACE_ON(dinput)) {
119 DPRINTF(" - dwObj = 0x%08x\n", diph->dwObj);
120 DPRINTF(" - dwHow = %s\n",
121 ((diph->dwHow == DIPH_DEVICE) ? "DIPH_DEVICE" :
122 ((diph->dwHow == DIPH_BYOFFSET) ? "DIPH_BYOFFSET" :
123 ((diph->dwHow == DIPH_BYID)) ? "DIPH_BYID" : "unknown")));
127 void _dump_OBJECTINSTANCEA(DIDEVICEOBJECTINSTANCEA *ddoi) {
128 if (TRACE_ON(dinput)) {
129 DPRINTF(" - enumerating : %s ('%s') - %2d - 0x%08x - %s\n",
130 debugstr_guid(&ddoi->guidType), _dump_dinput_GUID(&ddoi->guidType), ddoi->dwOfs, ddoi->dwType, ddoi->tszName);
134 void _dump_OBJECTINSTANCEW(DIDEVICEOBJECTINSTANCEW *ddoi) {
135 if (TRACE_ON(dinput)) {
136 DPRINTF(" - enumerating : %s ('%s'), - %2d - 0x%08x - %s\n",
137 debugstr_guid(&ddoi->guidType), _dump_dinput_GUID(&ddoi->guidType), ddoi->dwOfs, ddoi->dwType, debugstr_w(ddoi->tszName));
141 /* This function is a helper to convert a GUID into any possible DInput GUID out there */
142 const char *_dump_dinput_GUID(const GUID *guid) {
143 unsigned int i;
144 static const struct {
145 const GUID *guid;
146 const char *name;
147 } guids[] = {
148 #define FE(x) { &x, #x}
149 FE(GUID_XAxis),
150 FE(GUID_YAxis),
151 FE(GUID_ZAxis),
152 FE(GUID_RxAxis),
153 FE(GUID_RyAxis),
154 FE(GUID_RzAxis),
155 FE(GUID_Slider),
156 FE(GUID_Button),
157 FE(GUID_Key),
158 FE(GUID_POV),
159 FE(GUID_Unknown),
160 FE(GUID_SysMouse),
161 FE(GUID_SysKeyboard),
162 FE(GUID_Joystick),
163 FE(GUID_ConstantForce),
164 FE(GUID_RampForce),
165 FE(GUID_Square),
166 FE(GUID_Sine),
167 FE(GUID_Triangle),
168 FE(GUID_SawtoothUp),
169 FE(GUID_SawtoothDown),
170 FE(GUID_Spring),
171 FE(GUID_Damper),
172 FE(GUID_Inertia),
173 FE(GUID_Friction),
174 FE(GUID_CustomForce)
175 #undef FE
177 if (guid == NULL)
178 return "null GUID";
179 for (i = 0; i < (sizeof(guids) / sizeof(guids[0])); i++) {
180 if (IsEqualGUID(guids[i].guid, guid)) {
181 return guids[i].name;
184 return "Unknown GUID";
187 void _dump_DIDATAFORMAT(const DIDATAFORMAT *df) {
188 unsigned int i;
190 TRACE("Dumping DIDATAFORMAT structure:\n");
191 TRACE(" - dwSize: %d\n", df->dwSize);
192 if (df->dwSize != sizeof(DIDATAFORMAT)) {
193 WARN("Non-standard DIDATAFORMAT structure size %d\n", df->dwSize);
195 TRACE(" - dwObjsize: %d\n", df->dwObjSize);
196 if (df->dwObjSize != sizeof(DIOBJECTDATAFORMAT)) {
197 WARN("Non-standard DIOBJECTDATAFORMAT structure size %d\n", df->dwObjSize);
199 TRACE(" - dwFlags: 0x%08x (", df->dwFlags);
200 switch (df->dwFlags) {
201 case DIDF_ABSAXIS: TRACE("DIDF_ABSAXIS"); break;
202 case DIDF_RELAXIS: TRACE("DIDF_RELAXIS"); break;
203 default: TRACE("unknown"); break;
205 TRACE(")\n");
206 TRACE(" - dwDataSize: %d\n", df->dwDataSize);
207 TRACE(" - dwNumObjs: %d\n", df->dwNumObjs);
209 for (i = 0; i < df->dwNumObjs; i++) {
210 TRACE(" - Object %d:\n", i);
211 TRACE(" * GUID: %s ('%s')\n", debugstr_guid(df->rgodf[i].pguid), _dump_dinput_GUID(df->rgodf[i].pguid));
212 TRACE(" * dwOfs: %d\n", df->rgodf[i].dwOfs);
213 TRACE(" * dwType: 0x%08x\n", df->rgodf[i].dwType);
214 TRACE(" "); _dump_EnumObjects_flags(df->rgodf[i].dwType); TRACE("\n");
215 TRACE(" * dwFlags: 0x%08x\n", df->rgodf[i].dwFlags);
219 /* Conversion between internal data buffer and external data buffer */
220 void fill_DataFormat(void *out, const void *in, DataFormat *df) {
221 int i;
222 const char *in_c = in;
223 char *out_c = (char *) out;
225 if (df->dt == NULL) {
226 /* This means that the app uses Wine's internal data format */
227 memcpy(out, in, df->internal_format_size);
228 } else {
229 for (i = 0; i < df->size; i++) {
230 if (df->dt[i].offset_in >= 0) {
231 switch (df->dt[i].size) {
232 case 1:
233 TRACE("Copying (c) to %d from %d (value %d)\n",
234 df->dt[i].offset_out, df->dt[i].offset_in, *(in_c + df->dt[i].offset_in));
235 *(out_c + df->dt[i].offset_out) = *(in_c + df->dt[i].offset_in);
236 break;
238 case 2:
239 TRACE("Copying (s) to %d from %d (value %d)\n",
240 df->dt[i].offset_out, df->dt[i].offset_in, *((const short *)(in_c + df->dt[i].offset_in)));
241 *((short *)(out_c + df->dt[i].offset_out)) = *((const short *)(in_c + df->dt[i].offset_in));
242 break;
244 case 4:
245 TRACE("Copying (i) to %d from %d (value %d)\n",
246 df->dt[i].offset_out, df->dt[i].offset_in, *((const int *)(in_c + df->dt[i].offset_in)));
247 *((int *)(out_c + df->dt[i].offset_out)) = *((const int *)(in_c + df->dt[i].offset_in));
248 break;
250 default:
251 memcpy((out_c + df->dt[i].offset_out), (in_c + df->dt[i].offset_in), df->dt[i].size);
252 break;
254 } else {
255 switch (df->dt[i].size) {
256 case 1:
257 TRACE("Copying (c) to %d default value %d\n",
258 df->dt[i].offset_out, df->dt[i].value);
259 *(out_c + df->dt[i].offset_out) = (char) df->dt[i].value;
260 break;
262 case 2:
263 TRACE("Copying (s) to %d default value %d\n",
264 df->dt[i].offset_out, df->dt[i].value);
265 *((short *) (out_c + df->dt[i].offset_out)) = (short) df->dt[i].value;
266 break;
268 case 4:
269 TRACE("Copying (i) to %d default value %d\n",
270 df->dt[i].offset_out, df->dt[i].value);
271 *((int *) (out_c + df->dt[i].offset_out)) = (int) df->dt[i].value;
272 break;
274 default:
275 memset((out_c + df->dt[i].offset_out), 0, df->dt[i].size);
276 break;
283 void release_DataFormat(DataFormat * format)
285 TRACE("Deleting DataTransform :\n");
287 HeapFree(GetProcessHeap(), 0, format->dt);
290 DataFormat *create_DataFormat(const DIDATAFORMAT *wine_format, LPCDIDATAFORMAT asked_format, int *offset) {
291 DataFormat *ret;
292 DataTransform *dt;
293 unsigned int i, j;
294 int same = 1;
295 int *done;
296 int index = 0;
297 DWORD next = 0;
299 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(DataFormat));
301 done = HeapAlloc(GetProcessHeap(), 0, sizeof(int) * asked_format->dwNumObjs);
302 memset(done, 0, sizeof(int) * asked_format->dwNumObjs);
304 dt = HeapAlloc(GetProcessHeap(), 0, asked_format->dwNumObjs * sizeof(DataTransform));
306 TRACE("Creating DataTransform :\n");
308 for (i = 0; i < wine_format->dwNumObjs; i++) {
309 offset[i] = -1;
311 for (j = 0; j < asked_format->dwNumObjs; j++) {
312 if (done[j] == 1)
313 continue;
315 if (/* Check if the application either requests any GUID and if not, it if matches
316 * the GUID of the Wine object.
318 ((asked_format->rgodf[j].pguid == NULL) ||
319 (wine_format->rgodf[i].pguid == NULL) ||
320 (IsEqualGUID(wine_format->rgodf[i].pguid, asked_format->rgodf[j].pguid)))
322 (/* Then check if it accepts any instance id, and if not, if it matches Wine's
323 * instance id.
325 (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == 0xFFFF) ||
326 (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == 0x00FF) || /* This is mentionned in no DX docs, but it works fine - tested on WinXP */
327 (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == DIDFT_GETINSTANCE(wine_format->rgodf[i].dwType)))
329 ( /* Then if the asked type matches the one Wine provides */
330 DIDFT_GETTYPE(asked_format->rgodf[j].dwType) & wine_format->rgodf[i].dwType))
332 done[j] = 1;
334 TRACE("Matching :\n");
335 TRACE(" - Asked (%d) :\n", j);
336 TRACE(" * GUID: %s ('%s')\n",
337 debugstr_guid(asked_format->rgodf[j].pguid),
338 _dump_dinput_GUID(asked_format->rgodf[j].pguid));
339 TRACE(" * Offset: %3d\n", asked_format->rgodf[j].dwOfs);
340 TRACE(" * dwType: %08x\n", asked_format->rgodf[j].dwType);
341 TRACE(" "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
343 TRACE(" - Wine (%d) :\n", i);
344 TRACE(" * GUID: %s ('%s')\n",
345 debugstr_guid(wine_format->rgodf[i].pguid),
346 _dump_dinput_GUID(wine_format->rgodf[i].pguid));
347 TRACE(" * Offset: %3d\n", wine_format->rgodf[i].dwOfs);
348 TRACE(" * dwType: %08x\n", wine_format->rgodf[i].dwType);
349 TRACE(" "); _dump_EnumObjects_flags(wine_format->rgodf[i].dwType); TRACE("\n");
351 if (wine_format->rgodf[i].dwType & DIDFT_BUTTON)
352 dt[index].size = sizeof(BYTE);
353 else
354 dt[index].size = sizeof(DWORD);
355 dt[index].offset_in = wine_format->rgodf[i].dwOfs;
356 if (asked_format->rgodf[j].dwOfs < next) {
357 WARN("bad format: dwOfs=%d, changing to %d\n", asked_format->rgodf[j].dwOfs, next);
358 dt[index].offset_out = next;
359 offset[i] = next;
360 } else {
361 dt[index].offset_out = asked_format->rgodf[j].dwOfs;
362 offset[i] = asked_format->rgodf[j].dwOfs;
364 dt[index].value = 0;
365 next = next + dt[index].size;
367 if (wine_format->rgodf[i].dwOfs != dt[index].offset_out)
368 same = 0;
370 index++;
371 break;
375 if (j == asked_format->dwNumObjs)
376 same = 0;
379 TRACE("Setting to default value :\n");
380 for (j = 0; j < asked_format->dwNumObjs; j++) {
381 if (done[j] == 0) {
382 TRACE(" - Asked (%d) :\n", j);
383 TRACE(" * GUID: %s ('%s')\n",
384 debugstr_guid(asked_format->rgodf[j].pguid),
385 _dump_dinput_GUID(asked_format->rgodf[j].pguid));
386 TRACE(" * Offset: %3d\n", asked_format->rgodf[j].dwOfs);
387 TRACE(" * dwType: %08x\n", asked_format->rgodf[j].dwType);
388 TRACE(" "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
390 if (asked_format->rgodf[j].dwType & DIDFT_BUTTON)
391 dt[index].size = sizeof(BYTE);
392 else
393 dt[index].size = sizeof(DWORD);
394 dt[index].offset_in = -1;
395 dt[index].offset_out = asked_format->rgodf[j].dwOfs;
396 dt[index].value = 0;
397 index++;
399 same = 0;
403 ret->internal_format_size = wine_format->dwDataSize;
404 ret->size = index;
405 if (same) {
406 ret->dt = NULL;
407 HeapFree(GetProcessHeap(), 0, dt);
408 } else {
409 ret->dt = dt;
412 HeapFree(GetProcessHeap(), 0, done);
414 return ret;
417 BOOL DIEnumDevicesCallbackAtoW(LPCDIDEVICEOBJECTINSTANCEA lpddi, LPVOID lpvRef) {
418 DIDEVICEOBJECTINSTANCEW ddtmp;
419 device_enumobjects_AtoWcb_data* data;
421 data = (device_enumobjects_AtoWcb_data*) lpvRef;
423 memset(&ddtmp, 0, sizeof(ddtmp));
425 ddtmp.dwSize = sizeof(DIDEVICEINSTANCEW);
426 ddtmp.guidType = lpddi->guidType;
427 ddtmp.dwOfs = lpddi->dwOfs;
428 ddtmp.dwType = lpddi->dwType;
429 ddtmp.dwFlags = lpddi->dwFlags;
430 MultiByteToWideChar(CP_ACP, 0, lpddi->tszName, -1, ddtmp.tszName, MAX_PATH);
432 if (lpddi->dwSize == sizeof(DIDEVICEINSTANCEA)) {
434 * if dwSize < sizeof(DIDEVICEINSTANCEA of DInput version >= 5)
435 * force feedback and other newer datas aren't available
437 ddtmp.dwFFMaxForce = lpddi->dwFFMaxForce;
438 ddtmp.dwFFForceResolution = lpddi->dwFFForceResolution;
439 ddtmp.wCollectionNumber = lpddi->wCollectionNumber;
440 ddtmp.wDesignatorIndex = lpddi->wDesignatorIndex;
441 ddtmp.wUsagePage = lpddi->wUsagePage;
442 ddtmp.wUsage = lpddi->wUsage;
443 ddtmp.dwDimension = lpddi->dwDimension;
444 ddtmp.wExponent = lpddi->wExponent;
445 ddtmp.wReserved = lpddi->wReserved;
447 return data->lpCallBack(&ddtmp, data->lpvRef);
450 /******************************************************************************
451 * queue_event - add new event to the ring queue
454 void queue_event(LPDIRECTINPUTDEVICE8A iface, int ofs, DWORD data, DWORD time, DWORD seq)
456 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
457 int next_pos;
459 if (!This->queue_len || This->overflow || ofs < 0) return;
461 next_pos = (This->queue_head + 1) % This->queue_len;
462 if (next_pos == This->queue_tail)
464 TRACE(" queue overflowed\n");
465 This->overflow = TRUE;
466 return;
469 TRACE(" queueing %d at offset %d (queue head %d / size %d)\n",
470 data, ofs, This->queue_head, This->queue_len);
472 This->data_queue[This->queue_head].dwOfs = ofs;
473 This->data_queue[This->queue_head].dwData = data;
474 This->data_queue[This->queue_head].dwTimeStamp = time;
475 This->data_queue[This->queue_head].dwSequence = seq;
476 This->queue_head = next_pos;
479 /******************************************************************************
480 * Acquire
483 HRESULT WINAPI IDirectInputDevice2AImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
485 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
486 HRESULT res;
488 EnterCriticalSection(&This->crit);
489 res = This->acquired ? S_FALSE : DI_OK;
490 This->acquired = 1;
491 if (res == DI_OK)
492 This->queue_head = This->queue_tail = This->overflow = 0;
493 LeaveCriticalSection(&This->crit);
495 return res;
498 /******************************************************************************
499 * Unacquire
502 HRESULT WINAPI IDirectInputDevice2AImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
504 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
505 HRESULT res;
507 EnterCriticalSection(&This->crit);
508 res = !This->acquired ? DI_NOEFFECT : DI_OK;
509 This->acquired = 0;
510 LeaveCriticalSection(&This->crit);
512 return res;
515 /******************************************************************************
516 * IDirectInputDeviceA
519 HRESULT WINAPI IDirectInputDevice2AImpl_SetDataFormat(
520 LPDIRECTINPUTDEVICE8A iface,LPCDIDATAFORMAT df
522 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
524 TRACE("(this=%p,%p)\n",This,df);
526 _dump_DIDATAFORMAT(df);
528 return DI_OK;
531 /******************************************************************************
532 * SetCooperativeLevel
534 * Set cooperative level and the source window for the events.
536 HRESULT WINAPI IDirectInputDevice2AImpl_SetCooperativeLevel(
537 LPDIRECTINPUTDEVICE8A iface, HWND hwnd, DWORD dwflags)
539 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
541 TRACE("(%p) %p,0x%08x\n", This, hwnd, dwflags);
542 TRACE(" cooperative level : ");
543 _dump_cooperativelevel_DI(dwflags);
545 if ((dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == 0 ||
546 (dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE) ||
547 (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == 0 ||
548 (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == (DISCL_FOREGROUND | DISCL_BACKGROUND))
549 return DIERR_INVALIDPARAM;
551 if (dwflags == (DISCL_NONEXCLUSIVE | DISCL_BACKGROUND))
552 hwnd = GetDesktopWindow();
554 if (!hwnd) return E_HANDLE;
556 /* For security reasons native does not allow exclusive background level
557 for mouse and keyboard only */
558 if (dwflags & DISCL_EXCLUSIVE && dwflags & DISCL_BACKGROUND &&
559 (IsEqualGUID(&This->guid, &GUID_SysMouse) ||
560 IsEqualGUID(&This->guid, &GUID_SysKeyboard)))
561 return DIERR_UNSUPPORTED;
563 /* Store the window which asks for the mouse */
564 EnterCriticalSection(&This->crit);
565 This->win = hwnd;
566 This->dwCoopLevel = dwflags;
567 LeaveCriticalSection(&This->crit);
569 return DI_OK;
572 /******************************************************************************
573 * SetEventNotification : specifies event to be sent on state change
575 HRESULT WINAPI IDirectInputDevice2AImpl_SetEventNotification(
576 LPDIRECTINPUTDEVICE8A iface, HANDLE event)
578 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
580 TRACE("(%p) %p\n", This, event);
582 EnterCriticalSection(&This->crit);
583 This->hEvent = event;
584 LeaveCriticalSection(&This->crit);
585 return DI_OK;
588 ULONG WINAPI IDirectInputDevice2AImpl_Release(LPDIRECTINPUTDEVICE8A iface)
590 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
591 ULONG ref;
593 ref = InterlockedDecrement(&(This->ref));
594 if (ref) return ref;
596 DeleteCriticalSection(&This->crit);
597 HeapFree(GetProcessHeap(), 0, This->data_queue);
598 HeapFree(GetProcessHeap(), 0, This);
600 return DI_OK;
603 HRESULT WINAPI IDirectInputDevice2AImpl_QueryInterface(
604 LPDIRECTINPUTDEVICE8A iface,REFIID riid,LPVOID *ppobj
607 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
609 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
610 if (IsEqualGUID(&IID_IUnknown,riid)) {
611 IDirectInputDevice2_AddRef(iface);
612 *ppobj = This;
613 return DI_OK;
615 if (IsEqualGUID(&IID_IDirectInputDeviceA,riid)) {
616 IDirectInputDevice2_AddRef(iface);
617 *ppobj = This;
618 return DI_OK;
620 if (IsEqualGUID(&IID_IDirectInputDevice2A,riid)) {
621 IDirectInputDevice2_AddRef(iface);
622 *ppobj = This;
623 return DI_OK;
625 if (IsEqualGUID(&IID_IDirectInputDevice7A,riid)) {
626 IDirectInputDevice7_AddRef(iface);
627 *ppobj = This;
628 return DI_OK;
630 if (IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
631 IDirectInputDevice8_AddRef(iface);
632 *ppobj = This;
633 return DI_OK;
635 TRACE("Unsupported interface !\n");
636 return E_FAIL;
639 HRESULT WINAPI IDirectInputDevice2WImpl_QueryInterface(
640 LPDIRECTINPUTDEVICE8W iface,REFIID riid,LPVOID *ppobj
643 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
645 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
646 if (IsEqualGUID(&IID_IUnknown,riid)) {
647 IDirectInputDevice2_AddRef(iface);
648 *ppobj = This;
649 return DI_OK;
651 if (IsEqualGUID(&IID_IDirectInputDeviceW,riid)) {
652 IDirectInputDevice2_AddRef(iface);
653 *ppobj = This;
654 return DI_OK;
656 if (IsEqualGUID(&IID_IDirectInputDevice2W,riid)) {
657 IDirectInputDevice2_AddRef(iface);
658 *ppobj = This;
659 return DI_OK;
661 if (IsEqualGUID(&IID_IDirectInputDevice7W,riid)) {
662 IDirectInputDevice7_AddRef(iface);
663 *ppobj = This;
664 return DI_OK;
666 if (IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
667 IDirectInputDevice8_AddRef(iface);
668 *ppobj = This;
669 return DI_OK;
671 TRACE("Unsupported interface !\n");
672 return E_FAIL;
675 ULONG WINAPI IDirectInputDevice2AImpl_AddRef(
676 LPDIRECTINPUTDEVICE8A iface)
678 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
679 return InterlockedIncrement(&(This->ref));
682 HRESULT WINAPI IDirectInputDevice2AImpl_EnumObjects(
683 LPDIRECTINPUTDEVICE8A iface,
684 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback,
685 LPVOID lpvRef,
686 DWORD dwFlags)
688 FIXME("(this=%p,%p,%p,%08x): stub!\n", iface, lpCallback, lpvRef, dwFlags);
689 if (TRACE_ON(dinput)) {
690 DPRINTF(" - flags = ");
691 _dump_EnumObjects_flags(dwFlags);
692 DPRINTF("\n");
695 return DI_OK;
698 HRESULT WINAPI IDirectInputDevice2WImpl_EnumObjects(
699 LPDIRECTINPUTDEVICE8W iface,
700 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback,
701 LPVOID lpvRef,
702 DWORD dwFlags)
704 FIXME("(this=%p,%p,%p,%08x): stub!\n", iface, lpCallback, lpvRef, dwFlags);
705 if (TRACE_ON(dinput)) {
706 DPRINTF(" - flags = ");
707 _dump_EnumObjects_flags(dwFlags);
708 DPRINTF("\n");
711 return DI_OK;
714 /******************************************************************************
715 * GetProperty
718 HRESULT WINAPI IDirectInputDevice2AImpl_GetProperty(
719 LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPDIPROPHEADER pdiph)
721 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
723 TRACE("(%p) %s,%p\n", iface, debugstr_guid(rguid), pdiph);
724 _dump_DIPROPHEADER(pdiph);
726 if (HIWORD(rguid)) return DI_OK;
728 switch (LOWORD(rguid))
730 case (DWORD) DIPROP_BUFFERSIZE:
732 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
734 if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
736 pd->dwData = This->queue_len;
737 TRACE("buffersize = %d\n", pd->dwData);
738 break;
740 default:
741 WARN("Unknown property %s\n", debugstr_guid(rguid));
742 break;
745 return DI_OK;
748 /******************************************************************************
749 * SetProperty
752 HRESULT WINAPI IDirectInputDevice2AImpl_SetProperty(
753 LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPCDIPROPHEADER pdiph)
755 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
757 TRACE("(%p) %s,%p\n", iface, debugstr_guid(rguid), pdiph);
758 _dump_DIPROPHEADER(pdiph);
760 if (HIWORD(rguid)) return DI_OK;
762 switch (LOWORD(rguid))
764 case (DWORD) DIPROP_BUFFERSIZE:
766 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph;
768 if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
769 if (This->acquired) return DIERR_ACQUIRED;
771 TRACE("buffersize = %d\n", pd->dwData);
773 EnterCriticalSection(&This->crit);
774 HeapFree(GetProcessHeap(), 0, This->data_queue);
776 This->data_queue = !pd->dwData ? NULL : HeapAlloc(GetProcessHeap(), 0,
777 pd->dwData * sizeof(DIDEVICEOBJECTDATA));
778 This->queue_head = This->queue_tail = This->overflow = 0;
779 This->queue_len = pd->dwData;
781 LeaveCriticalSection(&This->crit);
782 break;
784 default:
785 WARN("Unknown property %s\n", debugstr_guid(rguid));
786 return DIERR_UNSUPPORTED;
789 return DI_OK;
792 HRESULT WINAPI IDirectInputDevice2AImpl_GetObjectInfo(
793 LPDIRECTINPUTDEVICE8A iface,
794 LPDIDEVICEOBJECTINSTANCEA pdidoi,
795 DWORD dwObj,
796 DWORD dwHow)
798 FIXME("(this=%p,%p,%d,0x%08x): stub!\n",
799 iface, pdidoi, dwObj, dwHow);
801 return DI_OK;
804 HRESULT WINAPI IDirectInputDevice2WImpl_GetObjectInfo(
805 LPDIRECTINPUTDEVICE8W iface,
806 LPDIDEVICEOBJECTINSTANCEW pdidoi,
807 DWORD dwObj,
808 DWORD dwHow)
810 FIXME("(this=%p,%p,%d,0x%08x): stub!\n",
811 iface, pdidoi, dwObj, dwHow);
813 return DI_OK;
816 HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceData(
817 LPDIRECTINPUTDEVICE8A iface, DWORD dodsize, LPDIDEVICEOBJECTDATA dod,
818 LPDWORD entries, DWORD flags)
820 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
821 HRESULT ret = DI_OK;
822 int len;
824 TRACE("(%p) %p -> %p(%d) x%d, 0x%08x\n",
825 This, dod, entries, entries ? *entries : 0, dodsize, flags);
827 if (!This->acquired)
828 return DIERR_NOTACQUIRED;
829 if (!This->queue_len)
830 return DIERR_NOTBUFFERED;
831 if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3))
832 return DIERR_INVALIDPARAM;
834 IDirectInputDevice2_Poll(iface);
835 EnterCriticalSection(&This->crit);
837 len = This->queue_head - This->queue_tail;
838 if (len < 0) len += This->queue_len;
840 if ((*entries != INFINITE) && (len > *entries)) len = *entries;
842 if (dod)
844 int i;
845 for (i = 0; i < len; i++)
847 int n = (This->queue_tail + i) % This->queue_len;
848 memcpy((char *)dod + dodsize * i, This->data_queue + n, dodsize);
851 *entries = len;
853 if (This->overflow)
854 ret = DI_BUFFEROVERFLOW;
856 if (!(flags & DIGDD_PEEK))
858 /* Advance reading position */
859 This->queue_tail = (This->queue_tail + len) % This->queue_len;
860 This->overflow = FALSE;
863 LeaveCriticalSection(&This->crit);
865 TRACE("Returning %d events queued\n", *entries);
866 return ret;
869 HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceInfo(
870 LPDIRECTINPUTDEVICE8A iface,
871 LPDIDEVICEINSTANCEA pdidi)
873 FIXME("(this=%p,%p): stub!\n",
874 iface, pdidi);
876 return DI_OK;
879 HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceInfo(
880 LPDIRECTINPUTDEVICE8W iface,
881 LPDIDEVICEINSTANCEW pdidi)
883 FIXME("(this=%p,%p): stub!\n",
884 iface, pdidi);
886 return DI_OK;
889 HRESULT WINAPI IDirectInputDevice2AImpl_RunControlPanel(
890 LPDIRECTINPUTDEVICE8A iface,
891 HWND hwndOwner,
892 DWORD dwFlags)
894 FIXME("(this=%p,%p,0x%08x): stub!\n",
895 iface, hwndOwner, dwFlags);
897 return DI_OK;
900 HRESULT WINAPI IDirectInputDevice2AImpl_Initialize(
901 LPDIRECTINPUTDEVICE8A iface,
902 HINSTANCE hinst,
903 DWORD dwVersion,
904 REFGUID rguid)
906 FIXME("(this=%p,%p,%d,%s): stub!\n",
907 iface, hinst, dwVersion, debugstr_guid(rguid));
908 return DI_OK;
911 /******************************************************************************
912 * IDirectInputDevice2A
915 HRESULT WINAPI IDirectInputDevice2AImpl_CreateEffect(
916 LPDIRECTINPUTDEVICE8A iface,
917 REFGUID rguid,
918 LPCDIEFFECT lpeff,
919 LPDIRECTINPUTEFFECT *ppdef,
920 LPUNKNOWN pUnkOuter)
922 FIXME("(this=%p,%s,%p,%p,%p): stub!\n",
923 iface, debugstr_guid(rguid), lpeff, ppdef, pUnkOuter);
924 return DI_OK;
927 HRESULT WINAPI IDirectInputDevice2AImpl_EnumEffects(
928 LPDIRECTINPUTDEVICE8A iface,
929 LPDIENUMEFFECTSCALLBACKA lpCallback,
930 LPVOID lpvRef,
931 DWORD dwFlags)
933 FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
934 iface, lpCallback, lpvRef, dwFlags);
936 return DI_OK;
939 HRESULT WINAPI IDirectInputDevice2WImpl_EnumEffects(
940 LPDIRECTINPUTDEVICE8W iface,
941 LPDIENUMEFFECTSCALLBACKW lpCallback,
942 LPVOID lpvRef,
943 DWORD dwFlags)
945 FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
946 iface, lpCallback, lpvRef, dwFlags);
948 return DI_OK;
951 HRESULT WINAPI IDirectInputDevice2AImpl_GetEffectInfo(
952 LPDIRECTINPUTDEVICE8A iface,
953 LPDIEFFECTINFOA lpdei,
954 REFGUID rguid)
956 FIXME("(this=%p,%p,%s): stub!\n",
957 iface, lpdei, debugstr_guid(rguid));
958 return DI_OK;
961 HRESULT WINAPI IDirectInputDevice2WImpl_GetEffectInfo(
962 LPDIRECTINPUTDEVICE8W iface,
963 LPDIEFFECTINFOW lpdei,
964 REFGUID rguid)
966 FIXME("(this=%p,%p,%s): stub!\n",
967 iface, lpdei, debugstr_guid(rguid));
968 return DI_OK;
971 HRESULT WINAPI IDirectInputDevice2AImpl_GetForceFeedbackState(
972 LPDIRECTINPUTDEVICE8A iface,
973 LPDWORD pdwOut)
975 FIXME("(this=%p,%p): stub!\n",
976 iface, pdwOut);
977 return DI_OK;
980 HRESULT WINAPI IDirectInputDevice2AImpl_SendForceFeedbackCommand(
981 LPDIRECTINPUTDEVICE8A iface,
982 DWORD dwFlags)
984 FIXME("(this=%p,0x%08x): stub!\n",
985 iface, dwFlags);
986 return DI_OK;
989 HRESULT WINAPI IDirectInputDevice2AImpl_EnumCreatedEffectObjects(
990 LPDIRECTINPUTDEVICE8A iface,
991 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback,
992 LPVOID lpvRef,
993 DWORD dwFlags)
995 FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
996 iface, lpCallback, lpvRef, dwFlags);
997 return DI_OK;
1000 HRESULT WINAPI IDirectInputDevice2AImpl_Escape(
1001 LPDIRECTINPUTDEVICE8A iface,
1002 LPDIEFFESCAPE lpDIEEsc)
1004 FIXME("(this=%p,%p): stub!\n",
1005 iface, lpDIEEsc);
1006 return DI_OK;
1009 HRESULT WINAPI IDirectInputDevice2AImpl_Poll(
1010 LPDIRECTINPUTDEVICE8A iface)
1012 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
1014 if (!This->acquired) return DIERR_NOTACQUIRED;
1015 /* Because wine devices do not need to be polled, just return DI_NOEFFECT */
1016 return DI_NOEFFECT;
1019 HRESULT WINAPI IDirectInputDevice2AImpl_SendDeviceData(
1020 LPDIRECTINPUTDEVICE8A iface,
1021 DWORD cbObjectData,
1022 LPCDIDEVICEOBJECTDATA rgdod,
1023 LPDWORD pdwInOut,
1024 DWORD dwFlags)
1026 FIXME("(this=%p,0x%08x,%p,%p,0x%08x): stub!\n",
1027 iface, cbObjectData, rgdod, pdwInOut, dwFlags);
1029 return DI_OK;
1032 HRESULT WINAPI IDirectInputDevice7AImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8A iface,
1033 LPCSTR lpszFileName,
1034 LPDIENUMEFFECTSINFILECALLBACK pec,
1035 LPVOID pvRef,
1036 DWORD dwFlags)
1038 FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", iface, lpszFileName, pec, pvRef, dwFlags);
1040 return DI_OK;
1043 HRESULT WINAPI IDirectInputDevice7WImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8W iface,
1044 LPCWSTR lpszFileName,
1045 LPDIENUMEFFECTSINFILECALLBACK pec,
1046 LPVOID pvRef,
1047 DWORD dwFlags)
1049 FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", iface, debugstr_w(lpszFileName), pec, pvRef, dwFlags);
1051 return DI_OK;
1054 HRESULT WINAPI IDirectInputDevice7AImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8A iface,
1055 LPCSTR lpszFileName,
1056 DWORD dwEntries,
1057 LPDIFILEEFFECT rgDiFileEft,
1058 DWORD dwFlags)
1060 FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", iface, lpszFileName, dwEntries, rgDiFileEft, dwFlags);
1062 return DI_OK;
1065 HRESULT WINAPI IDirectInputDevice7WImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8W iface,
1066 LPCWSTR lpszFileName,
1067 DWORD dwEntries,
1068 LPDIFILEEFFECT rgDiFileEft,
1069 DWORD dwFlags)
1071 FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", iface, debugstr_w(lpszFileName), dwEntries, rgDiFileEft, dwFlags);
1073 return DI_OK;
1076 HRESULT WINAPI IDirectInputDevice8AImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface,
1077 LPDIACTIONFORMATA lpdiaf,
1078 LPCSTR lpszUserName,
1079 DWORD dwFlags)
1081 FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, lpszUserName, dwFlags);
1083 return DI_OK;
1086 HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface,
1087 LPDIACTIONFORMATW lpdiaf,
1088 LPCWSTR lpszUserName,
1089 DWORD dwFlags)
1091 FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
1093 return DI_OK;
1096 HRESULT WINAPI IDirectInputDevice8AImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface,
1097 LPDIACTIONFORMATA lpdiaf,
1098 LPCSTR lpszUserName,
1099 DWORD dwFlags)
1101 FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, lpszUserName, dwFlags);
1103 return DI_OK;
1106 HRESULT WINAPI IDirectInputDevice8WImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
1107 LPDIACTIONFORMATW lpdiaf,
1108 LPCWSTR lpszUserName,
1109 DWORD dwFlags)
1111 FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
1113 return DI_OK;
1116 HRESULT WINAPI IDirectInputDevice8AImpl_GetImageInfo(LPDIRECTINPUTDEVICE8A iface,
1117 LPDIDEVICEIMAGEINFOHEADERA lpdiDevImageInfoHeader)
1119 FIXME("(%p)->(%p): stub !\n", iface, lpdiDevImageInfoHeader);
1121 return DI_OK;
1124 HRESULT WINAPI IDirectInputDevice8WImpl_GetImageInfo(LPDIRECTINPUTDEVICE8W iface,
1125 LPDIDEVICEIMAGEINFOHEADERW lpdiDevImageInfoHeader)
1127 FIXME("(%p)->(%p): stub !\n", iface, lpdiDevImageInfoHeader);
1129 return DI_OK;