dmloader: Declare some functions static.
[wine] / dlls / dinput / device.c
1 /*              DirectInput Device
2  *
3  * Copyright 1998 Marcus Meissner
4  * Copyright 1998,1999 Lionel Ulmer
5  *
6  *
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.
11  *
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.
16  *
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
20  */
21
22 /* This file contains all the Device specific functions that can be used as stubs
23    by real device implementations.
24
25    It also contains all the helper functions.
26 */
27 #include "config.h"
28
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"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
42
43 /******************************************************************************
44  *      Various debugging tools
45  */
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
60         };
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");
65     }
66 }
67
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
91         };
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);
102                 }
103             }
104             if (type) {
105                 DPRINTF(" (unhandled: %08x)", type);
106             }
107         }
108         DPRINTF(" / Instance: ");
109         if (instance == ((DIDFT_ANYINSTANCE >> 8) & 0xFFFF)) {
110             DPRINTF("DIDFT_ANYINSTANCE");
111         } else {
112             DPRINTF("%3d", instance);
113         }
114     }
115 }
116
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")));
124     }
125 }
126
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);
131     }
132 }
133
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));
138     }
139 }
140
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
176     };
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;
182         }
183     }
184     return "Unknown GUID";
185 }
186
187 void _dump_DIDATAFORMAT(const DIDATAFORMAT *df) {
188     unsigned int i;
189
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);
194     }
195     TRACE("  - dwObjsize: %d\n", df->dwObjSize);
196     if (df->dwObjSize != sizeof(DIOBJECTDATAFORMAT)) {
197         WARN("Non-standard DIOBJECTDATAFORMAT structure size %d\n", df->dwObjSize);
198     }
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;
204     }
205     TRACE(")\n");
206     TRACE("  - dwDataSize: %d\n", df->dwDataSize);
207     TRACE("  - dwNumObjs: %d\n", df->dwNumObjs);
208     
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);
216     }
217 }
218
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;
224
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;
237
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;
243
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;
249
250                     default:
251                         memcpy((out_c + df->dt[i].offset_out), (in_c + df->dt[i].offset_in), df->dt[i].size);
252                         break;
253                 }
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;
261                         
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;
267                         
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;
273                         
274                     default:
275                         memset((out_c + df->dt[i].offset_out), 0, df->dt[i].size);
276                         break;
277                 }
278             }
279         }
280     }
281 }
282
283 void release_DataFormat(DataFormat * format)
284 {
285     TRACE("Deleting DataFormat: %p\n", format);
286
287     HeapFree(GetProcessHeap(), 0, format->dt);
288     format->dt = NULL;
289     HeapFree(GetProcessHeap(), 0, format->offsets);
290     format->offsets = NULL;
291     if (format->user_df)
292         HeapFree(GetProcessHeap(), 0, format->user_df->rgodf);
293     HeapFree(GetProcessHeap(), 0, format->user_df);
294     format->user_df = NULL;
295 }
296
297 inline LPDIOBJECTDATAFORMAT dataformat_to_odf(LPCDIDATAFORMAT df, int idx)
298 {
299     if (idx < 0 || idx >= df->dwNumObjs) return NULL;
300     return (LPDIOBJECTDATAFORMAT)((LPBYTE)df->rgodf + idx * df->dwObjSize);
301 }
302
303 /* Make all instances sequential */
304 static void calculate_ids(LPDIDATAFORMAT df)
305 {
306     int i, axis = 0, pov = 0, button = 0;
307     int axis_base, pov_base, button_base;
308     DWORD type;
309
310     /* Make two passes over the format. The first counts the number
311      * for each type and the second sets the id */
312     for (i = 0; i < df->dwNumObjs; i++)
313     {
314         type = DIDFT_GETTYPE(df->rgodf[i].dwType);
315         if      (type & DIDFT_AXIS)   axis++;
316         else if (type & DIDFT_POV)    pov++;
317         else if (type & DIDFT_BUTTON) button++;
318     }
319
320     axis_base   = 0;
321     pov_base    = axis_base + axis;
322     button_base = pov_base + pov;
323     axis = pov = button = 0;
324
325     for (i = 0; i < df->dwNumObjs; i++)
326     {
327         type = DIDFT_GETTYPE(df->rgodf[i].dwType);
328         if (type & DIDFT_AXIS)
329         {
330             type |= DIDFT_MAKEINSTANCE(axis_base + axis++);
331             TRACE("axis type = 0x%08x\n", type);
332         } else if (type & DIDFT_POV)
333         {
334             type |= DIDFT_MAKEINSTANCE(pov_base + pov++);
335             TRACE("POV type = 0x%08x\n", type);
336         } else if (type & DIDFT_BUTTON)
337         {
338             type |= DIDFT_MAKEINSTANCE(button_base + button++);
339             TRACE("button type = 0x%08x\n", type);
340         }
341         df->rgodf[i].dwType = type;
342     }
343 }
344
345 HRESULT create_DataFormat(LPCDIDATAFORMAT asked_format, DataFormat *format)
346 {
347     DataTransform *dt;
348     unsigned int i, j;
349     int same = 1;
350     int *done;
351     int index = 0;
352     DWORD next = 0;
353
354     if (!format->wine_df) return DIERR_INVALIDPARAM;
355     done = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, asked_format->dwNumObjs * sizeof(int));
356     dt = HeapAlloc(GetProcessHeap(), 0, asked_format->dwNumObjs * sizeof(DataTransform));
357     if (!dt || !done) goto failed;
358
359     if (!(format->offsets = HeapAlloc(GetProcessHeap(), 0, format->wine_df->dwNumObjs * sizeof(int))))
360         goto failed;
361
362     if (!(format->user_df = HeapAlloc(GetProcessHeap(), 0, asked_format->dwSize)))
363         goto failed;
364     memcpy(format->user_df, asked_format, asked_format->dwSize);
365
366     if (!(format->user_df->rgodf = HeapAlloc(GetProcessHeap(), 0, asked_format->dwNumObjs*asked_format->dwObjSize)))
367         goto failed;
368     memcpy(format->user_df->rgodf, asked_format->rgodf, asked_format->dwNumObjs*asked_format->dwObjSize);
369
370     TRACE("Creating DataTransform :\n");
371     
372     for (i = 0; i < format->wine_df->dwNumObjs; i++)
373     {
374         format->offsets[i] = -1;
375
376         for (j = 0; j < asked_format->dwNumObjs; j++) {
377             if (done[j] == 1)
378                 continue;
379             
380             if (/* Check if the application either requests any GUID and if not, it if matches
381                  * the GUID of the Wine object.
382                  */
383                 ((asked_format->rgodf[j].pguid == NULL) ||
384                  (format->wine_df->rgodf[i].pguid == NULL) ||
385                  (IsEqualGUID(format->wine_df->rgodf[i].pguid, asked_format->rgodf[j].pguid)))
386                 &&
387                 (/* Then check if it accepts any instance id, and if not, if it matches Wine's
388                   * instance id.
389                   */
390                  ((asked_format->rgodf[j].dwType & DIDFT_INSTANCEMASK) == DIDFT_ANYINSTANCE) ||
391                  (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == 0x00FF) || /* This is mentionned in no DX docs, but it works fine - tested on WinXP */
392                  (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == DIDFT_GETINSTANCE(format->wine_df->rgodf[i].dwType)))
393                 &&
394                 ( /* Then if the asked type matches the one Wine provides */
395                  DIDFT_GETTYPE(asked_format->rgodf[j].dwType) & format->wine_df->rgodf[i].dwType))
396             {
397                 done[j] = 1;
398                 
399                 TRACE("Matching :\n");
400                 TRACE("   - Asked (%d) :\n", j);
401                 TRACE("       * GUID: %s ('%s')\n",
402                       debugstr_guid(asked_format->rgodf[j].pguid),
403                       _dump_dinput_GUID(asked_format->rgodf[j].pguid));
404                 TRACE("       * Offset: %3d\n", asked_format->rgodf[j].dwOfs);
405                 TRACE("       * dwType: %08x\n", asked_format->rgodf[j].dwType);
406                 TRACE("         "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
407                 
408                 TRACE("   - Wine  (%d) :\n", i);
409                 TRACE("       * GUID: %s ('%s')\n",
410                       debugstr_guid(format->wine_df->rgodf[i].pguid),
411                       _dump_dinput_GUID(format->wine_df->rgodf[i].pguid));
412                 TRACE("       * Offset: %3d\n", format->wine_df->rgodf[i].dwOfs);
413                 TRACE("       * dwType: %08x\n", format->wine_df->rgodf[i].dwType);
414                 TRACE("         "); _dump_EnumObjects_flags(format->wine_df->rgodf[i].dwType); TRACE("\n");
415                 
416                 if (format->wine_df->rgodf[i].dwType & DIDFT_BUTTON)
417                     dt[index].size = sizeof(BYTE);
418                 else
419                     dt[index].size = sizeof(DWORD);
420                 dt[index].offset_in = format->wine_df->rgodf[i].dwOfs;
421                 dt[index].offset_out = asked_format->rgodf[j].dwOfs;
422                 format->offsets[i]   = asked_format->rgodf[j].dwOfs;
423                 dt[index].value = 0;
424                 next = next + dt[index].size;
425                 
426                 if (format->wine_df->rgodf[i].dwOfs != dt[index].offset_out)
427                     same = 0;
428                 
429                 index++;
430                 break;
431             }
432         }
433         
434         if (j == asked_format->dwNumObjs)
435             same = 0;
436     }
437     
438     TRACE("Setting to default value :\n");
439     for (j = 0; j < asked_format->dwNumObjs; j++) {
440         if (done[j] == 0) {
441             TRACE("   - Asked (%d) :\n", j);
442             TRACE("       * GUID: %s ('%s')\n",
443                   debugstr_guid(asked_format->rgodf[j].pguid),
444                   _dump_dinput_GUID(asked_format->rgodf[j].pguid));
445             TRACE("       * Offset: %3d\n", asked_format->rgodf[j].dwOfs);
446             TRACE("       * dwType: %08x\n", asked_format->rgodf[j].dwType);
447             TRACE("         "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
448             
449             if (asked_format->rgodf[j].dwType & DIDFT_BUTTON)
450                 dt[index].size = sizeof(BYTE);
451             else
452                 dt[index].size = sizeof(DWORD);
453             dt[index].offset_in  = -1;
454             dt[index].offset_out = asked_format->rgodf[j].dwOfs;
455             dt[index].value = 0;
456             index++;
457             
458             same = 0;
459         }
460     }
461     
462     format->internal_format_size = format->wine_df->dwDataSize;
463     format->size = index;
464     if (same) {
465         HeapFree(GetProcessHeap(), 0, dt);
466         dt = NULL;
467     }
468     format->dt = dt;
469
470     HeapFree(GetProcessHeap(), 0, done);
471
472     /* Last step - reset all instances of the new format */
473     calculate_ids(format->user_df);
474     return DI_OK;
475
476 failed:
477     HeapFree(GetProcessHeap(), 0, done);
478     HeapFree(GetProcessHeap(), 0, dt);
479     format->dt = NULL;
480     HeapFree(GetProcessHeap(), 0, format->offsets);
481     format->offsets = NULL;
482     if (format->user_df)
483         HeapFree(GetProcessHeap(), 0, format->user_df->rgodf);
484     HeapFree(GetProcessHeap(), 0, format->user_df);
485     format->user_df = NULL;
486
487     return DIERR_OUTOFMEMORY;
488 }
489
490 /* find an object by it's offset in a data format */
491 int offset_to_object(LPCDIDATAFORMAT df, int offset)
492 {
493     int i;
494
495     for (i = 0; i < df->dwNumObjs; i++)
496         if (df->rgodf[i].dwOfs == offset)
497             return i;
498
499     return -1;
500 }
501
502 static int id_to_object(LPCDIDATAFORMAT df, int id)
503 {
504     int i;
505
506     for (i = 0; i < df->dwNumObjs; i++)
507         if ((df->rgodf[i].dwType & 0x00ffffff) == (id & 0x00ffffff))
508             return i;
509
510     return -1;
511 }
512
513 int find_property(LPCDIDATAFORMAT df, LPCDIPROPHEADER ph)
514 {
515     switch (ph->dwHow)
516     {
517         case DIPH_BYID:     return id_to_object(df, ph->dwObj);
518         case DIPH_BYOFFSET: return offset_to_object(df, ph->dwObj);
519     }
520     FIXME("Unhandled ph->dwHow=='%04X'\n", (unsigned int)ph->dwHow);
521
522     return -1;
523 }
524
525
526 BOOL DIEnumDevicesCallbackAtoW(LPCDIDEVICEOBJECTINSTANCEA lpddi, LPVOID lpvRef) {
527     DIDEVICEOBJECTINSTANCEW ddtmp;
528     device_enumobjects_AtoWcb_data* data;
529
530     data = (device_enumobjects_AtoWcb_data*) lpvRef;
531     
532     memset(&ddtmp, 0, sizeof(ddtmp));
533     
534     ddtmp.dwSize = sizeof(DIDEVICEINSTANCEW);
535     ddtmp.guidType     = lpddi->guidType;
536     ddtmp.dwOfs        = lpddi->dwOfs;
537     ddtmp.dwType       = lpddi->dwType;
538     ddtmp.dwFlags      = lpddi->dwFlags;
539     MultiByteToWideChar(CP_ACP, 0, lpddi->tszName, -1, ddtmp.tszName, MAX_PATH);
540     
541     if (lpddi->dwSize == sizeof(DIDEVICEINSTANCEA)) {
542         /**
543          * if dwSize < sizeof(DIDEVICEINSTANCEA of DInput version >= 5)
544          *  force feedback and other newer datas aren't available
545          */
546         ddtmp.dwFFMaxForce        = lpddi->dwFFMaxForce;
547         ddtmp.dwFFForceResolution = lpddi->dwFFForceResolution;
548         ddtmp.wCollectionNumber   = lpddi->wCollectionNumber;
549         ddtmp.wDesignatorIndex    = lpddi->wDesignatorIndex;
550         ddtmp.wUsagePage          = lpddi->wUsagePage;
551         ddtmp.wUsage              = lpddi->wUsage;
552         ddtmp.dwDimension         = lpddi->dwDimension;
553         ddtmp.wExponent           = lpddi->wExponent;
554         ddtmp.wReserved           = lpddi->wReserved;
555     }
556     return data->lpCallBack(&ddtmp, data->lpvRef);
557 }
558
559 /******************************************************************************
560  *      queue_event - add new event to the ring queue
561  */
562
563 void queue_event(LPDIRECTINPUTDEVICE8A iface, int ofs, DWORD data, DWORD time, DWORD seq)
564 {
565     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
566     int next_pos;
567
568     if (!This->queue_len || This->overflow || ofs < 0) return;
569
570     next_pos = (This->queue_head + 1) % This->queue_len;
571     if (next_pos == This->queue_tail)
572     {
573         TRACE(" queue overflowed\n");
574         This->overflow = TRUE;
575         return;
576     }
577
578     TRACE(" queueing %d at offset %d (queue head %d / size %d)\n",
579           data, ofs, This->queue_head, This->queue_len);
580
581     This->data_queue[This->queue_head].dwOfs       = ofs;
582     This->data_queue[This->queue_head].dwData      = data;
583     This->data_queue[This->queue_head].dwTimeStamp = time;
584     This->data_queue[This->queue_head].dwSequence  = seq;
585     This->queue_head = next_pos;
586 }
587
588 /******************************************************************************
589  *      Acquire
590  */
591
592 HRESULT WINAPI IDirectInputDevice2AImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
593 {
594     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
595     HRESULT res;
596
597     if (!This->data_format.user_df) return DIERR_INVALIDPARAM;
598
599     EnterCriticalSection(&This->crit);
600     res = This->acquired ? S_FALSE : DI_OK;
601     This->acquired = 1;
602     if (res == DI_OK)
603         This->queue_head = This->queue_tail = This->overflow = 0;
604     LeaveCriticalSection(&This->crit);
605
606     return res;
607 }
608
609 /******************************************************************************
610  *      Unacquire
611  */
612
613 HRESULT WINAPI IDirectInputDevice2AImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
614 {
615     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
616     HRESULT res;
617
618     EnterCriticalSection(&This->crit);
619     res = !This->acquired ? DI_NOEFFECT : DI_OK;
620     This->acquired = 0;
621     LeaveCriticalSection(&This->crit);
622
623     return res;
624 }
625
626 /******************************************************************************
627  *      IDirectInputDeviceA
628  */
629
630 HRESULT WINAPI IDirectInputDevice2AImpl_SetDataFormat(
631         LPDIRECTINPUTDEVICE8A iface, LPCDIDATAFORMAT df)
632 {
633     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
634     HRESULT res = DI_OK;
635
636     if (!df) return E_POINTER;
637     TRACE("(%p) %p\n", This, df);
638     _dump_DIDATAFORMAT(df);
639
640     if (df->dwSize != sizeof(DIDATAFORMAT)) return DIERR_INVALIDPARAM;
641     if (This->acquired) return DIERR_ACQUIRED;
642
643     EnterCriticalSection(&This->crit);
644
645     release_DataFormat(&This->data_format);
646     res = create_DataFormat(df, &This->data_format);
647
648     LeaveCriticalSection(&This->crit);
649     return res;
650 }
651
652 /******************************************************************************
653   *     SetCooperativeLevel
654   *
655   *  Set cooperative level and the source window for the events.
656   */
657 HRESULT WINAPI IDirectInputDevice2AImpl_SetCooperativeLevel(
658         LPDIRECTINPUTDEVICE8A iface, HWND hwnd, DWORD dwflags)
659 {
660     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
661
662     TRACE("(%p) %p,0x%08x\n", This, hwnd, dwflags);
663     TRACE(" cooperative level : ");
664     _dump_cooperativelevel_DI(dwflags);
665
666     if ((dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == 0 ||
667         (dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE) ||
668         (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == 0 ||
669         (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == (DISCL_FOREGROUND | DISCL_BACKGROUND))
670         return DIERR_INVALIDPARAM;
671
672     if (dwflags == (DISCL_NONEXCLUSIVE | DISCL_BACKGROUND))
673         hwnd = GetDesktopWindow();
674
675     if (!hwnd) return E_HANDLE;
676
677     /* For security reasons native does not allow exclusive background level
678        for mouse and keyboard only */
679     if (dwflags & DISCL_EXCLUSIVE && dwflags & DISCL_BACKGROUND &&
680         (IsEqualGUID(&This->guid, &GUID_SysMouse) ||
681          IsEqualGUID(&This->guid, &GUID_SysKeyboard)))
682         return DIERR_UNSUPPORTED;
683
684     /* Store the window which asks for the mouse */
685     EnterCriticalSection(&This->crit);
686     This->win = hwnd;
687     This->dwCoopLevel = dwflags;
688     LeaveCriticalSection(&This->crit);
689
690     return DI_OK;
691 }
692
693 /******************************************************************************
694   *     SetEventNotification : specifies event to be sent on state change
695   */
696 HRESULT WINAPI IDirectInputDevice2AImpl_SetEventNotification(
697         LPDIRECTINPUTDEVICE8A iface, HANDLE event)
698 {
699     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
700
701     TRACE("(%p) %p\n", This, event);
702
703     EnterCriticalSection(&This->crit);
704     This->hEvent = event;
705     LeaveCriticalSection(&This->crit);
706     return DI_OK;
707 }
708
709 ULONG WINAPI IDirectInputDevice2AImpl_Release(LPDIRECTINPUTDEVICE8A iface)
710 {
711     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
712     ULONG ref;
713
714     ref = InterlockedDecrement(&(This->ref));
715     if (ref) return ref;
716
717     DeleteCriticalSection(&This->crit);
718     HeapFree(GetProcessHeap(), 0, This->data_queue);
719     HeapFree(GetProcessHeap(), 0, This);
720
721     return DI_OK;
722 }
723
724 HRESULT WINAPI IDirectInputDevice2AImpl_QueryInterface(
725         LPDIRECTINPUTDEVICE8A iface,REFIID riid,LPVOID *ppobj
726 )
727 {
728     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
729     
730     TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
731     if (IsEqualGUID(&IID_IUnknown,riid)) {
732         IDirectInputDevice2_AddRef(iface);
733         *ppobj = This;
734         return DI_OK;
735     }
736     if (IsEqualGUID(&IID_IDirectInputDeviceA,riid)) {
737         IDirectInputDevice2_AddRef(iface);
738         *ppobj = This;
739         return DI_OK;
740     }
741     if (IsEqualGUID(&IID_IDirectInputDevice2A,riid)) {
742         IDirectInputDevice2_AddRef(iface);
743         *ppobj = This;
744         return DI_OK;
745     }
746     if (IsEqualGUID(&IID_IDirectInputDevice7A,riid)) {
747         IDirectInputDevice7_AddRef(iface);
748         *ppobj = This;
749         return DI_OK;
750     }
751     if (IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
752         IDirectInputDevice8_AddRef(iface);
753         *ppobj = This;
754         return DI_OK;
755     }
756     TRACE("Unsupported interface !\n");
757     return E_FAIL;
758 }
759
760 HRESULT WINAPI IDirectInputDevice2WImpl_QueryInterface(
761         LPDIRECTINPUTDEVICE8W iface,REFIID riid,LPVOID *ppobj
762 )
763 {
764     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
765     
766     TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
767     if (IsEqualGUID(&IID_IUnknown,riid)) {
768         IDirectInputDevice2_AddRef(iface);
769         *ppobj = This;
770         return DI_OK;
771     }
772     if (IsEqualGUID(&IID_IDirectInputDeviceW,riid)) {
773         IDirectInputDevice2_AddRef(iface);
774         *ppobj = This;
775         return DI_OK;
776     }
777     if (IsEqualGUID(&IID_IDirectInputDevice2W,riid)) {
778         IDirectInputDevice2_AddRef(iface);
779         *ppobj = This;
780         return DI_OK;
781     }
782     if (IsEqualGUID(&IID_IDirectInputDevice7W,riid)) {
783         IDirectInputDevice7_AddRef(iface);
784         *ppobj = This;
785         return DI_OK;
786     }
787     if (IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
788         IDirectInputDevice8_AddRef(iface);
789         *ppobj = This;
790         return DI_OK;
791     }
792     TRACE("Unsupported interface !\n");
793     return E_FAIL;
794 }
795
796 ULONG WINAPI IDirectInputDevice2AImpl_AddRef(
797         LPDIRECTINPUTDEVICE8A iface)
798 {
799     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
800     return InterlockedIncrement(&(This->ref));
801 }
802
803 HRESULT WINAPI IDirectInputDevice2AImpl_EnumObjects(LPDIRECTINPUTDEVICE8A iface,
804         LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback, LPVOID lpvRef, DWORD dwFlags)
805 {
806     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
807     DIDEVICEOBJECTINSTANCEA ddoi;
808     int i;
809
810     TRACE("(%p) %p,%p flags:%08x)\n", iface, lpCallback, lpvRef, dwFlags);
811     TRACE("  - flags = ");
812     _dump_EnumObjects_flags(dwFlags);
813     TRACE("\n");
814
815     /* Only the fields till dwFFMaxForce are relevant */
816     memset(&ddoi, 0, sizeof(ddoi));
817     ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce);
818
819     for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++)
820     {
821         LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(This->data_format.wine_df, i);
822
823         if (dwFlags != DIDFT_ALL && !(dwFlags & DIEFT_GETTYPE(odf->dwType))) continue;
824         if (IDirectInputDevice_GetObjectInfo(iface, &ddoi, odf->dwType, DIPH_BYID) != DI_OK)
825             continue;
826
827         if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) break;
828     }
829
830     return DI_OK;
831 }
832
833 HRESULT WINAPI IDirectInputDevice2WImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface,
834         LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback, LPVOID lpvRef, DWORD dwFlags)
835 {
836     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
837     DIDEVICEOBJECTINSTANCEW ddoi;
838     int i;
839
840     TRACE("(%p) %p,%p flags:%08x)\n", iface, lpCallback, lpvRef, dwFlags);
841     TRACE("  - flags = ");
842     _dump_EnumObjects_flags(dwFlags);
843     TRACE("\n");
844
845     /* Only the fields till dwFFMaxForce are relevant */
846     memset(&ddoi, 0, sizeof(ddoi));
847     ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEW, dwFFMaxForce);
848
849     for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++)
850     {
851         LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(This->data_format.wine_df, i);
852
853         if (dwFlags != DIDFT_ALL && !(dwFlags & DIEFT_GETTYPE(odf->dwType))) continue;
854         if (IDirectInputDevice_GetObjectInfo(iface, &ddoi, odf->dwType, DIPH_BYID) != DI_OK)
855             continue;
856
857         if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) break;
858     }
859
860     return DI_OK;
861 }
862
863 /******************************************************************************
864  *      GetProperty
865  */
866
867 HRESULT WINAPI IDirectInputDevice2AImpl_GetProperty(
868         LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPDIPROPHEADER pdiph)
869 {
870     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
871
872     TRACE("(%p) %s,%p\n", iface, debugstr_guid(rguid), pdiph);
873     _dump_DIPROPHEADER(pdiph);
874
875     if (HIWORD(rguid)) return DI_OK;
876
877     switch (LOWORD(rguid))
878     {
879         case (DWORD) DIPROP_BUFFERSIZE:
880         {
881             LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
882
883             if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
884
885             pd->dwData = This->queue_len;
886             TRACE("buffersize = %d\n", pd->dwData);
887             break;
888         }
889         default:
890             WARN("Unknown property %s\n", debugstr_guid(rguid));
891             break;
892     }
893
894     return DI_OK;
895 }
896
897 /******************************************************************************
898  *      SetProperty
899  */
900
901 HRESULT WINAPI IDirectInputDevice2AImpl_SetProperty(
902         LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPCDIPROPHEADER pdiph)
903 {
904     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
905
906     TRACE("(%p) %s,%p\n", iface, debugstr_guid(rguid), pdiph);
907     _dump_DIPROPHEADER(pdiph);
908
909     if (HIWORD(rguid)) return DI_OK;
910
911     switch (LOWORD(rguid))
912     {
913         case (DWORD) DIPROP_AXISMODE:
914         {
915             LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph;
916
917             if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
918             if (pdiph->dwHow == DIPH_DEVICE && pdiph->dwObj) return DIERR_INVALIDPARAM;
919             if (This->acquired) return DIERR_ACQUIRED;
920             if (pdiph->dwHow != DIPH_DEVICE) return DIERR_UNSUPPORTED;
921             if (!This->data_format.user_df) return DI_OK;
922
923             TRACE("Axis mode: %s\n", pd->dwData == DIPROPAXISMODE_ABS ? "absolute" :
924                                                                         "relative");
925
926             EnterCriticalSection(&This->crit);
927             This->data_format.user_df->dwFlags &= ~DIDFT_AXIS;
928             This->data_format.user_df->dwFlags |= pd->dwData == DIPROPAXISMODE_ABS ?
929                                                   DIDF_ABSAXIS : DIDF_RELAXIS;
930             LeaveCriticalSection(&This->crit);
931             break;
932         }
933         case (DWORD) DIPROP_BUFFERSIZE:
934         {
935             LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph;
936
937             if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
938             if (This->acquired) return DIERR_ACQUIRED;
939
940             TRACE("buffersize = %d\n", pd->dwData);
941
942             EnterCriticalSection(&This->crit);
943             HeapFree(GetProcessHeap(), 0, This->data_queue);
944
945             This->data_queue = !pd->dwData ? NULL : HeapAlloc(GetProcessHeap(), 0,
946                                 pd->dwData * sizeof(DIDEVICEOBJECTDATA));
947             This->queue_head = This->queue_tail = This->overflow = 0;
948             This->queue_len  = pd->dwData;
949
950             LeaveCriticalSection(&This->crit);
951             break;
952         }
953         default:
954             WARN("Unknown property %s\n", debugstr_guid(rguid));
955             return DIERR_UNSUPPORTED;
956     }
957
958     return DI_OK;
959 }
960
961 HRESULT WINAPI IDirectInputDevice2AImpl_GetObjectInfo(
962         LPDIRECTINPUTDEVICE8A iface,
963         LPDIDEVICEOBJECTINSTANCEA pdidoi,
964         DWORD dwObj,
965         DWORD dwHow)
966 {
967     DIDEVICEOBJECTINSTANCEW didoiW;
968     HRESULT res;
969
970     if (!pdidoi ||
971         (pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCEA) &&
972          pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCE_DX3A)))
973         return DIERR_INVALIDPARAM;
974
975     didoiW.dwSize = sizeof(didoiW);
976     res = IDirectInputDevice2WImpl_GetObjectInfo((LPDIRECTINPUTDEVICE8W)iface, &didoiW, dwObj, dwHow);
977     if (res == DI_OK)
978     {
979         DWORD dwSize = pdidoi->dwSize;
980
981         memset(pdidoi, 0, pdidoi->dwSize);
982         pdidoi->dwSize   = dwSize;
983         pdidoi->guidType = didoiW.guidType;
984         pdidoi->dwOfs    = didoiW.dwOfs;
985         pdidoi->dwType   = didoiW.dwType;
986         pdidoi->dwFlags  = didoiW.dwFlags;
987     }
988
989     return res;
990 }
991
992 HRESULT WINAPI IDirectInputDevice2WImpl_GetObjectInfo(
993         LPDIRECTINPUTDEVICE8W iface,
994         LPDIDEVICEOBJECTINSTANCEW pdidoi,
995         DWORD dwObj,
996         DWORD dwHow)
997 {
998     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
999     DWORD dwSize = pdidoi->dwSize;
1000     LPDIOBJECTDATAFORMAT odf;
1001     int idx = -1;
1002
1003     TRACE("(%p) %d(0x%08x) -> %p\n", This, dwHow, dwObj, pdidoi);
1004
1005     if (!pdidoi ||
1006         (pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCEW) &&
1007          pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCE_DX3W)))
1008         return DIERR_INVALIDPARAM;
1009
1010     switch (dwHow)
1011     {
1012     case DIPH_BYOFFSET:
1013         if (!This->data_format.offsets) break;
1014         for (idx = This->data_format.wine_df->dwNumObjs - 1; idx >= 0; idx--)
1015             if (This->data_format.offsets[idx] == dwObj) break;
1016         break;
1017     case DIPH_BYID:
1018         dwObj &= 0x00ffffff;
1019         for (idx = This->data_format.wine_df->dwNumObjs - 1; idx >= 0; idx--)
1020             if ((dataformat_to_odf(This->data_format.wine_df, idx)->dwType & 0x00ffffff) == dwObj)
1021                 break;
1022         break;
1023
1024     case DIPH_BYUSAGE:
1025         FIXME("dwHow = DIPH_BYUSAGE not implemented\n");
1026         break;
1027     default:
1028         WARN("invalid parameter: dwHow = %08x\n", dwHow);
1029         return DIERR_INVALIDPARAM;
1030     }
1031     if (idx < 0) return DIERR_OBJECTNOTFOUND;
1032
1033     odf = dataformat_to_odf(This->data_format.wine_df, idx);
1034     memset(pdidoi, 0, pdidoi->dwSize);
1035     pdidoi->dwSize   = dwSize;
1036     pdidoi->guidType = *odf->pguid;
1037     pdidoi->dwOfs    = This->data_format.offsets ? This->data_format.offsets[idx] : odf->dwOfs;
1038     pdidoi->dwType   = odf->dwType;
1039     pdidoi->dwFlags  = odf->dwFlags;
1040
1041     return DI_OK;
1042 }
1043
1044 HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceData(
1045         LPDIRECTINPUTDEVICE8A iface, DWORD dodsize, LPDIDEVICEOBJECTDATA dod,
1046         LPDWORD entries, DWORD flags)
1047 {
1048     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
1049     HRESULT ret = DI_OK;
1050     int len;
1051
1052     TRACE("(%p) %p -> %p(%d) x%d, 0x%08x\n",
1053           This, dod, entries, entries ? *entries : 0, dodsize, flags);
1054
1055     if (!This->acquired)
1056         return DIERR_NOTACQUIRED;
1057     if (!This->queue_len)
1058         return DIERR_NOTBUFFERED;
1059     if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3))
1060         return DIERR_INVALIDPARAM;
1061
1062     IDirectInputDevice2_Poll(iface);
1063     EnterCriticalSection(&This->crit);
1064
1065     len = This->queue_head - This->queue_tail;
1066     if (len < 0) len += This->queue_len;
1067
1068     if ((*entries != INFINITE) && (len > *entries)) len = *entries;
1069
1070     if (dod)
1071     {
1072         int i;
1073         for (i = 0; i < len; i++)
1074         {
1075             int n = (This->queue_tail + i) % This->queue_len;
1076             memcpy((char *)dod + dodsize * i, This->data_queue + n, dodsize);
1077         }
1078     }
1079     *entries = len;
1080
1081     if (This->overflow)
1082         ret = DI_BUFFEROVERFLOW;
1083
1084     if (!(flags & DIGDD_PEEK))
1085     {
1086         /* Advance reading position */
1087         This->queue_tail = (This->queue_tail + len) % This->queue_len;
1088         This->overflow = FALSE;
1089     }
1090
1091     LeaveCriticalSection(&This->crit);
1092
1093     TRACE("Returning %d events queued\n", *entries);
1094     return ret;
1095 }
1096
1097 HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceInfo(
1098         LPDIRECTINPUTDEVICE8A iface,
1099         LPDIDEVICEINSTANCEA pdidi)
1100 {
1101     FIXME("(this=%p,%p): stub!\n",
1102           iface, pdidi);
1103     
1104     return DI_OK;
1105 }
1106
1107 HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceInfo(
1108         LPDIRECTINPUTDEVICE8W iface,
1109         LPDIDEVICEINSTANCEW pdidi)
1110 {
1111     FIXME("(this=%p,%p): stub!\n",
1112           iface, pdidi);
1113     
1114     return DI_OK;
1115 }
1116
1117 HRESULT WINAPI IDirectInputDevice2AImpl_RunControlPanel(
1118         LPDIRECTINPUTDEVICE8A iface,
1119         HWND hwndOwner,
1120         DWORD dwFlags)
1121 {
1122     FIXME("(this=%p,%p,0x%08x): stub!\n",
1123           iface, hwndOwner, dwFlags);
1124
1125     return DI_OK;
1126 }
1127
1128 HRESULT WINAPI IDirectInputDevice2AImpl_Initialize(
1129         LPDIRECTINPUTDEVICE8A iface,
1130         HINSTANCE hinst,
1131         DWORD dwVersion,
1132         REFGUID rguid)
1133 {
1134     FIXME("(this=%p,%p,%d,%s): stub!\n",
1135           iface, hinst, dwVersion, debugstr_guid(rguid));
1136     return DI_OK;
1137 }
1138
1139 /******************************************************************************
1140  *      IDirectInputDevice2A
1141  */
1142
1143 HRESULT WINAPI IDirectInputDevice2AImpl_CreateEffect(
1144         LPDIRECTINPUTDEVICE8A iface,
1145         REFGUID rguid,
1146         LPCDIEFFECT lpeff,
1147         LPDIRECTINPUTEFFECT *ppdef,
1148         LPUNKNOWN pUnkOuter)
1149 {
1150     FIXME("(this=%p,%s,%p,%p,%p): stub!\n",
1151           iface, debugstr_guid(rguid), lpeff, ppdef, pUnkOuter);
1152     return DI_OK;
1153 }
1154
1155 HRESULT WINAPI IDirectInputDevice2AImpl_EnumEffects(
1156         LPDIRECTINPUTDEVICE8A iface,
1157         LPDIENUMEFFECTSCALLBACKA lpCallback,
1158         LPVOID lpvRef,
1159         DWORD dwFlags)
1160 {
1161     FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1162           iface, lpCallback, lpvRef, dwFlags);
1163     
1164     return DI_OK;
1165 }
1166
1167 HRESULT WINAPI IDirectInputDevice2WImpl_EnumEffects(
1168         LPDIRECTINPUTDEVICE8W iface,
1169         LPDIENUMEFFECTSCALLBACKW lpCallback,
1170         LPVOID lpvRef,
1171         DWORD dwFlags)
1172 {
1173     FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1174           iface, lpCallback, lpvRef, dwFlags);
1175     
1176     return DI_OK;
1177 }
1178
1179 HRESULT WINAPI IDirectInputDevice2AImpl_GetEffectInfo(
1180         LPDIRECTINPUTDEVICE8A iface,
1181         LPDIEFFECTINFOA lpdei,
1182         REFGUID rguid)
1183 {
1184     FIXME("(this=%p,%p,%s): stub!\n",
1185           iface, lpdei, debugstr_guid(rguid));
1186     return DI_OK;
1187 }
1188
1189 HRESULT WINAPI IDirectInputDevice2WImpl_GetEffectInfo(
1190         LPDIRECTINPUTDEVICE8W iface,
1191         LPDIEFFECTINFOW lpdei,
1192         REFGUID rguid)
1193 {
1194     FIXME("(this=%p,%p,%s): stub!\n",
1195           iface, lpdei, debugstr_guid(rguid));
1196     return DI_OK;
1197 }
1198
1199 HRESULT WINAPI IDirectInputDevice2AImpl_GetForceFeedbackState(
1200         LPDIRECTINPUTDEVICE8A iface,
1201         LPDWORD pdwOut)
1202 {
1203     FIXME("(this=%p,%p): stub!\n",
1204           iface, pdwOut);
1205     return DI_OK;
1206 }
1207
1208 HRESULT WINAPI IDirectInputDevice2AImpl_SendForceFeedbackCommand(
1209         LPDIRECTINPUTDEVICE8A iface,
1210         DWORD dwFlags)
1211 {
1212     FIXME("(this=%p,0x%08x): stub!\n",
1213           iface, dwFlags);
1214     return DI_OK;
1215 }
1216
1217 HRESULT WINAPI IDirectInputDevice2AImpl_EnumCreatedEffectObjects(
1218         LPDIRECTINPUTDEVICE8A iface,
1219         LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback,
1220         LPVOID lpvRef,
1221         DWORD dwFlags)
1222 {
1223     FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1224           iface, lpCallback, lpvRef, dwFlags);
1225     return DI_OK;
1226 }
1227
1228 HRESULT WINAPI IDirectInputDevice2AImpl_Escape(
1229         LPDIRECTINPUTDEVICE8A iface,
1230         LPDIEFFESCAPE lpDIEEsc)
1231 {
1232     FIXME("(this=%p,%p): stub!\n",
1233           iface, lpDIEEsc);
1234     return DI_OK;
1235 }
1236
1237 HRESULT WINAPI IDirectInputDevice2AImpl_Poll(
1238         LPDIRECTINPUTDEVICE8A iface)
1239 {
1240     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
1241
1242     if (!This->acquired) return DIERR_NOTACQUIRED;
1243     /* Because wine devices do not need to be polled, just return DI_NOEFFECT */
1244     return DI_NOEFFECT;
1245 }
1246
1247 HRESULT WINAPI IDirectInputDevice2AImpl_SendDeviceData(
1248         LPDIRECTINPUTDEVICE8A iface,
1249         DWORD cbObjectData,
1250         LPCDIDEVICEOBJECTDATA rgdod,
1251         LPDWORD pdwInOut,
1252         DWORD dwFlags)
1253 {
1254     FIXME("(this=%p,0x%08x,%p,%p,0x%08x): stub!\n",
1255           iface, cbObjectData, rgdod, pdwInOut, dwFlags);
1256     
1257     return DI_OK;
1258 }
1259
1260 HRESULT WINAPI IDirectInputDevice7AImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8A iface,
1261                                                           LPCSTR lpszFileName,
1262                                                           LPDIENUMEFFECTSINFILECALLBACK pec,
1263                                                           LPVOID pvRef,
1264                                                           DWORD dwFlags)
1265 {
1266     FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", iface, lpszFileName, pec, pvRef, dwFlags);
1267     
1268     return DI_OK;
1269 }
1270
1271 HRESULT WINAPI IDirectInputDevice7WImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8W iface,
1272                                                           LPCWSTR lpszFileName,
1273                                                           LPDIENUMEFFECTSINFILECALLBACK pec,
1274                                                           LPVOID pvRef,
1275                                                           DWORD dwFlags)
1276 {
1277     FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", iface, debugstr_w(lpszFileName), pec, pvRef, dwFlags);
1278     
1279     return DI_OK;
1280 }
1281
1282 HRESULT WINAPI IDirectInputDevice7AImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8A iface,
1283                                                           LPCSTR lpszFileName,
1284                                                           DWORD dwEntries,
1285                                                           LPDIFILEEFFECT rgDiFileEft,
1286                                                           DWORD dwFlags)
1287 {
1288     FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", iface, lpszFileName, dwEntries, rgDiFileEft, dwFlags);
1289     
1290     return DI_OK;
1291 }
1292
1293 HRESULT WINAPI IDirectInputDevice7WImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8W iface,
1294                                                           LPCWSTR lpszFileName,
1295                                                           DWORD dwEntries,
1296                                                           LPDIFILEEFFECT rgDiFileEft,
1297                                                           DWORD dwFlags)
1298 {
1299     FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", iface, debugstr_w(lpszFileName), dwEntries, rgDiFileEft, dwFlags);
1300     
1301     return DI_OK;
1302 }
1303
1304 HRESULT WINAPI IDirectInputDevice8AImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface,
1305                                                        LPDIACTIONFORMATA lpdiaf,
1306                                                        LPCSTR lpszUserName,
1307                                                        DWORD dwFlags)
1308 {
1309     FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, lpszUserName, dwFlags);
1310     
1311     return DI_OK;
1312 }
1313
1314 HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface,
1315                                                        LPDIACTIONFORMATW lpdiaf,
1316                                                        LPCWSTR lpszUserName,
1317                                                        DWORD dwFlags)
1318 {
1319     FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
1320   
1321     return DI_OK;
1322 }
1323
1324 HRESULT WINAPI IDirectInputDevice8AImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface,
1325                                                      LPDIACTIONFORMATA lpdiaf,
1326                                                      LPCSTR lpszUserName,
1327                                                      DWORD dwFlags)
1328 {
1329     FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, lpszUserName, dwFlags);
1330     
1331     return DI_OK;
1332 }
1333
1334 HRESULT WINAPI IDirectInputDevice8WImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
1335                                                      LPDIACTIONFORMATW lpdiaf,
1336                                                      LPCWSTR lpszUserName,
1337                                                      DWORD dwFlags)
1338 {
1339     FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
1340     
1341     return DI_OK;
1342 }
1343
1344 HRESULT WINAPI IDirectInputDevice8AImpl_GetImageInfo(LPDIRECTINPUTDEVICE8A iface,
1345                                                      LPDIDEVICEIMAGEINFOHEADERA lpdiDevImageInfoHeader)
1346 {
1347     FIXME("(%p)->(%p): stub !\n", iface, lpdiDevImageInfoHeader);
1348     
1349     return DI_OK;
1350 }
1351
1352 HRESULT WINAPI IDirectInputDevice8WImpl_GetImageInfo(LPDIRECTINPUTDEVICE8W iface,
1353                                                      LPDIDEVICEIMAGEINFOHEADERW lpdiDevImageInfoHeader)
1354 {
1355     FIXME("(%p)->(%p): stub !\n", iface, lpdiDevImageInfoHeader);
1356     
1357     return DI_OK;
1358 }