ntdll: Fix two tests that fail on all NT platforms.
[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 "winreg.h"
36 #include "winuser.h"
37 #include "winerror.h"
38 #include "dinput.h"
39 #include "device_private.h"
40 #include "dinput_private.h"
41
42 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
43
44 /******************************************************************************
45  *      Various debugging tools
46  */
47 void _dump_cooperativelevel_DI(DWORD dwFlags) {
48     if (TRACE_ON(dinput)) {
49         unsigned int   i;
50         static const struct {
51             DWORD       mask;
52             const char  *name;
53         } flags[] = {
54 #define FE(x) { x, #x}
55             FE(DISCL_BACKGROUND),
56             FE(DISCL_EXCLUSIVE),
57             FE(DISCL_FOREGROUND),
58             FE(DISCL_NONEXCLUSIVE),
59             FE(DISCL_NOWINKEY)
60 #undef FE
61         };
62         TRACE(" cooperative level : ");
63         for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++)
64             if (flags[i].mask & dwFlags)
65                 TRACE("%s ",flags[i].name);
66         TRACE("\n");
67     }
68 }
69
70 void _dump_EnumObjects_flags(DWORD dwFlags) {
71     if (TRACE_ON(dinput)) {
72         unsigned int   i;
73         DWORD type, instance;
74         static const struct {
75             DWORD       mask;
76             const char  *name;
77         } flags[] = {
78 #define FE(x) { x, #x}
79             FE(DIDFT_RELAXIS),
80             FE(DIDFT_ABSAXIS),
81             FE(DIDFT_PSHBUTTON),
82             FE(DIDFT_TGLBUTTON),
83             FE(DIDFT_POV),
84             FE(DIDFT_COLLECTION),
85             FE(DIDFT_NODATA),       
86             FE(DIDFT_FFACTUATOR),
87             FE(DIDFT_FFEFFECTTRIGGER),
88             FE(DIDFT_OUTPUT),
89             FE(DIDFT_VENDORDEFINED),
90             FE(DIDFT_ALIAS),
91             FE(DIDFT_OPTIONAL)
92 #undef FE
93         };
94         type = (dwFlags & 0xFF0000FF);
95         instance = ((dwFlags >> 8) & 0xFFFF);
96         TRACE("Type:");
97         if (type == DIDFT_ALL) {
98             TRACE(" DIDFT_ALL");
99         } else {
100             for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++) {
101                 if (flags[i].mask & type) {
102                     type &= ~flags[i].mask;
103                     TRACE(" %s",flags[i].name);
104                 }
105             }
106             if (type) {
107                 TRACE(" (unhandled: %08x)", type);
108             }
109         }
110         TRACE(" / Instance: ");
111         if (instance == ((DIDFT_ANYINSTANCE >> 8) & 0xFFFF)) {
112             TRACE("DIDFT_ANYINSTANCE");
113         } else {
114             TRACE("%3d", instance);
115         }
116     }
117 }
118
119 void _dump_DIPROPHEADER(LPCDIPROPHEADER diph) {
120     if (TRACE_ON(dinput)) {
121         TRACE("  - dwObj = 0x%08x\n", diph->dwObj);
122         TRACE("  - dwHow = %s\n",
123             ((diph->dwHow == DIPH_DEVICE) ? "DIPH_DEVICE" :
124             ((diph->dwHow == DIPH_BYOFFSET) ? "DIPH_BYOFFSET" :
125             ((diph->dwHow == DIPH_BYID)) ? "DIPH_BYID" : "unknown")));
126     }
127 }
128
129 void _dump_OBJECTINSTANCEA(const DIDEVICEOBJECTINSTANCEA *ddoi) {
130     TRACE("    - enumerating : %s ('%s') - %2d - 0x%08x - %s\n",
131         debugstr_guid(&ddoi->guidType), _dump_dinput_GUID(&ddoi->guidType), ddoi->dwOfs, ddoi->dwType, ddoi->tszName);
132 }
133
134 void _dump_OBJECTINSTANCEW(const DIDEVICEOBJECTINSTANCEW *ddoi) {
135     TRACE("    - enumerating : %s ('%s'), - %2d - 0x%08x - %s\n",
136         debugstr_guid(&ddoi->guidType), _dump_dinput_GUID(&ddoi->guidType), ddoi->dwOfs, ddoi->dwType, debugstr_w(ddoi->tszName));
137 }
138
139 /* This function is a helper to convert a GUID into any possible DInput GUID out there */
140 const char *_dump_dinput_GUID(const GUID *guid) {
141     unsigned int i;
142     static const struct {
143         const GUID *guid;
144         const char *name;
145     } guids[] = {
146 #define FE(x) { &x, #x}
147         FE(GUID_XAxis),
148         FE(GUID_YAxis),
149         FE(GUID_ZAxis),
150         FE(GUID_RxAxis),
151         FE(GUID_RyAxis),
152         FE(GUID_RzAxis),
153         FE(GUID_Slider),
154         FE(GUID_Button),
155         FE(GUID_Key),
156         FE(GUID_POV),
157         FE(GUID_Unknown),
158         FE(GUID_SysMouse),
159         FE(GUID_SysKeyboard),
160         FE(GUID_Joystick),
161         FE(GUID_ConstantForce),
162         FE(GUID_RampForce),
163         FE(GUID_Square),
164         FE(GUID_Sine),
165         FE(GUID_Triangle),
166         FE(GUID_SawtoothUp),
167         FE(GUID_SawtoothDown),
168         FE(GUID_Spring),
169         FE(GUID_Damper),
170         FE(GUID_Inertia),
171         FE(GUID_Friction),
172         FE(GUID_CustomForce)
173 #undef FE
174     };
175     if (guid == NULL)
176         return "null GUID";
177     for (i = 0; i < (sizeof(guids) / sizeof(guids[0])); i++) {
178         if (IsEqualGUID(guids[i].guid, guid)) {
179             return guids[i].name;
180         }
181     }
182     return "Unknown GUID";
183 }
184
185 void _dump_DIDATAFORMAT(const DIDATAFORMAT *df) {
186     unsigned int i;
187
188     TRACE("Dumping DIDATAFORMAT structure:\n");
189     TRACE("  - dwSize: %d\n", df->dwSize);
190     if (df->dwSize != sizeof(DIDATAFORMAT)) {
191         WARN("Non-standard DIDATAFORMAT structure size %d\n", df->dwSize);
192     }
193     TRACE("  - dwObjsize: %d\n", df->dwObjSize);
194     if (df->dwObjSize != sizeof(DIOBJECTDATAFORMAT)) {
195         WARN("Non-standard DIOBJECTDATAFORMAT structure size %d\n", df->dwObjSize);
196     }
197     TRACE("  - dwFlags: 0x%08x (", df->dwFlags);
198     switch (df->dwFlags) {
199         case DIDF_ABSAXIS: TRACE("DIDF_ABSAXIS"); break;
200         case DIDF_RELAXIS: TRACE("DIDF_RELAXIS"); break;
201         default: TRACE("unknown"); break;
202     }
203     TRACE(")\n");
204     TRACE("  - dwDataSize: %d\n", df->dwDataSize);
205     TRACE("  - dwNumObjs: %d\n", df->dwNumObjs);
206     
207     for (i = 0; i < df->dwNumObjs; i++) {
208         TRACE("  - Object %d:\n", i);
209         TRACE("      * GUID: %s ('%s')\n", debugstr_guid(df->rgodf[i].pguid), _dump_dinput_GUID(df->rgodf[i].pguid));
210         TRACE("      * dwOfs: %d\n", df->rgodf[i].dwOfs);
211         TRACE("      * dwType: 0x%08x\n", df->rgodf[i].dwType);
212         TRACE("        "); _dump_EnumObjects_flags(df->rgodf[i].dwType); TRACE("\n");
213         TRACE("      * dwFlags: 0x%08x\n", df->rgodf[i].dwFlags);
214     }
215 }
216
217 /******************************************************************************
218  * Get the default and the app-specific config keys.
219  */
220 BOOL get_app_key(HKEY *defkey, HKEY *appkey)
221 {
222     char buffer[MAX_PATH+16];
223     DWORD len;
224
225     *appkey = 0;
226
227     /* @@ Wine registry key: HKCU\Software\Wine\DirectInput */
228     if (RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\DirectInput", defkey))
229         *defkey = 0;
230
231     len = GetModuleFileNameA(0, buffer, MAX_PATH);
232     if (len && len < MAX_PATH)
233     {
234         HKEY tmpkey;
235
236         /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DirectInput */
237         if (!RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey))
238         {
239             char *p, *appname = buffer;
240             if ((p = strrchr(appname, '/'))) appname = p + 1;
241             if ((p = strrchr(appname, '\\'))) appname = p + 1;
242             strcat(appname, "\\DirectInput");
243
244             if (RegOpenKeyA(tmpkey, appname, appkey)) *appkey = 0;
245             RegCloseKey(tmpkey);
246         }
247     }
248
249     return *defkey || *appkey;
250 }
251
252 /******************************************************************************
253  * Get a config key from either the app-specific or the default config
254  */
255 DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
256                              char *buffer, DWORD size )
257 {
258     if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE)buffer, &size ))
259         return 0;
260
261     if (defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE)buffer, &size ))
262         return 0;
263
264     return ERROR_FILE_NOT_FOUND;
265 }
266
267 /* Conversion between internal data buffer and external data buffer */
268 void fill_DataFormat(void *out, const void *in, const DataFormat *df) {
269     int i;
270     const char *in_c = in;
271     char *out_c = (char *) out;
272
273     if (df->dt == NULL) {
274         /* This means that the app uses Wine's internal data format */
275         memcpy(out, in, df->internal_format_size);
276     } else {
277         for (i = 0; i < df->size; i++) {
278             if (df->dt[i].offset_in >= 0) {
279                 switch (df->dt[i].size) {
280                     case 1:
281                         TRACE("Copying (c) to %d from %d (value %d)\n",
282                               df->dt[i].offset_out, df->dt[i].offset_in, *(in_c + df->dt[i].offset_in));
283                         *(out_c + df->dt[i].offset_out) = *(in_c + df->dt[i].offset_in);
284                         break;
285
286                     case 2:
287                         TRACE("Copying (s) to %d from %d (value %d)\n",
288                               df->dt[i].offset_out, df->dt[i].offset_in, *((const short *)(in_c + df->dt[i].offset_in)));
289                         *((short *)(out_c + df->dt[i].offset_out)) = *((const short *)(in_c + df->dt[i].offset_in));
290                         break;
291
292                     case 4:
293                         TRACE("Copying (i) to %d from %d (value %d)\n",
294                               df->dt[i].offset_out, df->dt[i].offset_in, *((const int *)(in_c + df->dt[i].offset_in)));
295                         *((int *)(out_c + df->dt[i].offset_out)) = *((const int *)(in_c + df->dt[i].offset_in));
296                         break;
297
298                     default:
299                         memcpy((out_c + df->dt[i].offset_out), (in_c + df->dt[i].offset_in), df->dt[i].size);
300                         break;
301                 }
302             } else {
303                 switch (df->dt[i].size) {
304                     case 1:
305                         TRACE("Copying (c) to %d default value %d\n",
306                               df->dt[i].offset_out, df->dt[i].value);
307                         *(out_c + df->dt[i].offset_out) = (char) df->dt[i].value;
308                         break;
309                         
310                     case 2:
311                         TRACE("Copying (s) to %d default value %d\n",
312                               df->dt[i].offset_out, df->dt[i].value);
313                         *((short *) (out_c + df->dt[i].offset_out)) = (short) df->dt[i].value;
314                         break;
315                         
316                     case 4:
317                         TRACE("Copying (i) to %d default value %d\n",
318                               df->dt[i].offset_out, df->dt[i].value);
319                         *((int *) (out_c + df->dt[i].offset_out)) = df->dt[i].value;
320                         break;
321                         
322                     default:
323                         memset((out_c + df->dt[i].offset_out), 0, df->dt[i].size);
324                         break;
325                 }
326             }
327         }
328     }
329 }
330
331 void release_DataFormat(DataFormat * format)
332 {
333     TRACE("Deleting DataFormat: %p\n", format);
334
335     HeapFree(GetProcessHeap(), 0, format->dt);
336     format->dt = NULL;
337     HeapFree(GetProcessHeap(), 0, format->offsets);
338     format->offsets = NULL;
339     HeapFree(GetProcessHeap(), 0, format->user_df);
340     format->user_df = NULL;
341 }
342
343 inline LPDIOBJECTDATAFORMAT dataformat_to_odf(LPCDIDATAFORMAT df, int idx)
344 {
345     if (idx < 0 || idx >= df->dwNumObjs) return NULL;
346     return (LPDIOBJECTDATAFORMAT)((LPBYTE)df->rgodf + idx * df->dwObjSize);
347 }
348
349 HRESULT create_DataFormat(LPCDIDATAFORMAT asked_format, DataFormat *format)
350 {
351     DataTransform *dt;
352     unsigned int i, j;
353     int same = 1;
354     int *done;
355     int index = 0;
356     DWORD next = 0;
357
358     if (!format->wine_df) return DIERR_INVALIDPARAM;
359     done = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, asked_format->dwNumObjs * sizeof(int));
360     dt = HeapAlloc(GetProcessHeap(), 0, asked_format->dwNumObjs * sizeof(DataTransform));
361     if (!dt || !done) goto failed;
362
363     if (!(format->offsets = HeapAlloc(GetProcessHeap(), 0, format->wine_df->dwNumObjs * sizeof(int))))
364         goto failed;
365
366     if (!(format->user_df = HeapAlloc(GetProcessHeap(), 0, asked_format->dwSize)))
367         goto failed;
368     memcpy(format->user_df, asked_format, asked_format->dwSize);
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     return DI_OK;
473
474 failed:
475     HeapFree(GetProcessHeap(), 0, done);
476     HeapFree(GetProcessHeap(), 0, dt);
477     format->dt = NULL;
478     HeapFree(GetProcessHeap(), 0, format->offsets);
479     format->offsets = NULL;
480     HeapFree(GetProcessHeap(), 0, format->user_df);
481     format->user_df = NULL;
482
483     return DIERR_OUTOFMEMORY;
484 }
485
486 /* find an object by it's offset in a data format */
487 static int offset_to_object(const DataFormat *df, int offset)
488 {
489     int i;
490
491     if (!df->offsets) return -1;
492
493     for (i = 0; i < df->wine_df->dwNumObjs; i++)
494         if (df->offsets[i] == offset) return i;
495
496     return -1;
497 }
498
499 int id_to_object(LPCDIDATAFORMAT df, int id)
500 {
501     int i;
502
503     id &= 0x00ffffff;
504     for (i = 0; i < df->dwNumObjs; i++)
505         if ((dataformat_to_odf(df, i)->dwType & 0x00ffffff) == id)
506             return i;
507
508     return -1;
509 }
510
511 int id_to_offset(const DataFormat *df, int id)
512 {
513     int obj = id_to_object(df->wine_df, id);
514
515     return obj >= 0 && df->offsets ? df->offsets[obj] : -1;
516 }
517
518 int find_property(const DataFormat *df, LPCDIPROPHEADER ph)
519 {
520     switch (ph->dwHow)
521     {
522         case DIPH_BYID:     return id_to_object(df->wine_df, ph->dwObj);
523         case DIPH_BYOFFSET: return offset_to_object(df, ph->dwObj);
524     }
525     FIXME("Unhandled ph->dwHow=='%04X'\n", (unsigned int)ph->dwHow);
526
527     return -1;
528 }
529
530
531 BOOL DIEnumDevicesCallbackAtoW(LPCDIDEVICEOBJECTINSTANCEA lpddi, LPVOID lpvRef) {
532     DIDEVICEOBJECTINSTANCEW ddtmp;
533     device_enumobjects_AtoWcb_data* data;
534
535     data = (device_enumobjects_AtoWcb_data*) lpvRef;
536     
537     memset(&ddtmp, 0, sizeof(ddtmp));
538     
539     ddtmp.dwSize = sizeof(DIDEVICEINSTANCEW);
540     ddtmp.guidType     = lpddi->guidType;
541     ddtmp.dwOfs        = lpddi->dwOfs;
542     ddtmp.dwType       = lpddi->dwType;
543     ddtmp.dwFlags      = lpddi->dwFlags;
544     MultiByteToWideChar(CP_ACP, 0, lpddi->tszName, -1, ddtmp.tszName, MAX_PATH);
545     
546     if (lpddi->dwSize == sizeof(DIDEVICEINSTANCEA)) {
547         /**
548          * if dwSize < sizeof(DIDEVICEINSTANCEA of DInput version >= 5)
549          *  force feedback and other newer datas aren't available
550          */
551         ddtmp.dwFFMaxForce        = lpddi->dwFFMaxForce;
552         ddtmp.dwFFForceResolution = lpddi->dwFFForceResolution;
553         ddtmp.wCollectionNumber   = lpddi->wCollectionNumber;
554         ddtmp.wDesignatorIndex    = lpddi->wDesignatorIndex;
555         ddtmp.wUsagePage          = lpddi->wUsagePage;
556         ddtmp.wUsage              = lpddi->wUsage;
557         ddtmp.dwDimension         = lpddi->dwDimension;
558         ddtmp.wExponent           = lpddi->wExponent;
559         ddtmp.wReserved           = lpddi->wReserved;
560     }
561     return data->lpCallBack(&ddtmp, data->lpvRef);
562 }
563
564 /******************************************************************************
565  *      queue_event - add new event to the ring queue
566  */
567
568 void queue_event(LPDIRECTINPUTDEVICE8A iface, int ofs, DWORD data, DWORD time, DWORD seq)
569 {
570     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
571     int next_pos;
572
573     /* Event is being set regardless of the queue state */
574     if (This->hEvent) SetEvent(This->hEvent);
575
576     if (!This->queue_len || This->overflow || ofs < 0) return;
577
578     next_pos = (This->queue_head + 1) % This->queue_len;
579     if (next_pos == This->queue_tail)
580     {
581         TRACE(" queue overflowed\n");
582         This->overflow = TRUE;
583         return;
584     }
585
586     TRACE(" queueing %d at offset %d (queue head %d / size %d)\n",
587           data, ofs, This->queue_head, This->queue_len);
588
589     This->data_queue[This->queue_head].dwOfs       = ofs;
590     This->data_queue[This->queue_head].dwData      = data;
591     This->data_queue[This->queue_head].dwTimeStamp = time;
592     This->data_queue[This->queue_head].dwSequence  = seq;
593     This->queue_head = next_pos;
594     /* Send event if asked */
595 }
596
597 /******************************************************************************
598  *      Acquire
599  */
600
601 HRESULT WINAPI IDirectInputDevice2AImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
602 {
603     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
604     HRESULT res;
605
606     if (!This->data_format.user_df) return DIERR_INVALIDPARAM;
607     if (This->dwCoopLevel & DISCL_FOREGROUND && This->win != GetForegroundWindow())
608         return DIERR_OTHERAPPHASPRIO;
609
610     EnterCriticalSection(&This->crit);
611     res = This->acquired ? S_FALSE : DI_OK;
612     This->acquired = 1;
613     if (res == DI_OK)
614     {
615         This->queue_head = This->queue_tail = This->overflow = 0;
616         check_dinput_hooks(iface);
617     }
618     LeaveCriticalSection(&This->crit);
619
620     return res;
621 }
622
623 /******************************************************************************
624  *      Unacquire
625  */
626
627 HRESULT WINAPI IDirectInputDevice2AImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
628 {
629     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
630     HRESULT res;
631
632     EnterCriticalSection(&This->crit);
633     res = !This->acquired ? DI_NOEFFECT : DI_OK;
634     This->acquired = 0;
635     if (res == DI_OK)
636         check_dinput_hooks(iface);
637     LeaveCriticalSection(&This->crit);
638
639     return res;
640 }
641
642 /******************************************************************************
643  *      IDirectInputDeviceA
644  */
645
646 HRESULT WINAPI IDirectInputDevice2AImpl_SetDataFormat(
647         LPDIRECTINPUTDEVICE8A iface, LPCDIDATAFORMAT df)
648 {
649     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
650     HRESULT res = DI_OK;
651
652     if (!df) return E_POINTER;
653     TRACE("(%p) %p\n", This, df);
654     _dump_DIDATAFORMAT(df);
655
656     if (df->dwSize != sizeof(DIDATAFORMAT)) return DIERR_INVALIDPARAM;
657     if (This->acquired) return DIERR_ACQUIRED;
658
659     EnterCriticalSection(&This->crit);
660
661     release_DataFormat(&This->data_format);
662     res = create_DataFormat(df, &This->data_format);
663
664     LeaveCriticalSection(&This->crit);
665     return res;
666 }
667
668 /******************************************************************************
669   *     SetCooperativeLevel
670   *
671   *  Set cooperative level and the source window for the events.
672   */
673 HRESULT WINAPI IDirectInputDevice2AImpl_SetCooperativeLevel(
674         LPDIRECTINPUTDEVICE8A iface, HWND hwnd, DWORD dwflags)
675 {
676     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
677
678     TRACE("(%p) %p,0x%08x\n", This, hwnd, dwflags);
679     _dump_cooperativelevel_DI(dwflags);
680
681     if ((dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == 0 ||
682         (dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE) ||
683         (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == 0 ||
684         (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == (DISCL_FOREGROUND | DISCL_BACKGROUND))
685         return DIERR_INVALIDPARAM;
686
687     if (dwflags == (DISCL_NONEXCLUSIVE | DISCL_BACKGROUND))
688         hwnd = GetDesktopWindow();
689
690     if (!hwnd) return E_HANDLE;
691
692     /* For security reasons native does not allow exclusive background level
693        for mouse and keyboard only */
694     if (dwflags & DISCL_EXCLUSIVE && dwflags & DISCL_BACKGROUND &&
695         (IsEqualGUID(&This->guid, &GUID_SysMouse) ||
696          IsEqualGUID(&This->guid, &GUID_SysKeyboard)))
697         return DIERR_UNSUPPORTED;
698
699     /* Store the window which asks for the mouse */
700     EnterCriticalSection(&This->crit);
701     This->win = hwnd;
702     This->dwCoopLevel = dwflags;
703     LeaveCriticalSection(&This->crit);
704
705     return DI_OK;
706 }
707
708 /******************************************************************************
709   *     SetEventNotification : specifies event to be sent on state change
710   */
711 HRESULT WINAPI IDirectInputDevice2AImpl_SetEventNotification(
712         LPDIRECTINPUTDEVICE8A iface, HANDLE event)
713 {
714     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
715
716     TRACE("(%p) %p\n", This, event);
717
718     EnterCriticalSection(&This->crit);
719     This->hEvent = event;
720     LeaveCriticalSection(&This->crit);
721     return DI_OK;
722 }
723
724 ULONG WINAPI IDirectInputDevice2AImpl_Release(LPDIRECTINPUTDEVICE8A iface)
725 {
726     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
727     ULONG ref;
728
729     ref = InterlockedDecrement(&(This->ref));
730     if (ref) return ref;
731
732     IDirectInputDevice_Unacquire(iface);
733     /* Reset the FF state, free all effects, etc */
734     IDirectInputDevice8_SendForceFeedbackCommand(iface, DISFFC_RESET);
735
736     HeapFree(GetProcessHeap(), 0, This->data_queue);
737
738     /* Free data format */
739     HeapFree(GetProcessHeap(), 0, This->data_format.wine_df->rgodf);
740     HeapFree(GetProcessHeap(), 0, This->data_format.wine_df);
741     release_DataFormat(&This->data_format);
742
743     EnterCriticalSection( &This->dinput->crit );
744     list_remove( &This->entry );
745     LeaveCriticalSection( &This->dinput->crit );
746
747     IDirectInput_Release((LPDIRECTINPUTDEVICE8A)This->dinput);
748     This->crit.DebugInfo->Spare[0] = 0;
749     DeleteCriticalSection(&This->crit);
750
751     HeapFree(GetProcessHeap(), 0, This);
752
753     return DI_OK;
754 }
755
756 HRESULT WINAPI IDirectInputDevice2AImpl_QueryInterface(
757         LPDIRECTINPUTDEVICE8A iface,REFIID riid,LPVOID *ppobj
758 )
759 {
760     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
761     
762     TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
763     if (IsEqualGUID(&IID_IUnknown,riid)) {
764         IDirectInputDevice2_AddRef(iface);
765         *ppobj = This;
766         return DI_OK;
767     }
768     if (IsEqualGUID(&IID_IDirectInputDeviceA,riid)) {
769         IDirectInputDevice2_AddRef(iface);
770         *ppobj = This;
771         return DI_OK;
772     }
773     if (IsEqualGUID(&IID_IDirectInputDevice2A,riid)) {
774         IDirectInputDevice2_AddRef(iface);
775         *ppobj = This;
776         return DI_OK;
777     }
778     if (IsEqualGUID(&IID_IDirectInputDevice7A,riid)) {
779         IDirectInputDevice7_AddRef(iface);
780         *ppobj = This;
781         return DI_OK;
782     }
783     if (IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
784         IDirectInputDevice8_AddRef(iface);
785         *ppobj = This;
786         return DI_OK;
787     }
788     TRACE("Unsupported interface !\n");
789     return E_FAIL;
790 }
791
792 HRESULT WINAPI IDirectInputDevice2WImpl_QueryInterface(
793         LPDIRECTINPUTDEVICE8W iface,REFIID riid,LPVOID *ppobj
794 )
795 {
796     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
797     
798     TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
799     if (IsEqualGUID(&IID_IUnknown,riid)) {
800         IDirectInputDevice2_AddRef(iface);
801         *ppobj = This;
802         return DI_OK;
803     }
804     if (IsEqualGUID(&IID_IDirectInputDeviceW,riid)) {
805         IDirectInputDevice2_AddRef(iface);
806         *ppobj = This;
807         return DI_OK;
808     }
809     if (IsEqualGUID(&IID_IDirectInputDevice2W,riid)) {
810         IDirectInputDevice2_AddRef(iface);
811         *ppobj = This;
812         return DI_OK;
813     }
814     if (IsEqualGUID(&IID_IDirectInputDevice7W,riid)) {
815         IDirectInputDevice7_AddRef(iface);
816         *ppobj = This;
817         return DI_OK;
818     }
819     if (IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
820         IDirectInputDevice8_AddRef(iface);
821         *ppobj = This;
822         return DI_OK;
823     }
824     TRACE("Unsupported interface !\n");
825     return E_FAIL;
826 }
827
828 ULONG WINAPI IDirectInputDevice2AImpl_AddRef(
829         LPDIRECTINPUTDEVICE8A iface)
830 {
831     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
832     return InterlockedIncrement(&(This->ref));
833 }
834
835 HRESULT WINAPI IDirectInputDevice2AImpl_EnumObjects(LPDIRECTINPUTDEVICE8A iface,
836         LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback, LPVOID lpvRef, DWORD dwFlags)
837 {
838     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
839     DIDEVICEOBJECTINSTANCEA ddoi;
840     int i;
841
842     TRACE("(%p) %p,%p flags:%08x)\n", iface, lpCallback, lpvRef, dwFlags);
843     TRACE("  - flags = ");
844     _dump_EnumObjects_flags(dwFlags);
845     TRACE("\n");
846
847     /* Only the fields till dwFFMaxForce are relevant */
848     memset(&ddoi, 0, sizeof(ddoi));
849     ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce);
850
851     for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++)
852     {
853         LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(This->data_format.wine_df, i);
854
855         if (dwFlags != DIDFT_ALL && !(dwFlags & DIEFT_GETTYPE(odf->dwType))) continue;
856         if (IDirectInputDevice_GetObjectInfo(iface, &ddoi, odf->dwType, DIPH_BYID) != DI_OK)
857             continue;
858
859         if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) break;
860     }
861
862     return DI_OK;
863 }
864
865 HRESULT WINAPI IDirectInputDevice2WImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface,
866         LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback, LPVOID lpvRef, DWORD dwFlags)
867 {
868     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
869     DIDEVICEOBJECTINSTANCEW ddoi;
870     int i;
871
872     TRACE("(%p) %p,%p flags:%08x)\n", iface, lpCallback, lpvRef, dwFlags);
873     TRACE("  - flags = ");
874     _dump_EnumObjects_flags(dwFlags);
875     TRACE("\n");
876
877     /* Only the fields till dwFFMaxForce are relevant */
878     memset(&ddoi, 0, sizeof(ddoi));
879     ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEW, dwFFMaxForce);
880
881     for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++)
882     {
883         LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(This->data_format.wine_df, i);
884
885         if (dwFlags != DIDFT_ALL && !(dwFlags & DIEFT_GETTYPE(odf->dwType))) continue;
886         if (IDirectInputDevice_GetObjectInfo(iface, &ddoi, odf->dwType, DIPH_BYID) != DI_OK)
887             continue;
888
889         if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) break;
890     }
891
892     return DI_OK;
893 }
894
895 /******************************************************************************
896  *      GetProperty
897  */
898
899 HRESULT WINAPI IDirectInputDevice2AImpl_GetProperty(
900         LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPDIPROPHEADER pdiph)
901 {
902     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
903
904     TRACE("(%p) %s,%p\n", iface, debugstr_guid(rguid), pdiph);
905     _dump_DIPROPHEADER(pdiph);
906
907     if (HIWORD(rguid)) return DI_OK;
908
909     switch (LOWORD(rguid))
910     {
911         case (DWORD) DIPROP_BUFFERSIZE:
912         {
913             LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
914
915             if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
916
917             pd->dwData = This->queue_len;
918             TRACE("buffersize = %d\n", pd->dwData);
919             break;
920         }
921         default:
922             WARN("Unknown property %s\n", debugstr_guid(rguid));
923             break;
924     }
925
926     return DI_OK;
927 }
928
929 /******************************************************************************
930  *      SetProperty
931  */
932
933 HRESULT WINAPI IDirectInputDevice2AImpl_SetProperty(
934         LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPCDIPROPHEADER pdiph)
935 {
936     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
937
938     TRACE("(%p) %s,%p\n", iface, debugstr_guid(rguid), pdiph);
939     _dump_DIPROPHEADER(pdiph);
940
941     if (HIWORD(rguid)) return DI_OK;
942
943     switch (LOWORD(rguid))
944     {
945         case (DWORD) DIPROP_AXISMODE:
946         {
947             LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph;
948
949             if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
950             if (pdiph->dwHow == DIPH_DEVICE && pdiph->dwObj) return DIERR_INVALIDPARAM;
951             if (This->acquired) return DIERR_ACQUIRED;
952             if (pdiph->dwHow != DIPH_DEVICE) return DIERR_UNSUPPORTED;
953             if (!This->data_format.user_df) return DI_OK;
954
955             TRACE("Axis mode: %s\n", pd->dwData == DIPROPAXISMODE_ABS ? "absolute" :
956                                                                         "relative");
957
958             EnterCriticalSection(&This->crit);
959             This->data_format.user_df->dwFlags &= ~DIDFT_AXIS;
960             This->data_format.user_df->dwFlags |= pd->dwData == DIPROPAXISMODE_ABS ?
961                                                   DIDF_ABSAXIS : DIDF_RELAXIS;
962             LeaveCriticalSection(&This->crit);
963             break;
964         }
965         case (DWORD) DIPROP_BUFFERSIZE:
966         {
967             LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph;
968
969             if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
970             if (This->acquired) return DIERR_ACQUIRED;
971
972             TRACE("buffersize = %d\n", pd->dwData);
973
974             EnterCriticalSection(&This->crit);
975             HeapFree(GetProcessHeap(), 0, This->data_queue);
976
977             This->data_queue = !pd->dwData ? NULL : HeapAlloc(GetProcessHeap(), 0,
978                                 pd->dwData * sizeof(DIDEVICEOBJECTDATA));
979             This->queue_head = This->queue_tail = This->overflow = 0;
980             This->queue_len  = pd->dwData;
981
982             LeaveCriticalSection(&This->crit);
983             break;
984         }
985         default:
986             WARN("Unknown property %s\n", debugstr_guid(rguid));
987             return DIERR_UNSUPPORTED;
988     }
989
990     return DI_OK;
991 }
992
993 HRESULT WINAPI IDirectInputDevice2AImpl_GetObjectInfo(
994         LPDIRECTINPUTDEVICE8A iface,
995         LPDIDEVICEOBJECTINSTANCEA pdidoi,
996         DWORD dwObj,
997         DWORD dwHow)
998 {
999     DIDEVICEOBJECTINSTANCEW didoiW;
1000     HRESULT res;
1001
1002     if (!pdidoi ||
1003         (pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCEA) &&
1004          pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCE_DX3A)))
1005         return DIERR_INVALIDPARAM;
1006
1007     didoiW.dwSize = sizeof(didoiW);
1008     res = IDirectInputDevice2WImpl_GetObjectInfo((LPDIRECTINPUTDEVICE8W)iface, &didoiW, dwObj, dwHow);
1009     if (res == DI_OK)
1010     {
1011         DWORD dwSize = pdidoi->dwSize;
1012
1013         memset(pdidoi, 0, pdidoi->dwSize);
1014         pdidoi->dwSize   = dwSize;
1015         pdidoi->guidType = didoiW.guidType;
1016         pdidoi->dwOfs    = didoiW.dwOfs;
1017         pdidoi->dwType   = didoiW.dwType;
1018         pdidoi->dwFlags  = didoiW.dwFlags;
1019     }
1020
1021     return res;
1022 }
1023
1024 HRESULT WINAPI IDirectInputDevice2WImpl_GetObjectInfo(
1025         LPDIRECTINPUTDEVICE8W iface,
1026         LPDIDEVICEOBJECTINSTANCEW pdidoi,
1027         DWORD dwObj,
1028         DWORD dwHow)
1029 {
1030     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
1031     DWORD dwSize;
1032     LPDIOBJECTDATAFORMAT odf;
1033     int idx = -1;
1034
1035     TRACE("(%p) %d(0x%08x) -> %p\n", This, dwHow, dwObj, pdidoi);
1036
1037     if (!pdidoi ||
1038         (pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCEW) &&
1039          pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCE_DX3W)))
1040         return DIERR_INVALIDPARAM;
1041
1042     switch (dwHow)
1043     {
1044     case DIPH_BYOFFSET:
1045         if (!This->data_format.offsets) break;
1046         for (idx = This->data_format.wine_df->dwNumObjs - 1; idx >= 0; idx--)
1047             if (This->data_format.offsets[idx] == dwObj) break;
1048         break;
1049     case DIPH_BYID:
1050         dwObj &= 0x00ffffff;
1051         for (idx = This->data_format.wine_df->dwNumObjs - 1; idx >= 0; idx--)
1052             if ((dataformat_to_odf(This->data_format.wine_df, idx)->dwType & 0x00ffffff) == dwObj)
1053                 break;
1054         break;
1055
1056     case DIPH_BYUSAGE:
1057         FIXME("dwHow = DIPH_BYUSAGE not implemented\n");
1058         break;
1059     default:
1060         WARN("invalid parameter: dwHow = %08x\n", dwHow);
1061         return DIERR_INVALIDPARAM;
1062     }
1063     if (idx < 0) return DIERR_OBJECTNOTFOUND;
1064
1065     odf = dataformat_to_odf(This->data_format.wine_df, idx);
1066     dwSize = pdidoi->dwSize; /* save due to memset below */
1067     memset(pdidoi, 0, pdidoi->dwSize);
1068     pdidoi->dwSize   = dwSize;
1069     if (odf->pguid) pdidoi->guidType = *odf->pguid;
1070     pdidoi->dwOfs    = This->data_format.offsets ? This->data_format.offsets[idx] : odf->dwOfs;
1071     pdidoi->dwType   = odf->dwType;
1072     pdidoi->dwFlags  = odf->dwFlags;
1073
1074     return DI_OK;
1075 }
1076
1077 HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceData(
1078         LPDIRECTINPUTDEVICE8A iface, DWORD dodsize, LPDIDEVICEOBJECTDATA dod,
1079         LPDWORD entries, DWORD flags)
1080 {
1081     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
1082     HRESULT ret = DI_OK;
1083     int len;
1084
1085     TRACE("(%p) %p -> %p(%d) x%d, 0x%08x\n",
1086           This, dod, entries, entries ? *entries : 0, dodsize, flags);
1087
1088     if (!This->acquired)
1089         return DIERR_NOTACQUIRED;
1090     if (!This->queue_len)
1091         return DIERR_NOTBUFFERED;
1092     if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3))
1093         return DIERR_INVALIDPARAM;
1094
1095     IDirectInputDevice2_Poll(iface);
1096     EnterCriticalSection(&This->crit);
1097
1098     len = This->queue_head - This->queue_tail;
1099     if (len < 0) len += This->queue_len;
1100
1101     if ((*entries != INFINITE) && (len > *entries)) len = *entries;
1102
1103     if (dod)
1104     {
1105         int i;
1106         for (i = 0; i < len; i++)
1107         {
1108             int n = (This->queue_tail + i) % This->queue_len;
1109             memcpy((char *)dod + dodsize * i, This->data_queue + n, dodsize);
1110         }
1111     }
1112     *entries = len;
1113
1114     if (This->overflow)
1115         ret = DI_BUFFEROVERFLOW;
1116
1117     if (!(flags & DIGDD_PEEK))
1118     {
1119         /* Advance reading position */
1120         This->queue_tail = (This->queue_tail + len) % This->queue_len;
1121         This->overflow = FALSE;
1122     }
1123
1124     LeaveCriticalSection(&This->crit);
1125
1126     TRACE("Returning %d events queued\n", *entries);
1127     return ret;
1128 }
1129
1130 HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceInfo(
1131         LPDIRECTINPUTDEVICE8A iface,
1132         LPDIDEVICEINSTANCEA pdidi)
1133 {
1134     FIXME("(this=%p,%p): stub!\n",
1135           iface, pdidi);
1136     
1137     return DI_OK;
1138 }
1139
1140 HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceInfo(
1141         LPDIRECTINPUTDEVICE8W iface,
1142         LPDIDEVICEINSTANCEW pdidi)
1143 {
1144     FIXME("(this=%p,%p): stub!\n",
1145           iface, pdidi);
1146     
1147     return DI_OK;
1148 }
1149
1150 HRESULT WINAPI IDirectInputDevice2AImpl_RunControlPanel(
1151         LPDIRECTINPUTDEVICE8A iface,
1152         HWND hwndOwner,
1153         DWORD dwFlags)
1154 {
1155     FIXME("(this=%p,%p,0x%08x): stub!\n",
1156           iface, hwndOwner, dwFlags);
1157
1158     return DI_OK;
1159 }
1160
1161 HRESULT WINAPI IDirectInputDevice2AImpl_Initialize(
1162         LPDIRECTINPUTDEVICE8A iface,
1163         HINSTANCE hinst,
1164         DWORD dwVersion,
1165         REFGUID rguid)
1166 {
1167     FIXME("(this=%p,%p,%d,%s): stub!\n",
1168           iface, hinst, dwVersion, debugstr_guid(rguid));
1169     return DI_OK;
1170 }
1171
1172 /******************************************************************************
1173  *      IDirectInputDevice2A
1174  */
1175
1176 HRESULT WINAPI IDirectInputDevice2AImpl_CreateEffect(
1177         LPDIRECTINPUTDEVICE8A iface,
1178         REFGUID rguid,
1179         LPCDIEFFECT lpeff,
1180         LPDIRECTINPUTEFFECT *ppdef,
1181         LPUNKNOWN pUnkOuter)
1182 {
1183     FIXME("(this=%p,%s,%p,%p,%p): stub!\n",
1184           iface, debugstr_guid(rguid), lpeff, ppdef, pUnkOuter);
1185     return DI_OK;
1186 }
1187
1188 HRESULT WINAPI IDirectInputDevice2AImpl_EnumEffects(
1189         LPDIRECTINPUTDEVICE8A iface,
1190         LPDIENUMEFFECTSCALLBACKA lpCallback,
1191         LPVOID lpvRef,
1192         DWORD dwFlags)
1193 {
1194     FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1195           iface, lpCallback, lpvRef, dwFlags);
1196     
1197     return DI_OK;
1198 }
1199
1200 HRESULT WINAPI IDirectInputDevice2WImpl_EnumEffects(
1201         LPDIRECTINPUTDEVICE8W iface,
1202         LPDIENUMEFFECTSCALLBACKW lpCallback,
1203         LPVOID lpvRef,
1204         DWORD dwFlags)
1205 {
1206     FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1207           iface, lpCallback, lpvRef, dwFlags);
1208     
1209     return DI_OK;
1210 }
1211
1212 HRESULT WINAPI IDirectInputDevice2AImpl_GetEffectInfo(
1213         LPDIRECTINPUTDEVICE8A iface,
1214         LPDIEFFECTINFOA lpdei,
1215         REFGUID rguid)
1216 {
1217     FIXME("(this=%p,%p,%s): stub!\n",
1218           iface, lpdei, debugstr_guid(rguid));
1219     return DI_OK;
1220 }
1221
1222 HRESULT WINAPI IDirectInputDevice2WImpl_GetEffectInfo(
1223         LPDIRECTINPUTDEVICE8W iface,
1224         LPDIEFFECTINFOW lpdei,
1225         REFGUID rguid)
1226 {
1227     FIXME("(this=%p,%p,%s): stub!\n",
1228           iface, lpdei, debugstr_guid(rguid));
1229     return DI_OK;
1230 }
1231
1232 HRESULT WINAPI IDirectInputDevice2AImpl_GetForceFeedbackState(
1233         LPDIRECTINPUTDEVICE8A iface,
1234         LPDWORD pdwOut)
1235 {
1236     FIXME("(this=%p,%p): stub!\n",
1237           iface, pdwOut);
1238     return DI_OK;
1239 }
1240
1241 HRESULT WINAPI IDirectInputDevice2AImpl_SendForceFeedbackCommand(
1242         LPDIRECTINPUTDEVICE8A iface,
1243         DWORD dwFlags)
1244 {
1245     TRACE("(%p) 0x%08x:\n", iface, dwFlags);
1246     return DI_NOEFFECT;
1247 }
1248
1249 HRESULT WINAPI IDirectInputDevice2AImpl_EnumCreatedEffectObjects(
1250         LPDIRECTINPUTDEVICE8A iface,
1251         LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback,
1252         LPVOID lpvRef,
1253         DWORD dwFlags)
1254 {
1255     FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1256           iface, lpCallback, lpvRef, dwFlags);
1257     return DI_OK;
1258 }
1259
1260 HRESULT WINAPI IDirectInputDevice2AImpl_Escape(
1261         LPDIRECTINPUTDEVICE8A iface,
1262         LPDIEFFESCAPE lpDIEEsc)
1263 {
1264     FIXME("(this=%p,%p): stub!\n",
1265           iface, lpDIEEsc);
1266     return DI_OK;
1267 }
1268
1269 HRESULT WINAPI IDirectInputDevice2AImpl_Poll(
1270         LPDIRECTINPUTDEVICE8A iface)
1271 {
1272     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
1273
1274     if (!This->acquired) return DIERR_NOTACQUIRED;
1275     /* Because wine devices do not need to be polled, just return DI_NOEFFECT */
1276     return DI_NOEFFECT;
1277 }
1278
1279 HRESULT WINAPI IDirectInputDevice2AImpl_SendDeviceData(
1280         LPDIRECTINPUTDEVICE8A iface,
1281         DWORD cbObjectData,
1282         LPCDIDEVICEOBJECTDATA rgdod,
1283         LPDWORD pdwInOut,
1284         DWORD dwFlags)
1285 {
1286     FIXME("(this=%p,0x%08x,%p,%p,0x%08x): stub!\n",
1287           iface, cbObjectData, rgdod, pdwInOut, dwFlags);
1288     
1289     return DI_OK;
1290 }
1291
1292 HRESULT WINAPI IDirectInputDevice7AImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8A iface,
1293                                                           LPCSTR lpszFileName,
1294                                                           LPDIENUMEFFECTSINFILECALLBACK pec,
1295                                                           LPVOID pvRef,
1296                                                           DWORD dwFlags)
1297 {
1298     FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", iface, lpszFileName, pec, pvRef, dwFlags);
1299     
1300     return DI_OK;
1301 }
1302
1303 HRESULT WINAPI IDirectInputDevice7WImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8W iface,
1304                                                           LPCWSTR lpszFileName,
1305                                                           LPDIENUMEFFECTSINFILECALLBACK pec,
1306                                                           LPVOID pvRef,
1307                                                           DWORD dwFlags)
1308 {
1309     FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", iface, debugstr_w(lpszFileName), pec, pvRef, dwFlags);
1310     
1311     return DI_OK;
1312 }
1313
1314 HRESULT WINAPI IDirectInputDevice7AImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8A iface,
1315                                                           LPCSTR lpszFileName,
1316                                                           DWORD dwEntries,
1317                                                           LPDIFILEEFFECT rgDiFileEft,
1318                                                           DWORD dwFlags)
1319 {
1320     FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", iface, lpszFileName, dwEntries, rgDiFileEft, dwFlags);
1321     
1322     return DI_OK;
1323 }
1324
1325 HRESULT WINAPI IDirectInputDevice7WImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8W iface,
1326                                                           LPCWSTR lpszFileName,
1327                                                           DWORD dwEntries,
1328                                                           LPDIFILEEFFECT rgDiFileEft,
1329                                                           DWORD dwFlags)
1330 {
1331     FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", iface, debugstr_w(lpszFileName), dwEntries, rgDiFileEft, dwFlags);
1332     
1333     return DI_OK;
1334 }
1335
1336 HRESULT WINAPI IDirectInputDevice8AImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface,
1337                                                        LPDIACTIONFORMATA lpdiaf,
1338                                                        LPCSTR lpszUserName,
1339                                                        DWORD dwFlags)
1340 {
1341     FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, lpszUserName, dwFlags);
1342 #define X(x) if (dwFlags & x) FIXME("\tdwFlags =|"#x"\n");
1343         X(DIDBAM_DEFAULT)
1344         X(DIDBAM_PRESERVE)
1345         X(DIDBAM_INITIALIZE)
1346         X(DIDBAM_HWDEFAULTS)
1347 #undef X
1348     _dump_diactionformatA(lpdiaf);
1349     return DI_OK;
1350 }
1351
1352 HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface,
1353                                                        LPDIACTIONFORMATW lpdiaf,
1354                                                        LPCWSTR lpszUserName,
1355                                                        DWORD dwFlags)
1356 {
1357     FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
1358 #define X(x) if (dwFlags & x) FIXME("\tdwFlags =|"#x"\n");
1359         X(DIDBAM_DEFAULT)
1360         X(DIDBAM_PRESERVE)
1361         X(DIDBAM_INITIALIZE)
1362         X(DIDBAM_HWDEFAULTS)
1363 #undef X
1364   
1365     return DI_OK;
1366 }
1367
1368 HRESULT WINAPI IDirectInputDevice8AImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface,
1369                                                      LPDIACTIONFORMATA lpdiaf,
1370                                                      LPCSTR lpszUserName,
1371                                                      DWORD dwFlags)
1372 {
1373     FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, lpszUserName, dwFlags);
1374     
1375     return DI_OK;
1376 }
1377
1378 HRESULT WINAPI IDirectInputDevice8WImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
1379                                                      LPDIACTIONFORMATW lpdiaf,
1380                                                      LPCWSTR lpszUserName,
1381                                                      DWORD dwFlags)
1382 {
1383     FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
1384     
1385     return DI_OK;
1386 }
1387
1388 HRESULT WINAPI IDirectInputDevice8AImpl_GetImageInfo(LPDIRECTINPUTDEVICE8A iface,
1389                                                      LPDIDEVICEIMAGEINFOHEADERA lpdiDevImageInfoHeader)
1390 {
1391     FIXME("(%p)->(%p): stub !\n", iface, lpdiDevImageInfoHeader);
1392     
1393     return DI_OK;
1394 }
1395
1396 HRESULT WINAPI IDirectInputDevice8WImpl_GetImageInfo(LPDIRECTINPUTDEVICE8W iface,
1397                                                      LPDIDEVICEIMAGEINFOHEADERW lpdiDevImageInfoHeader)
1398 {
1399     FIXME("(%p)->(%p): stub !\n", iface, lpdiDevImageInfoHeader);
1400     
1401     return DI_OK;
1402 }