wined3d: Just return the surface from wined3d_device_get_render_target().
[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 static inline IDirectInputDeviceImpl *impl_from_IDirectInputDevice8A(IDirectInputDevice8A *iface)
45 {
46     return CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8A_iface);
47 }
48 static inline IDirectInputDeviceImpl *impl_from_IDirectInputDevice8W(IDirectInputDevice8W *iface)
49 {
50     return CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8W_iface);
51 }
52
53 static inline IDirectInputDevice8A *IDirectInputDevice8A_from_impl(IDirectInputDeviceImpl *This)
54 {
55     return &This->IDirectInputDevice8A_iface;
56 }
57 static inline IDirectInputDevice8W *IDirectInputDevice8W_from_impl(IDirectInputDeviceImpl *This)
58 {
59     return &This->IDirectInputDevice8W_iface;
60 }
61
62 /******************************************************************************
63  *      Various debugging tools
64  */
65 static void _dump_cooperativelevel_DI(DWORD dwFlags) {
66     if (TRACE_ON(dinput)) {
67         unsigned int   i;
68         static const struct {
69             DWORD       mask;
70             const char  *name;
71         } flags[] = {
72 #define FE(x) { x, #x}
73             FE(DISCL_BACKGROUND),
74             FE(DISCL_EXCLUSIVE),
75             FE(DISCL_FOREGROUND),
76             FE(DISCL_NONEXCLUSIVE),
77             FE(DISCL_NOWINKEY)
78 #undef FE
79         };
80         TRACE(" cooperative level : ");
81         for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++)
82             if (flags[i].mask & dwFlags)
83                 TRACE("%s ",flags[i].name);
84         TRACE("\n");
85     }
86 }
87
88 static void _dump_EnumObjects_flags(DWORD dwFlags) {
89     if (TRACE_ON(dinput)) {
90         unsigned int   i;
91         DWORD type, instance;
92         static const struct {
93             DWORD       mask;
94             const char  *name;
95         } flags[] = {
96 #define FE(x) { x, #x}
97             FE(DIDFT_RELAXIS),
98             FE(DIDFT_ABSAXIS),
99             FE(DIDFT_PSHBUTTON),
100             FE(DIDFT_TGLBUTTON),
101             FE(DIDFT_POV),
102             FE(DIDFT_COLLECTION),
103             FE(DIDFT_NODATA),       
104             FE(DIDFT_FFACTUATOR),
105             FE(DIDFT_FFEFFECTTRIGGER),
106             FE(DIDFT_OUTPUT),
107             FE(DIDFT_VENDORDEFINED),
108             FE(DIDFT_ALIAS),
109             FE(DIDFT_OPTIONAL)
110 #undef FE
111         };
112         type = (dwFlags & 0xFF0000FF);
113         instance = ((dwFlags >> 8) & 0xFFFF);
114         TRACE("Type:");
115         if (type == DIDFT_ALL) {
116             TRACE(" DIDFT_ALL");
117         } else {
118             for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++) {
119                 if (flags[i].mask & type) {
120                     type &= ~flags[i].mask;
121                     TRACE(" %s",flags[i].name);
122                 }
123             }
124             if (type) {
125                 TRACE(" (unhandled: %08x)", type);
126             }
127         }
128         TRACE(" / Instance: ");
129         if (instance == ((DIDFT_ANYINSTANCE >> 8) & 0xFFFF)) {
130             TRACE("DIDFT_ANYINSTANCE");
131         } else {
132             TRACE("%3d", instance);
133         }
134     }
135 }
136
137 void _dump_DIPROPHEADER(LPCDIPROPHEADER diph) {
138     if (TRACE_ON(dinput)) {
139         TRACE("  - dwObj = 0x%08x\n", diph->dwObj);
140         TRACE("  - dwHow = %s\n",
141             ((diph->dwHow == DIPH_DEVICE) ? "DIPH_DEVICE" :
142             ((diph->dwHow == DIPH_BYOFFSET) ? "DIPH_BYOFFSET" :
143             ((diph->dwHow == DIPH_BYID)) ? "DIPH_BYID" : "unknown")));
144     }
145 }
146
147 void _dump_OBJECTINSTANCEA(const DIDEVICEOBJECTINSTANCEA *ddoi) {
148     TRACE("    - enumerating : %s ('%s') - %2d - 0x%08x - %s\n",
149         debugstr_guid(&ddoi->guidType), _dump_dinput_GUID(&ddoi->guidType), ddoi->dwOfs, ddoi->dwType, ddoi->tszName);
150 }
151
152 void _dump_OBJECTINSTANCEW(const DIDEVICEOBJECTINSTANCEW *ddoi) {
153     TRACE("    - enumerating : %s ('%s'), - %2d - 0x%08x - %s\n",
154         debugstr_guid(&ddoi->guidType), _dump_dinput_GUID(&ddoi->guidType), ddoi->dwOfs, ddoi->dwType, debugstr_w(ddoi->tszName));
155 }
156
157 /* This function is a helper to convert a GUID into any possible DInput GUID out there */
158 const char *_dump_dinput_GUID(const GUID *guid) {
159     unsigned int i;
160     static const struct {
161         const GUID *guid;
162         const char *name;
163     } guids[] = {
164 #define FE(x) { &x, #x}
165         FE(GUID_XAxis),
166         FE(GUID_YAxis),
167         FE(GUID_ZAxis),
168         FE(GUID_RxAxis),
169         FE(GUID_RyAxis),
170         FE(GUID_RzAxis),
171         FE(GUID_Slider),
172         FE(GUID_Button),
173         FE(GUID_Key),
174         FE(GUID_POV),
175         FE(GUID_Unknown),
176         FE(GUID_SysMouse),
177         FE(GUID_SysKeyboard),
178         FE(GUID_Joystick),
179         FE(GUID_ConstantForce),
180         FE(GUID_RampForce),
181         FE(GUID_Square),
182         FE(GUID_Sine),
183         FE(GUID_Triangle),
184         FE(GUID_SawtoothUp),
185         FE(GUID_SawtoothDown),
186         FE(GUID_Spring),
187         FE(GUID_Damper),
188         FE(GUID_Inertia),
189         FE(GUID_Friction),
190         FE(GUID_CustomForce)
191 #undef FE
192     };
193     if (guid == NULL)
194         return "null GUID";
195     for (i = 0; i < (sizeof(guids) / sizeof(guids[0])); i++) {
196         if (IsEqualGUID(guids[i].guid, guid)) {
197             return guids[i].name;
198         }
199     }
200     return debugstr_guid(guid);
201 }
202
203 void _dump_DIDATAFORMAT(const DIDATAFORMAT *df) {
204     unsigned int i;
205
206     TRACE("Dumping DIDATAFORMAT structure:\n");
207     TRACE("  - dwSize: %d\n", df->dwSize);
208     if (df->dwSize != sizeof(DIDATAFORMAT)) {
209         WARN("Non-standard DIDATAFORMAT structure size %d\n", df->dwSize);
210     }
211     TRACE("  - dwObjsize: %d\n", df->dwObjSize);
212     if (df->dwObjSize != sizeof(DIOBJECTDATAFORMAT)) {
213         WARN("Non-standard DIOBJECTDATAFORMAT structure size %d\n", df->dwObjSize);
214     }
215     TRACE("  - dwFlags: 0x%08x (", df->dwFlags);
216     switch (df->dwFlags) {
217         case DIDF_ABSAXIS: TRACE("DIDF_ABSAXIS"); break;
218         case DIDF_RELAXIS: TRACE("DIDF_RELAXIS"); break;
219         default: TRACE("unknown"); break;
220     }
221     TRACE(")\n");
222     TRACE("  - dwDataSize: %d\n", df->dwDataSize);
223     TRACE("  - dwNumObjs: %d\n", df->dwNumObjs);
224     
225     for (i = 0; i < df->dwNumObjs; i++) {
226         TRACE("  - Object %d:\n", i);
227         TRACE("      * GUID: %s ('%s')\n", debugstr_guid(df->rgodf[i].pguid), _dump_dinput_GUID(df->rgodf[i].pguid));
228         TRACE("      * dwOfs: %d\n", df->rgodf[i].dwOfs);
229         TRACE("      * dwType: 0x%08x\n", df->rgodf[i].dwType);
230         TRACE("        "); _dump_EnumObjects_flags(df->rgodf[i].dwType); TRACE("\n");
231         TRACE("      * dwFlags: 0x%08x\n", df->rgodf[i].dwFlags);
232     }
233 }
234
235 /******************************************************************************
236  * Get the default and the app-specific config keys.
237  */
238 BOOL get_app_key(HKEY *defkey, HKEY *appkey)
239 {
240     char buffer[MAX_PATH+16];
241     DWORD len;
242
243     *appkey = 0;
244
245     /* @@ Wine registry key: HKCU\Software\Wine\DirectInput */
246     if (RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\DirectInput", defkey))
247         *defkey = 0;
248
249     len = GetModuleFileNameA(0, buffer, MAX_PATH);
250     if (len && len < MAX_PATH)
251     {
252         HKEY tmpkey;
253
254         /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DirectInput */
255         if (!RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey))
256         {
257             char *p, *appname = buffer;
258             if ((p = strrchr(appname, '/'))) appname = p + 1;
259             if ((p = strrchr(appname, '\\'))) appname = p + 1;
260             strcat(appname, "\\DirectInput");
261
262             if (RegOpenKeyA(tmpkey, appname, appkey)) *appkey = 0;
263             RegCloseKey(tmpkey);
264         }
265     }
266
267     return *defkey || *appkey;
268 }
269
270 /******************************************************************************
271  * Get a config key from either the app-specific or the default config
272  */
273 DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
274                              char *buffer, DWORD size )
275 {
276     if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE)buffer, &size ))
277         return 0;
278
279     if (defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE)buffer, &size ))
280         return 0;
281
282     return ERROR_FILE_NOT_FOUND;
283 }
284
285 /* Conversion between internal data buffer and external data buffer */
286 void fill_DataFormat(void *out, DWORD size, const void *in, const DataFormat *df)
287 {
288     int i;
289     const char *in_c = in;
290     char *out_c = out;
291
292     memset(out, 0, size);
293     if (df->dt == NULL) {
294         /* This means that the app uses Wine's internal data format */
295         memcpy(out, in, min(size, df->internal_format_size));
296     } else {
297         for (i = 0; i < df->size; i++) {
298             if (df->dt[i].offset_in >= 0) {
299                 switch (df->dt[i].size) {
300                     case 1:
301                         TRACE("Copying (c) to %d from %d (value %d)\n",
302                               df->dt[i].offset_out, df->dt[i].offset_in, *(in_c + df->dt[i].offset_in));
303                         *(out_c + df->dt[i].offset_out) = *(in_c + df->dt[i].offset_in);
304                         break;
305
306                     case 2:
307                         TRACE("Copying (s) to %d from %d (value %d)\n",
308                               df->dt[i].offset_out, df->dt[i].offset_in, *((const short *)(in_c + df->dt[i].offset_in)));
309                         *((short *)(out_c + df->dt[i].offset_out)) = *((const short *)(in_c + df->dt[i].offset_in));
310                         break;
311
312                     case 4:
313                         TRACE("Copying (i) to %d from %d (value %d)\n",
314                               df->dt[i].offset_out, df->dt[i].offset_in, *((const int *)(in_c + df->dt[i].offset_in)));
315                         *((int *)(out_c + df->dt[i].offset_out)) = *((const int *)(in_c + df->dt[i].offset_in));
316                         break;
317
318                     default:
319                         memcpy((out_c + df->dt[i].offset_out), (in_c + df->dt[i].offset_in), df->dt[i].size);
320                         break;
321                 }
322             } else {
323                 switch (df->dt[i].size) {
324                     case 1:
325                         TRACE("Copying (c) to %d default value %d\n",
326                               df->dt[i].offset_out, df->dt[i].value);
327                         *(out_c + df->dt[i].offset_out) = (char) df->dt[i].value;
328                         break;
329                         
330                     case 2:
331                         TRACE("Copying (s) to %d default value %d\n",
332                               df->dt[i].offset_out, df->dt[i].value);
333                         *((short *) (out_c + df->dt[i].offset_out)) = (short) df->dt[i].value;
334                         break;
335                         
336                     case 4:
337                         TRACE("Copying (i) to %d default value %d\n",
338                               df->dt[i].offset_out, df->dt[i].value);
339                         *((int *) (out_c + df->dt[i].offset_out)) = df->dt[i].value;
340                         break;
341                         
342                     default:
343                         memset((out_c + df->dt[i].offset_out), 0, df->dt[i].size);
344                         break;
345                 }
346             }
347         }
348     }
349 }
350
351 void release_DataFormat(DataFormat * format)
352 {
353     TRACE("Deleting DataFormat: %p\n", format);
354
355     HeapFree(GetProcessHeap(), 0, format->dt);
356     format->dt = NULL;
357     HeapFree(GetProcessHeap(), 0, format->offsets);
358     format->offsets = NULL;
359     HeapFree(GetProcessHeap(), 0, format->user_df);
360     format->user_df = NULL;
361 }
362
363 static inline LPDIOBJECTDATAFORMAT dataformat_to_odf(LPCDIDATAFORMAT df, int idx)
364 {
365     if (idx < 0 || idx >= df->dwNumObjs) return NULL;
366     return (LPDIOBJECTDATAFORMAT)((LPBYTE)df->rgodf + idx * df->dwObjSize);
367 }
368
369 /* dataformat_to_odf_by_type
370  *  Find the Nth object of the selected type in the DataFormat
371  */
372 LPDIOBJECTDATAFORMAT dataformat_to_odf_by_type(LPCDIDATAFORMAT df, int n, DWORD type)
373 {
374     int i, nfound = 0;
375
376     for (i=0; i < df->dwNumObjs; i++)
377     {
378         LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(df, i);
379
380         if (odf->dwType & type)
381         {
382             if (n == nfound)
383                 return odf;
384
385             nfound++;
386         }
387     }
388
389     return NULL;
390 }
391
392 static HRESULT create_DataFormat(LPCDIDATAFORMAT asked_format, DataFormat *format)
393 {
394     DataTransform *dt;
395     unsigned int i, j;
396     int same = 1;
397     int *done;
398     int index = 0;
399     DWORD next = 0;
400
401     if (!format->wine_df) return DIERR_INVALIDPARAM;
402     done = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, asked_format->dwNumObjs * sizeof(int));
403     dt = HeapAlloc(GetProcessHeap(), 0, asked_format->dwNumObjs * sizeof(DataTransform));
404     if (!dt || !done) goto failed;
405
406     if (!(format->offsets = HeapAlloc(GetProcessHeap(), 0, format->wine_df->dwNumObjs * sizeof(int))))
407         goto failed;
408
409     if (!(format->user_df = HeapAlloc(GetProcessHeap(), 0, asked_format->dwSize)))
410         goto failed;
411     memcpy(format->user_df, asked_format, asked_format->dwSize);
412
413     TRACE("Creating DataTransform :\n");
414     
415     for (i = 0; i < format->wine_df->dwNumObjs; i++)
416     {
417         format->offsets[i] = -1;
418
419         for (j = 0; j < asked_format->dwNumObjs; j++) {
420             if (done[j] == 1)
421                 continue;
422             
423             if (/* Check if the application either requests any GUID and if not, it if matches
424                  * the GUID of the Wine object.
425                  */
426                 ((asked_format->rgodf[j].pguid == NULL) ||
427                  (format->wine_df->rgodf[i].pguid == NULL) ||
428                  (IsEqualGUID(format->wine_df->rgodf[i].pguid, asked_format->rgodf[j].pguid)))
429                 &&
430                 (/* Then check if it accepts any instance id, and if not, if it matches Wine's
431                   * instance id.
432                   */
433                  ((asked_format->rgodf[j].dwType & DIDFT_INSTANCEMASK) == DIDFT_ANYINSTANCE) ||
434                  (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == 0x00FF) || /* This is mentioned in no DX docs, but it works fine - tested on WinXP */
435                  (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == DIDFT_GETINSTANCE(format->wine_df->rgodf[i].dwType)))
436                 &&
437                 ( /* Then if the asked type matches the one Wine provides */
438                  DIDFT_GETTYPE(asked_format->rgodf[j].dwType) & format->wine_df->rgodf[i].dwType))
439             {
440                 done[j] = 1;
441                 
442                 TRACE("Matching :\n");
443                 TRACE("   - Asked (%d) :\n", j);
444                 TRACE("       * GUID: %s ('%s')\n",
445                       debugstr_guid(asked_format->rgodf[j].pguid),
446                       _dump_dinput_GUID(asked_format->rgodf[j].pguid));
447                 TRACE("       * Offset: %3d\n", asked_format->rgodf[j].dwOfs);
448                 TRACE("       * dwType: %08x\n", asked_format->rgodf[j].dwType);
449                 TRACE("         "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
450                 
451                 TRACE("   - Wine  (%d) :\n", i);
452                 TRACE("       * GUID: %s ('%s')\n",
453                       debugstr_guid(format->wine_df->rgodf[i].pguid),
454                       _dump_dinput_GUID(format->wine_df->rgodf[i].pguid));
455                 TRACE("       * Offset: %3d\n", format->wine_df->rgodf[i].dwOfs);
456                 TRACE("       * dwType: %08x\n", format->wine_df->rgodf[i].dwType);
457                 TRACE("         "); _dump_EnumObjects_flags(format->wine_df->rgodf[i].dwType); TRACE("\n");
458                 
459                 if (format->wine_df->rgodf[i].dwType & DIDFT_BUTTON)
460                     dt[index].size = sizeof(BYTE);
461                 else
462                     dt[index].size = sizeof(DWORD);
463                 dt[index].offset_in = format->wine_df->rgodf[i].dwOfs;
464                 dt[index].offset_out = asked_format->rgodf[j].dwOfs;
465                 format->offsets[i]   = asked_format->rgodf[j].dwOfs;
466                 dt[index].value = 0;
467                 next = next + dt[index].size;
468                 
469                 if (format->wine_df->rgodf[i].dwOfs != dt[index].offset_out)
470                     same = 0;
471                 
472                 index++;
473                 break;
474             }
475         }
476     }
477
478     TRACE("Setting to default value :\n");
479     for (j = 0; j < asked_format->dwNumObjs; j++) {
480         if (done[j] == 0) {
481             TRACE("   - Asked (%d) :\n", j);
482             TRACE("       * GUID: %s ('%s')\n",
483                   debugstr_guid(asked_format->rgodf[j].pguid),
484                   _dump_dinput_GUID(asked_format->rgodf[j].pguid));
485             TRACE("       * Offset: %3d\n", asked_format->rgodf[j].dwOfs);
486             TRACE("       * dwType: %08x\n", asked_format->rgodf[j].dwType);
487             TRACE("         "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
488             
489             if (asked_format->rgodf[j].dwType & DIDFT_BUTTON)
490                 dt[index].size = sizeof(BYTE);
491             else
492                 dt[index].size = sizeof(DWORD);
493             dt[index].offset_in  = -1;
494             dt[index].offset_out = asked_format->rgodf[j].dwOfs;
495             if (asked_format->rgodf[j].dwType & DIDFT_POV)
496                 dt[index].value = -1;
497             else
498                 dt[index].value = 0;
499             index++;
500
501             same = 0;
502         }
503     }
504     
505     format->internal_format_size = format->wine_df->dwDataSize;
506     format->size = index;
507     if (same) {
508         HeapFree(GetProcessHeap(), 0, dt);
509         dt = NULL;
510     }
511     format->dt = dt;
512
513     HeapFree(GetProcessHeap(), 0, done);
514
515     return DI_OK;
516
517 failed:
518     HeapFree(GetProcessHeap(), 0, done);
519     HeapFree(GetProcessHeap(), 0, dt);
520     format->dt = NULL;
521     HeapFree(GetProcessHeap(), 0, format->offsets);
522     format->offsets = NULL;
523     HeapFree(GetProcessHeap(), 0, format->user_df);
524     format->user_df = NULL;
525
526     return DIERR_OUTOFMEMORY;
527 }
528
529 /* find an object by it's offset in a data format */
530 static int offset_to_object(const DataFormat *df, int offset)
531 {
532     int i;
533
534     if (!df->offsets) return -1;
535
536     for (i = 0; i < df->wine_df->dwNumObjs; i++)
537         if (df->offsets[i] == offset) return i;
538
539     return -1;
540 }
541
542 int id_to_object(LPCDIDATAFORMAT df, int id)
543 {
544     int i;
545
546     id &= 0x00ffffff;
547     for (i = 0; i < df->dwNumObjs; i++)
548         if ((dataformat_to_odf(df, i)->dwType & 0x00ffffff) == id)
549             return i;
550
551     return -1;
552 }
553
554 static int id_to_offset(const DataFormat *df, int id)
555 {
556     int obj = id_to_object(df->wine_df, id);
557
558     return obj >= 0 && df->offsets ? df->offsets[obj] : -1;
559 }
560
561 int find_property(const DataFormat *df, LPCDIPROPHEADER ph)
562 {
563     switch (ph->dwHow)
564     {
565         case DIPH_BYID:     return id_to_object(df->wine_df, ph->dwObj);
566         case DIPH_BYOFFSET: return offset_to_object(df, ph->dwObj);
567     }
568     FIXME("Unhandled ph->dwHow=='%04X'\n", (unsigned int)ph->dwHow);
569
570     return -1;
571 }
572
573 static DWORD semantic_to_obj_id(IDirectInputDeviceImpl* This, DWORD dwSemantic)
574 {
575     DWORD type = (0x0000ff00 & dwSemantic) >> 8;
576     DWORD offset = 0x000000ff & dwSemantic;
577     DWORD obj_instance = 0;
578     DWORD found = 0;
579     int i;
580
581     for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++)
582     {
583         LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(This->data_format.wine_df, i);
584
585         if (odf->dwOfs == offset)
586         {
587             obj_instance = DIDFT_GETINSTANCE(odf->dwType);
588             found = 1;
589             break;
590         }
591     }
592
593     if (!found) return 0;
594
595     if (type & DIDFT_AXIS)   type = DIDFT_RELAXIS;
596     if (type & DIDFT_BUTTON) type = DIDFT_PSHBUTTON;
597
598     return type | (0x0000ff00 & (obj_instance << 8));
599 }
600
601 /*
602  * get_mapping_key
603  * Retrieves an open registry key to save the mapping, parametrized for an username,
604  * specific device and specific action mapping guid.
605  */
606 static HKEY get_mapping_key(const WCHAR *device, const WCHAR *username, const WCHAR *guid)
607 {
608     static const WCHAR subkey[] = {
609         'S','o','f','t','w','a','r','e','\\',
610         'W','i','n','e','\\',
611         'D','i','r','e','c','t','I','n','p','u','t','\\',
612         'M','a','p','p','i','n','g','s','\\','%','s','\\','%','s','\\','%','s','\0'};
613     HKEY hkey;
614     WCHAR *keyname;
615
616     keyname = HeapAlloc(GetProcessHeap(), 0,
617         sizeof(WCHAR) * (lstrlenW(subkey) + strlenW(username) + strlenW(device) + strlenW(guid)));
618     sprintfW(keyname, subkey, username, device, guid);
619
620     /* The key used is HKCU\Software\Wine\DirectInput\Mappings\[username]\[device]\[mapping_guid] */
621     if (RegCreateKeyW(HKEY_CURRENT_USER, keyname, &hkey))
622         hkey = 0;
623
624     HeapFree(GetProcessHeap(), 0, keyname);
625
626     return hkey;
627 }
628
629 static HRESULT save_mapping_settings(IDirectInputDevice8W *iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUsername)
630 {
631     WCHAR *guid_str = NULL;
632     DIDEVICEINSTANCEW didev;
633     HKEY hkey;
634     int i;
635
636     didev.dwSize = sizeof(didev);
637     IDirectInputDevice8_GetDeviceInfo(iface, &didev);
638
639     if (StringFromCLSID(&lpdiaf->guidActionMap, &guid_str) != S_OK)
640         return DI_SETTINGSNOTSAVED;
641
642     hkey = get_mapping_key(didev.tszInstanceName, lpszUsername, guid_str);
643
644     if (!hkey)
645     {
646         CoTaskMemFree(guid_str);
647         return DI_SETTINGSNOTSAVED;
648     }
649
650     /* Write each of the actions mapped for this device.
651        Format is "dwSemantic"="dwObjID" and key is of type REG_DWORD
652     */
653     for (i = 0; i < lpdiaf->dwNumActions; i++)
654     {
655         static const WCHAR format[] = {'%','x','\0'};
656         WCHAR label[9];
657
658         if (IsEqualGUID(&didev.guidInstance, &lpdiaf->rgoAction[i].guidInstance) &&
659             lpdiaf->rgoAction[i].dwHow != DIAH_UNMAPPED)
660         {
661              sprintfW(label, format, lpdiaf->rgoAction[i].dwSemantic);
662              RegSetValueExW(hkey, label, 0, REG_DWORD, (const BYTE*) &lpdiaf->rgoAction[i].dwObjID, sizeof(DWORD));
663         }
664     }
665
666     RegCloseKey(hkey);
667     CoTaskMemFree(guid_str);
668
669     return DI_OK;
670 }
671
672 static BOOL load_mapping_settings(IDirectInputDeviceImpl *This, LPDIACTIONFORMATW lpdiaf, const WCHAR *username)
673 {
674     HKEY hkey;
675     WCHAR *guid_str;
676     DIDEVICEINSTANCEW didev;
677     int i, mapped = 0;
678
679     didev.dwSize = sizeof(didev);
680     IDirectInputDevice8_GetDeviceInfo(&This->IDirectInputDevice8W_iface, &didev);
681
682     if (StringFromCLSID(&lpdiaf->guidActionMap, &guid_str) != S_OK)
683         return FALSE;
684
685     hkey = get_mapping_key(didev.tszInstanceName, username, guid_str);
686
687     if (!hkey)
688     {
689         CoTaskMemFree(guid_str);
690         return FALSE;
691     }
692
693     /* Try to read each action in the DIACTIONFORMAT from registry */
694     for (i = 0; i < lpdiaf->dwNumActions; i++)
695     {
696         static const WCHAR format[] = {'%','x','\0'};
697         DWORD id, size = sizeof(DWORD);
698         WCHAR label[9];
699
700         sprintfW(label, format, lpdiaf->rgoAction[i].dwSemantic);
701
702         if (!RegQueryValueExW(hkey, label, 0, NULL, (LPBYTE) &id, &size))
703         {
704             lpdiaf->rgoAction[i].dwObjID = id;
705             lpdiaf->rgoAction[i].guidInstance = didev.guidInstance;
706             lpdiaf->rgoAction[i].dwHow = DIAH_DEFAULT;
707             mapped += 1;
708         }
709     }
710
711     RegCloseKey(hkey);
712     CoTaskMemFree(guid_str);
713
714     return mapped > 0;
715 }
716
717 HRESULT _build_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags, DWORD devMask, LPCDIDATAFORMAT df)
718 {
719     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
720     WCHAR username[MAX_PATH];
721     DWORD username_size = MAX_PATH;
722     int i, has_actions = 0;
723     BOOL load_success = FALSE;
724
725     /* Unless asked the contrary by these flags, try to load a previous mapping */
726     if (!(dwFlags & DIDBAM_HWDEFAULTS))
727     {
728         /* Retrieve logged user name if necessary */
729         if (lpszUserName == NULL)
730             GetUserNameW(username, &username_size);
731         else
732             lstrcpynW(username, lpszUserName, MAX_PATH);
733
734         load_success = load_mapping_settings(This, lpdiaf, username);
735     }
736
737     if (load_success) return DI_OK;
738
739     for (i=0; i < lpdiaf->dwNumActions; i++)
740     {
741         /* Don't touch a user configured action */
742         if (lpdiaf->rgoAction[i].dwHow == DIAH_USERCONFIG) continue;
743
744         if ((lpdiaf->rgoAction[i].dwSemantic & devMask) == devMask)
745         {
746             DWORD obj_id = semantic_to_obj_id(This, lpdiaf->rgoAction[i].dwSemantic);
747             DWORD type = DIDFT_GETTYPE(obj_id);
748             DWORD inst = DIDFT_GETINSTANCE(obj_id);
749
750             LPDIOBJECTDATAFORMAT odf;
751
752             if (type == DIDFT_PSHBUTTON) type = DIDFT_BUTTON;
753             if (type == DIDFT_RELAXIS) type = DIDFT_AXIS;
754
755             /* Make sure the object exists */
756             odf = dataformat_to_odf_by_type(df, inst, type);
757
758             if (odf != NULL)
759             {
760                 lpdiaf->rgoAction[i].dwObjID = obj_id;
761                 lpdiaf->rgoAction[i].guidInstance = This->guid;
762                 lpdiaf->rgoAction[i].dwHow = DIAH_DEFAULT;
763                 has_actions = 1;
764             }
765         }
766         else if (!(dwFlags & DIDBAM_PRESERVE))
767         {
768             /* We must clear action data belonging to other devices */
769             memset(&lpdiaf->rgoAction[i].guidInstance, 0, sizeof(GUID));
770             lpdiaf->rgoAction[i].dwHow = DIAH_UNMAPPED;
771         }
772     }
773
774     if (!has_actions) return DI_NOEFFECT;
775
776     return  IDirectInputDevice8WImpl_BuildActionMap(iface, lpdiaf, lpszUserName, dwFlags);
777 }
778
779 HRESULT _set_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags, LPCDIDATAFORMAT df)
780 {
781     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
782     DIDATAFORMAT data_format;
783     DIOBJECTDATAFORMAT *obj_df = NULL;
784     DIPROPDWORD dp;
785     DIPROPRANGE dpr;
786     WCHAR username[MAX_PATH];
787     DWORD username_size = MAX_PATH;
788     int i, action = 0, num_actions = 0;
789     unsigned int offset = 0;
790
791     if (This->acquired) return DIERR_ACQUIRED;
792
793     data_format.dwSize = sizeof(data_format);
794     data_format.dwObjSize = sizeof(DIOBJECTDATAFORMAT);
795     data_format.dwFlags = DIDF_RELAXIS;
796     data_format.dwDataSize = lpdiaf->dwDataSize;
797
798     /* Count the actions */
799     for (i=0; i < lpdiaf->dwNumActions; i++)
800         if (IsEqualGUID(&This->guid, &lpdiaf->rgoAction[i].guidInstance))
801             num_actions++;
802
803     if (num_actions == 0) return DI_NOEFFECT;
804
805     This->num_actions = num_actions;
806
807     /* Construct the dataformat and actionmap */
808     obj_df = HeapAlloc(GetProcessHeap(), 0, sizeof(DIOBJECTDATAFORMAT)*num_actions);
809     data_format.rgodf = (LPDIOBJECTDATAFORMAT)obj_df;
810     data_format.dwNumObjs = num_actions;
811
812     HeapFree(GetProcessHeap(), 0, This->action_map);
813     This->action_map = HeapAlloc(GetProcessHeap(), 0, sizeof(ActionMap)*num_actions);
814
815     for (i = 0; i < lpdiaf->dwNumActions; i++)
816     {
817         if (IsEqualGUID(&This->guid, &lpdiaf->rgoAction[i].guidInstance))
818         {
819             DWORD inst = DIDFT_GETINSTANCE(lpdiaf->rgoAction[i].dwObjID);
820             DWORD type = DIDFT_GETTYPE(lpdiaf->rgoAction[i].dwObjID);
821             LPDIOBJECTDATAFORMAT obj;
822
823             if (type == DIDFT_PSHBUTTON) type = DIDFT_BUTTON;
824             if (type == DIDFT_RELAXIS) type = DIDFT_AXIS;
825
826             obj = dataformat_to_odf_by_type(df, inst, type);
827
828             memcpy(&obj_df[action], obj, df->dwObjSize);
829
830             This->action_map[action].uAppData = lpdiaf->rgoAction[i].uAppData;
831             This->action_map[action].offset = offset;
832             obj_df[action].dwOfs = offset;
833             offset += (type & DIDFT_BUTTON) ? 1 : 4;
834
835             action++;
836         }
837     }
838
839     IDirectInputDevice8_SetDataFormat(iface, &data_format);
840
841     HeapFree(GetProcessHeap(), 0, obj_df);
842
843     /* Set the device properties according to the action format */
844     dpr.diph.dwSize = sizeof(DIPROPRANGE);
845     dpr.lMin = lpdiaf->lAxisMin;
846     dpr.lMax = lpdiaf->lAxisMax;
847     dpr.diph.dwHeaderSize = sizeof(DIPROPHEADER);
848     dpr.diph.dwHow = DIPH_DEVICE;
849     IDirectInputDevice8_SetProperty(iface, DIPROP_RANGE, &dpr.diph);
850
851     if (lpdiaf->dwBufferSize > 0)
852     {
853         dp.diph.dwSize = sizeof(DIPROPDWORD);
854         dp.dwData = lpdiaf->dwBufferSize;
855         dp.diph.dwHeaderSize = sizeof(DIPROPHEADER);
856         dp.diph.dwHow = DIPH_DEVICE;
857         IDirectInputDevice8_SetProperty(iface, DIPROP_BUFFERSIZE, &dp.diph);
858     }
859
860     /* Retrieve logged user name if necessary */
861     if (lpszUserName == NULL)
862         GetUserNameW(username, &username_size);
863     else
864         lstrcpynW(username, lpszUserName, MAX_PATH);
865
866     /* Save the settings to disk */
867     save_mapping_settings(iface, lpdiaf, username);
868
869     return IDirectInputDevice8WImpl_SetActionMap(iface, lpdiaf, lpszUserName, dwFlags);
870 }
871
872 /******************************************************************************
873  *      queue_event - add new event to the ring queue
874  */
875
876 void queue_event(LPDIRECTINPUTDEVICE8A iface, int inst_id, DWORD data, DWORD time, DWORD seq)
877 {
878     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
879     int next_pos, ofs = id_to_offset(&This->data_format, inst_id);
880
881     /* Event is being set regardless of the queue state */
882     if (This->hEvent) SetEvent(This->hEvent);
883
884     if (!This->queue_len || This->overflow || ofs < 0) return;
885
886     next_pos = (This->queue_head + 1) % This->queue_len;
887     if (next_pos == This->queue_tail)
888     {
889         TRACE(" queue overflowed\n");
890         This->overflow = TRUE;
891         return;
892     }
893
894     TRACE(" queueing %d at offset %d (queue head %d / size %d)\n",
895           data, ofs, This->queue_head, This->queue_len);
896
897     This->data_queue[This->queue_head].dwOfs       = ofs;
898     This->data_queue[This->queue_head].dwData      = data;
899     This->data_queue[This->queue_head].dwTimeStamp = time;
900     This->data_queue[This->queue_head].dwSequence  = seq;
901
902     /* Set uAppData by means of action mapping */
903     if (This->num_actions > 0)
904     {
905         int i;
906         for (i=0; i < This->num_actions; i++)
907         {
908             if (This->action_map[i].offset == ofs)
909             {
910                 TRACE("Offset %d mapped to uAppData %lu\n", ofs, This->action_map[i].uAppData);
911                 This->data_queue[This->queue_head].uAppData = This->action_map[i].uAppData;
912                 break;
913             }
914         }
915     }
916
917     This->queue_head = next_pos;
918     /* Send event if asked */
919 }
920
921 /******************************************************************************
922  *      Acquire
923  */
924
925 HRESULT WINAPI IDirectInputDevice2WImpl_Acquire(LPDIRECTINPUTDEVICE8W iface)
926 {
927     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
928     HRESULT res;
929
930     TRACE("(%p)\n", This);
931
932     if (!This->data_format.user_df) return DIERR_INVALIDPARAM;
933     if (This->dwCoopLevel & DISCL_FOREGROUND && This->win != GetForegroundWindow())
934         return DIERR_OTHERAPPHASPRIO;
935
936     EnterCriticalSection(&This->crit);
937     res = This->acquired ? S_FALSE : DI_OK;
938     This->acquired = 1;
939     if (res == DI_OK)
940         check_dinput_hooks(iface);
941     LeaveCriticalSection(&This->crit);
942
943     return res;
944 }
945
946 HRESULT WINAPI IDirectInputDevice2AImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
947 {
948     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
949     return IDirectInputDevice2WImpl_Acquire(IDirectInputDevice8W_from_impl(This));
950 }
951
952
953 /******************************************************************************
954  *      Unacquire
955  */
956
957 HRESULT WINAPI IDirectInputDevice2WImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface)
958 {
959     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
960     HRESULT res;
961
962     TRACE("(%p)\n", This);
963
964     EnterCriticalSection(&This->crit);
965     res = !This->acquired ? DI_NOEFFECT : DI_OK;
966     This->acquired = 0;
967     if (res == DI_OK)
968         check_dinput_hooks(iface);
969     LeaveCriticalSection(&This->crit);
970
971     return res;
972 }
973
974 HRESULT WINAPI IDirectInputDevice2AImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
975 {
976     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
977     return IDirectInputDevice2WImpl_Unacquire(IDirectInputDevice8W_from_impl(This));
978 }
979
980 /******************************************************************************
981  *      IDirectInputDeviceA
982  */
983
984 HRESULT WINAPI IDirectInputDevice2WImpl_SetDataFormat(LPDIRECTINPUTDEVICE8W iface, LPCDIDATAFORMAT df)
985 {
986     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
987     HRESULT res = DI_OK;
988
989     if (!df) return E_POINTER;
990     TRACE("(%p) %p\n", This, df);
991     _dump_DIDATAFORMAT(df);
992
993     if (df->dwSize != sizeof(DIDATAFORMAT)) return DIERR_INVALIDPARAM;
994     if (This->acquired) return DIERR_ACQUIRED;
995
996     EnterCriticalSection(&This->crit);
997
998     release_DataFormat(&This->data_format);
999     res = create_DataFormat(df, &This->data_format);
1000
1001     LeaveCriticalSection(&This->crit);
1002     return res;
1003 }
1004
1005 HRESULT WINAPI IDirectInputDevice2AImpl_SetDataFormat(LPDIRECTINPUTDEVICE8A iface, LPCDIDATAFORMAT df)
1006 {
1007     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1008     return IDirectInputDevice2WImpl_SetDataFormat(IDirectInputDevice8W_from_impl(This), df);
1009 }
1010
1011 /******************************************************************************
1012   *     SetCooperativeLevel
1013   *
1014   *  Set cooperative level and the source window for the events.
1015   */
1016 HRESULT WINAPI IDirectInputDevice2WImpl_SetCooperativeLevel(LPDIRECTINPUTDEVICE8W iface, HWND hwnd, DWORD dwflags)
1017 {
1018     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1019
1020     TRACE("(%p) %p,0x%08x\n", This, hwnd, dwflags);
1021     _dump_cooperativelevel_DI(dwflags);
1022
1023     if ((dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == 0 ||
1024         (dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE) ||
1025         (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == 0 ||
1026         (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == (DISCL_FOREGROUND | DISCL_BACKGROUND))
1027         return DIERR_INVALIDPARAM;
1028
1029     if (hwnd && GetWindowLongW(hwnd, GWL_STYLE) & WS_CHILD) return E_HANDLE;
1030
1031     if (dwflags == (DISCL_NONEXCLUSIVE | DISCL_BACKGROUND))
1032         hwnd = GetDesktopWindow();
1033
1034     if (!hwnd) return E_HANDLE;
1035
1036     /* For security reasons native does not allow exclusive background level
1037        for mouse and keyboard only */
1038     if (dwflags & DISCL_EXCLUSIVE && dwflags & DISCL_BACKGROUND &&
1039         (IsEqualGUID(&This->guid, &GUID_SysMouse) ||
1040          IsEqualGUID(&This->guid, &GUID_SysKeyboard)))
1041         return DIERR_UNSUPPORTED;
1042
1043     /* Store the window which asks for the mouse */
1044     EnterCriticalSection(&This->crit);
1045     This->win = hwnd;
1046     This->dwCoopLevel = dwflags;
1047     LeaveCriticalSection(&This->crit);
1048
1049     return DI_OK;
1050 }
1051
1052 HRESULT WINAPI IDirectInputDevice2AImpl_SetCooperativeLevel(LPDIRECTINPUTDEVICE8A iface, HWND hwnd, DWORD dwflags)
1053 {
1054     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1055     return IDirectInputDevice2WImpl_SetCooperativeLevel(IDirectInputDevice8W_from_impl(This), hwnd, dwflags);
1056 }
1057
1058 /******************************************************************************
1059   *     SetEventNotification : specifies event to be sent on state change
1060   */
1061 HRESULT WINAPI IDirectInputDevice2WImpl_SetEventNotification(LPDIRECTINPUTDEVICE8W iface, HANDLE event)
1062 {
1063     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1064
1065     TRACE("(%p) %p\n", This, event);
1066
1067     EnterCriticalSection(&This->crit);
1068     This->hEvent = event;
1069     LeaveCriticalSection(&This->crit);
1070     return DI_OK;
1071 }
1072
1073 HRESULT WINAPI IDirectInputDevice2AImpl_SetEventNotification(LPDIRECTINPUTDEVICE8A iface, HANDLE event)
1074 {
1075     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1076     return IDirectInputDevice2WImpl_SetEventNotification(IDirectInputDevice8W_from_impl(This), event);
1077 }
1078
1079
1080 ULONG WINAPI IDirectInputDevice2WImpl_Release(LPDIRECTINPUTDEVICE8W iface)
1081 {
1082     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1083     ULONG ref = InterlockedDecrement(&(This->ref));
1084
1085     TRACE("(%p) releasing from %d\n", This, ref + 1);
1086
1087     if (ref) return ref;
1088
1089     IDirectInputDevice_Unacquire(iface);
1090     /* Reset the FF state, free all effects, etc */
1091     IDirectInputDevice8_SendForceFeedbackCommand(iface, DISFFC_RESET);
1092
1093     HeapFree(GetProcessHeap(), 0, This->data_queue);
1094
1095     /* Free data format */
1096     HeapFree(GetProcessHeap(), 0, This->data_format.wine_df->rgodf);
1097     HeapFree(GetProcessHeap(), 0, This->data_format.wine_df);
1098     release_DataFormat(&This->data_format);
1099
1100     /* Free action mapping */
1101     HeapFree(GetProcessHeap(), 0, This->action_map);
1102
1103     EnterCriticalSection( &This->dinput->crit );
1104     list_remove( &This->entry );
1105     LeaveCriticalSection( &This->dinput->crit );
1106
1107     IDirectInput_Release(&This->dinput->IDirectInput7A_iface);
1108     This->crit.DebugInfo->Spare[0] = 0;
1109     DeleteCriticalSection(&This->crit);
1110
1111     HeapFree(GetProcessHeap(), 0, This);
1112
1113     return DI_OK;
1114 }
1115
1116 ULONG WINAPI IDirectInputDevice2AImpl_Release(LPDIRECTINPUTDEVICE8A iface)
1117 {
1118     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1119     return IDirectInputDevice2WImpl_Release(IDirectInputDevice8W_from_impl(This));
1120 }
1121
1122 HRESULT WINAPI IDirectInputDevice2WImpl_QueryInterface(LPDIRECTINPUTDEVICE8W iface, REFIID riid, LPVOID *ppobj)
1123 {
1124     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1125
1126     TRACE("(%p this=%p,%s,%p)\n", iface, This, debugstr_guid(riid), ppobj);
1127     if (IsEqualGUID(&IID_IUnknown, riid) ||
1128         IsEqualGUID(&IID_IDirectInputDeviceA,  riid) ||
1129         IsEqualGUID(&IID_IDirectInputDevice2A, riid) ||
1130         IsEqualGUID(&IID_IDirectInputDevice7A, riid) ||
1131         IsEqualGUID(&IID_IDirectInputDevice8A, riid))
1132     {
1133         IDirectInputDevice2_AddRef(iface);
1134         *ppobj = IDirectInputDevice8A_from_impl(This);
1135         return DI_OK;
1136     }
1137     if (IsEqualGUID(&IID_IDirectInputDeviceW,  riid) ||
1138         IsEqualGUID(&IID_IDirectInputDevice2W, riid) ||
1139         IsEqualGUID(&IID_IDirectInputDevice7W, riid) ||
1140         IsEqualGUID(&IID_IDirectInputDevice8W, riid))
1141     {
1142         IDirectInputDevice2_AddRef(iface);
1143         *ppobj = IDirectInputDevice8W_from_impl(This);
1144         return DI_OK;
1145     }
1146
1147     WARN("Unsupported interface!\n");
1148     return E_FAIL;
1149 }
1150
1151 HRESULT WINAPI IDirectInputDevice2AImpl_QueryInterface(LPDIRECTINPUTDEVICE8A iface, REFIID riid, LPVOID *ppobj)
1152 {
1153     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1154     return IDirectInputDevice2WImpl_QueryInterface(IDirectInputDevice8W_from_impl(This), riid, ppobj);
1155 }
1156
1157 ULONG WINAPI IDirectInputDevice2WImpl_AddRef(LPDIRECTINPUTDEVICE8W iface)
1158 {
1159     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1160     return InterlockedIncrement(&This->ref);
1161 }
1162
1163 ULONG WINAPI IDirectInputDevice2AImpl_AddRef(LPDIRECTINPUTDEVICE8A iface)
1164 {
1165     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1166     return IDirectInputDevice2WImpl_AddRef(IDirectInputDevice8W_from_impl(This));
1167 }
1168
1169 HRESULT WINAPI IDirectInputDevice2AImpl_EnumObjects(LPDIRECTINPUTDEVICE8A iface,
1170         LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback, LPVOID lpvRef, DWORD dwFlags)
1171 {
1172     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1173     DIDEVICEOBJECTINSTANCEA ddoi;
1174     int i;
1175
1176     TRACE("(%p) %p,%p flags:%08x)\n", iface, lpCallback, lpvRef, dwFlags);
1177     TRACE("  - flags = ");
1178     _dump_EnumObjects_flags(dwFlags);
1179     TRACE("\n");
1180
1181     /* Only the fields till dwFFMaxForce are relevant */
1182     memset(&ddoi, 0, sizeof(ddoi));
1183     ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce);
1184
1185     for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++)
1186     {
1187         LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(This->data_format.wine_df, i);
1188
1189         if (dwFlags != DIDFT_ALL && !(dwFlags & DIDFT_GETTYPE(odf->dwType))) continue;
1190         if (IDirectInputDevice_GetObjectInfo(iface, &ddoi, odf->dwType, DIPH_BYID) != DI_OK)
1191             continue;
1192
1193         if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) break;
1194     }
1195
1196     return DI_OK;
1197 }
1198
1199 HRESULT WINAPI IDirectInputDevice2WImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface,
1200         LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback, LPVOID lpvRef, DWORD dwFlags)
1201 {
1202     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1203     DIDEVICEOBJECTINSTANCEW ddoi;
1204     int i;
1205
1206     TRACE("(%p) %p,%p flags:%08x)\n", iface, lpCallback, lpvRef, dwFlags);
1207     TRACE("  - flags = ");
1208     _dump_EnumObjects_flags(dwFlags);
1209     TRACE("\n");
1210
1211     /* Only the fields till dwFFMaxForce are relevant */
1212     memset(&ddoi, 0, sizeof(ddoi));
1213     ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEW, dwFFMaxForce);
1214
1215     for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++)
1216     {
1217         LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(This->data_format.wine_df, i);
1218
1219         if (dwFlags != DIDFT_ALL && !(dwFlags & DIDFT_GETTYPE(odf->dwType))) continue;
1220         if (IDirectInputDevice_GetObjectInfo(iface, &ddoi, odf->dwType, DIPH_BYID) != DI_OK)
1221             continue;
1222
1223         if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) break;
1224     }
1225
1226     return DI_OK;
1227 }
1228
1229 /******************************************************************************
1230  *      GetProperty
1231  */
1232
1233 HRESULT WINAPI IDirectInputDevice2WImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface, REFGUID rguid, LPDIPROPHEADER pdiph)
1234 {
1235     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1236
1237     TRACE("(%p) %s,%p\n", iface, debugstr_guid(rguid), pdiph);
1238     _dump_DIPROPHEADER(pdiph);
1239
1240     if (!IS_DIPROP(rguid)) return DI_OK;
1241
1242     switch (LOWORD(rguid))
1243     {
1244         case (DWORD_PTR) DIPROP_BUFFERSIZE:
1245         {
1246             LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
1247
1248             if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
1249
1250             pd->dwData = This->queue_len;
1251             TRACE("buffersize = %d\n", pd->dwData);
1252             break;
1253         }
1254         case (DWORD_PTR) DIPROP_VIDPID:
1255             FIXME("DIPROP_VIDPID not implemented\n");
1256             return DIERR_UNSUPPORTED;
1257         default:
1258             FIXME("Unknown property %s\n", debugstr_guid(rguid));
1259             return DIERR_INVALIDPARAM;
1260     }
1261
1262     return DI_OK;
1263 }
1264
1265 HRESULT WINAPI IDirectInputDevice2AImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPDIPROPHEADER pdiph)
1266 {
1267     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1268     return IDirectInputDevice2WImpl_GetProperty(IDirectInputDevice8W_from_impl(This), rguid, pdiph);
1269 }
1270
1271 /******************************************************************************
1272  *      SetProperty
1273  */
1274
1275 HRESULT WINAPI IDirectInputDevice2WImpl_SetProperty(
1276         LPDIRECTINPUTDEVICE8W iface, REFGUID rguid, LPCDIPROPHEADER pdiph)
1277 {
1278     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1279
1280     TRACE("(%p) %s,%p\n", iface, debugstr_guid(rguid), pdiph);
1281     _dump_DIPROPHEADER(pdiph);
1282
1283     if (!IS_DIPROP(rguid)) return DI_OK;
1284
1285     switch (LOWORD(rguid))
1286     {
1287         case (DWORD_PTR) DIPROP_AXISMODE:
1288         {
1289             LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph;
1290
1291             if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
1292             if (pdiph->dwHow == DIPH_DEVICE && pdiph->dwObj) return DIERR_INVALIDPARAM;
1293             if (This->acquired) return DIERR_ACQUIRED;
1294             if (pdiph->dwHow != DIPH_DEVICE) return DIERR_UNSUPPORTED;
1295             if (!This->data_format.user_df) return DI_OK;
1296
1297             TRACE("Axis mode: %s\n", pd->dwData == DIPROPAXISMODE_ABS ? "absolute" :
1298                                                                         "relative");
1299
1300             EnterCriticalSection(&This->crit);
1301             This->data_format.user_df->dwFlags &= ~DIDFT_AXIS;
1302             This->data_format.user_df->dwFlags |= pd->dwData == DIPROPAXISMODE_ABS ?
1303                                                   DIDF_ABSAXIS : DIDF_RELAXIS;
1304             LeaveCriticalSection(&This->crit);
1305             break;
1306         }
1307         case (DWORD_PTR) DIPROP_BUFFERSIZE:
1308         {
1309             LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph;
1310
1311             if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
1312             if (This->acquired) return DIERR_ACQUIRED;
1313
1314             TRACE("buffersize = %d\n", pd->dwData);
1315
1316             EnterCriticalSection(&This->crit);
1317             HeapFree(GetProcessHeap(), 0, This->data_queue);
1318
1319             This->data_queue = !pd->dwData ? NULL : HeapAlloc(GetProcessHeap(), 0,
1320                                 pd->dwData * sizeof(DIDEVICEOBJECTDATA));
1321             This->queue_head = This->queue_tail = This->overflow = 0;
1322             This->queue_len  = pd->dwData;
1323
1324             LeaveCriticalSection(&This->crit);
1325             break;
1326         }
1327         default:
1328             WARN("Unknown property %s\n", debugstr_guid(rguid));
1329             return DIERR_UNSUPPORTED;
1330     }
1331
1332     return DI_OK;
1333 }
1334
1335 HRESULT WINAPI IDirectInputDevice2AImpl_SetProperty(
1336         LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPCDIPROPHEADER pdiph)
1337 {
1338     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1339     return IDirectInputDevice2WImpl_SetProperty(IDirectInputDevice8W_from_impl(This), rguid, pdiph);
1340 }
1341
1342 HRESULT WINAPI IDirectInputDevice2AImpl_GetObjectInfo(
1343         LPDIRECTINPUTDEVICE8A iface,
1344         LPDIDEVICEOBJECTINSTANCEA pdidoi,
1345         DWORD dwObj,
1346         DWORD dwHow)
1347 {
1348     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1349     DIDEVICEOBJECTINSTANCEW didoiW;
1350     HRESULT res;
1351
1352     if (!pdidoi ||
1353         (pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCEA) &&
1354          pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCE_DX3A)))
1355         return DIERR_INVALIDPARAM;
1356
1357     didoiW.dwSize = sizeof(didoiW);
1358     res = IDirectInputDevice2WImpl_GetObjectInfo(IDirectInputDevice8W_from_impl(This), &didoiW, dwObj, dwHow);
1359     if (res == DI_OK)
1360     {
1361         DWORD dwSize = pdidoi->dwSize;
1362
1363         memset(pdidoi, 0, pdidoi->dwSize);
1364         pdidoi->dwSize   = dwSize;
1365         pdidoi->guidType = didoiW.guidType;
1366         pdidoi->dwOfs    = didoiW.dwOfs;
1367         pdidoi->dwType   = didoiW.dwType;
1368         pdidoi->dwFlags  = didoiW.dwFlags;
1369     }
1370
1371     return res;
1372 }
1373
1374 HRESULT WINAPI IDirectInputDevice2WImpl_GetObjectInfo(
1375         LPDIRECTINPUTDEVICE8W iface,
1376         LPDIDEVICEOBJECTINSTANCEW pdidoi,
1377         DWORD dwObj,
1378         DWORD dwHow)
1379 {
1380     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1381     DWORD dwSize;
1382     LPDIOBJECTDATAFORMAT odf;
1383     int idx = -1;
1384
1385     TRACE("(%p) %d(0x%08x) -> %p\n", This, dwHow, dwObj, pdidoi);
1386
1387     if (!pdidoi ||
1388         (pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCEW) &&
1389          pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCE_DX3W)))
1390         return DIERR_INVALIDPARAM;
1391
1392     switch (dwHow)
1393     {
1394     case DIPH_BYOFFSET:
1395         if (!This->data_format.offsets) break;
1396         for (idx = This->data_format.wine_df->dwNumObjs - 1; idx >= 0; idx--)
1397             if (This->data_format.offsets[idx] == dwObj) break;
1398         break;
1399     case DIPH_BYID:
1400         dwObj &= 0x00ffffff;
1401         for (idx = This->data_format.wine_df->dwNumObjs - 1; idx >= 0; idx--)
1402             if ((dataformat_to_odf(This->data_format.wine_df, idx)->dwType & 0x00ffffff) == dwObj)
1403                 break;
1404         break;
1405
1406     case DIPH_BYUSAGE:
1407         FIXME("dwHow = DIPH_BYUSAGE not implemented\n");
1408         break;
1409     default:
1410         WARN("invalid parameter: dwHow = %08x\n", dwHow);
1411         return DIERR_INVALIDPARAM;
1412     }
1413     if (idx < 0) return DIERR_OBJECTNOTFOUND;
1414
1415     odf = dataformat_to_odf(This->data_format.wine_df, idx);
1416     dwSize = pdidoi->dwSize; /* save due to memset below */
1417     memset(pdidoi, 0, pdidoi->dwSize);
1418     pdidoi->dwSize   = dwSize;
1419     if (odf->pguid) pdidoi->guidType = *odf->pguid;
1420     pdidoi->dwOfs    = This->data_format.offsets ? This->data_format.offsets[idx] : odf->dwOfs;
1421     pdidoi->dwType   = odf->dwType;
1422     pdidoi->dwFlags  = odf->dwFlags;
1423
1424     return DI_OK;
1425 }
1426
1427 HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceData(LPDIRECTINPUTDEVICE8W iface, DWORD dodsize,
1428                                                       LPDIDEVICEOBJECTDATA dod, LPDWORD entries, DWORD flags)
1429 {
1430     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1431     HRESULT ret = DI_OK;
1432     int len;
1433
1434     TRACE("(%p) %p -> %p(%d) x%d, 0x%08x\n",
1435           This, dod, entries, entries ? *entries : 0, dodsize, flags);
1436
1437     if (This->dinput->dwVersion == 0x0800 || dodsize == sizeof(DIDEVICEOBJECTDATA_DX3))
1438     {
1439         if (!This->queue_len) return DIERR_NOTBUFFERED;
1440         if (!This->acquired) return DIERR_NOTACQUIRED;
1441     }
1442
1443     if (!This->queue_len)
1444         return DI_OK;
1445     if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3))
1446         return DIERR_INVALIDPARAM;
1447
1448     IDirectInputDevice2_Poll(iface);
1449     EnterCriticalSection(&This->crit);
1450
1451     len = This->queue_head - This->queue_tail;
1452     if (len < 0) len += This->queue_len;
1453
1454     if ((*entries != INFINITE) && (len > *entries)) len = *entries;
1455
1456     if (dod)
1457     {
1458         int i;
1459         for (i = 0; i < len; i++)
1460         {
1461             int n = (This->queue_tail + i) % This->queue_len;
1462             memcpy((char *)dod + dodsize * i, This->data_queue + n, dodsize);
1463         }
1464     }
1465     *entries = len;
1466
1467     if (This->overflow && This->dinput->dwVersion == 0x0800)
1468         ret = DI_BUFFEROVERFLOW;
1469
1470     if (!(flags & DIGDD_PEEK))
1471     {
1472         /* Advance reading position */
1473         This->queue_tail = (This->queue_tail + len) % This->queue_len;
1474         This->overflow = FALSE;
1475     }
1476
1477     LeaveCriticalSection(&This->crit);
1478
1479     TRACE("Returning %d events queued\n", *entries);
1480     return ret;
1481 }
1482
1483 HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface, DWORD dodsize,
1484                                                       LPDIDEVICEOBJECTDATA dod, LPDWORD entries, DWORD flags)
1485 {
1486     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1487     return IDirectInputDevice2WImpl_GetDeviceData(IDirectInputDevice8W_from_impl(This), dodsize, dod, entries, flags);
1488 }
1489
1490 HRESULT WINAPI IDirectInputDevice2WImpl_RunControlPanel(LPDIRECTINPUTDEVICE8W iface, HWND hwndOwner, DWORD dwFlags)
1491 {
1492     FIXME("(this=%p,%p,0x%08x): stub!\n", iface, hwndOwner, dwFlags);
1493
1494     return DI_OK;
1495 }
1496
1497 HRESULT WINAPI IDirectInputDevice2AImpl_RunControlPanel(LPDIRECTINPUTDEVICE8A iface, HWND hwndOwner, DWORD dwFlags)
1498 {
1499     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1500     return IDirectInputDevice2WImpl_RunControlPanel(IDirectInputDevice8W_from_impl(This), hwndOwner, dwFlags);
1501 }
1502
1503 HRESULT WINAPI IDirectInputDevice2WImpl_Initialize(LPDIRECTINPUTDEVICE8W iface, HINSTANCE hinst, DWORD dwVersion,
1504                                                    REFGUID rguid)
1505 {
1506     FIXME("(this=%p,%p,%d,%s): stub!\n", iface, hinst, dwVersion, debugstr_guid(rguid));
1507     return DI_OK;
1508 }
1509
1510 HRESULT WINAPI IDirectInputDevice2AImpl_Initialize(LPDIRECTINPUTDEVICE8A iface, HINSTANCE hinst, DWORD dwVersion,
1511                                                    REFGUID rguid)
1512 {
1513     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1514     return IDirectInputDevice2WImpl_Initialize(IDirectInputDevice8W_from_impl(This), hinst, dwVersion, rguid);
1515 }
1516
1517 /******************************************************************************
1518  *      IDirectInputDevice2A
1519  */
1520
1521 HRESULT WINAPI IDirectInputDevice2WImpl_CreateEffect(LPDIRECTINPUTDEVICE8W iface, REFGUID rguid, LPCDIEFFECT lpeff,
1522                                                      LPDIRECTINPUTEFFECT *ppdef, LPUNKNOWN pUnkOuter)
1523 {
1524     FIXME("(this=%p,%s,%p,%p,%p): stub!\n", iface, debugstr_guid(rguid), lpeff, ppdef, pUnkOuter);
1525     return DI_OK;
1526 }
1527
1528 HRESULT WINAPI IDirectInputDevice2AImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPCDIEFFECT lpeff,
1529                                                      LPDIRECTINPUTEFFECT *ppdef, LPUNKNOWN pUnkOuter)
1530 {
1531     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1532     return IDirectInputDevice2WImpl_CreateEffect(IDirectInputDevice8W_from_impl(This), rguid, lpeff, ppdef, pUnkOuter);
1533 }
1534
1535 HRESULT WINAPI IDirectInputDevice2AImpl_EnumEffects(
1536         LPDIRECTINPUTDEVICE8A iface,
1537         LPDIENUMEFFECTSCALLBACKA lpCallback,
1538         LPVOID lpvRef,
1539         DWORD dwFlags)
1540 {
1541     FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1542           iface, lpCallback, lpvRef, dwFlags);
1543     
1544     return DI_OK;
1545 }
1546
1547 HRESULT WINAPI IDirectInputDevice2WImpl_EnumEffects(
1548         LPDIRECTINPUTDEVICE8W iface,
1549         LPDIENUMEFFECTSCALLBACKW lpCallback,
1550         LPVOID lpvRef,
1551         DWORD dwFlags)
1552 {
1553     FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1554           iface, lpCallback, lpvRef, dwFlags);
1555     
1556     return DI_OK;
1557 }
1558
1559 HRESULT WINAPI IDirectInputDevice2AImpl_GetEffectInfo(
1560         LPDIRECTINPUTDEVICE8A iface,
1561         LPDIEFFECTINFOA lpdei,
1562         REFGUID rguid)
1563 {
1564     FIXME("(this=%p,%p,%s): stub!\n",
1565           iface, lpdei, debugstr_guid(rguid));
1566     return DI_OK;
1567 }
1568
1569 HRESULT WINAPI IDirectInputDevice2WImpl_GetEffectInfo(
1570         LPDIRECTINPUTDEVICE8W iface,
1571         LPDIEFFECTINFOW lpdei,
1572         REFGUID rguid)
1573 {
1574     FIXME("(this=%p,%p,%s): stub!\n",
1575           iface, lpdei, debugstr_guid(rguid));
1576     return DI_OK;
1577 }
1578
1579 HRESULT WINAPI IDirectInputDevice2WImpl_GetForceFeedbackState(LPDIRECTINPUTDEVICE8W iface, LPDWORD pdwOut)
1580 {
1581     FIXME("(this=%p,%p): stub!\n", iface, pdwOut);
1582     return DI_OK;
1583 }
1584
1585 HRESULT WINAPI IDirectInputDevice2AImpl_GetForceFeedbackState(LPDIRECTINPUTDEVICE8A iface, LPDWORD pdwOut)
1586 {
1587     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1588     return IDirectInputDevice2WImpl_GetForceFeedbackState(IDirectInputDevice8W_from_impl(This), pdwOut);
1589 }
1590
1591 HRESULT WINAPI IDirectInputDevice2WImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8W iface, DWORD dwFlags)
1592 {
1593     TRACE("(%p) 0x%08x:\n", iface, dwFlags);
1594     return DI_NOEFFECT;
1595 }
1596
1597 HRESULT WINAPI IDirectInputDevice2AImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8A iface, DWORD dwFlags)
1598 {
1599     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1600     return IDirectInputDevice2WImpl_SendForceFeedbackCommand(IDirectInputDevice8W_from_impl(This), dwFlags);
1601 }
1602
1603 HRESULT WINAPI IDirectInputDevice2WImpl_EnumCreatedEffectObjects(LPDIRECTINPUTDEVICE8W iface,
1604         LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback, LPVOID lpvRef, DWORD dwFlags)
1605 {
1606     FIXME("(this=%p,%p,%p,0x%08x): stub!\n", iface, lpCallback, lpvRef, dwFlags);
1607     return DI_OK;
1608 }
1609
1610 HRESULT WINAPI IDirectInputDevice2AImpl_EnumCreatedEffectObjects(LPDIRECTINPUTDEVICE8A iface,
1611         LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback, LPVOID lpvRef, DWORD dwFlags)
1612 {
1613     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1614     return IDirectInputDevice2WImpl_EnumCreatedEffectObjects(IDirectInputDevice8W_from_impl(This), lpCallback, lpvRef, dwFlags);
1615 }
1616
1617 HRESULT WINAPI IDirectInputDevice2WImpl_Escape(LPDIRECTINPUTDEVICE8W iface, LPDIEFFESCAPE lpDIEEsc)
1618 {
1619     FIXME("(this=%p,%p): stub!\n", iface, lpDIEEsc);
1620     return DI_OK;
1621 }
1622
1623 HRESULT WINAPI IDirectInputDevice2AImpl_Escape(LPDIRECTINPUTDEVICE8A iface, LPDIEFFESCAPE lpDIEEsc)
1624 {
1625     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1626     return IDirectInputDevice2WImpl_Escape(IDirectInputDevice8W_from_impl(This), lpDIEEsc);
1627 }
1628
1629 HRESULT WINAPI IDirectInputDevice2WImpl_Poll(LPDIRECTINPUTDEVICE8W iface)
1630 {
1631     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1632
1633     if (!This->acquired) return DIERR_NOTACQUIRED;
1634     /* Because wine devices do not need to be polled, just return DI_NOEFFECT */
1635     return DI_NOEFFECT;
1636 }
1637
1638 HRESULT WINAPI IDirectInputDevice2AImpl_Poll(LPDIRECTINPUTDEVICE8A iface)
1639 {
1640     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1641     return IDirectInputDevice2WImpl_Poll(IDirectInputDevice8W_from_impl(This));
1642 }
1643
1644 HRESULT WINAPI IDirectInputDevice2WImpl_SendDeviceData(LPDIRECTINPUTDEVICE8W iface, DWORD cbObjectData,
1645                                                        LPCDIDEVICEOBJECTDATA rgdod, LPDWORD pdwInOut,
1646                                                        DWORD dwFlags)
1647 {
1648     FIXME("(this=%p,0x%08x,%p,%p,0x%08x): stub!\n", iface, cbObjectData, rgdod, pdwInOut, dwFlags);
1649
1650     return DI_OK;
1651 }
1652
1653 HRESULT WINAPI IDirectInputDevice2AImpl_SendDeviceData(LPDIRECTINPUTDEVICE8A iface, DWORD cbObjectData,
1654                                                        LPCDIDEVICEOBJECTDATA rgdod, LPDWORD pdwInOut,
1655                                                        DWORD dwFlags)
1656 {
1657     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1658     return IDirectInputDevice2WImpl_SendDeviceData(IDirectInputDevice8W_from_impl(This), cbObjectData, rgdod,
1659                                                    pdwInOut, dwFlags);
1660 }
1661
1662 HRESULT WINAPI IDirectInputDevice7AImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8A iface,
1663                                                           LPCSTR lpszFileName,
1664                                                           LPDIENUMEFFECTSINFILECALLBACK pec,
1665                                                           LPVOID pvRef,
1666                                                           DWORD dwFlags)
1667 {
1668     FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", iface, lpszFileName, pec, pvRef, dwFlags);
1669     
1670     return DI_OK;
1671 }
1672
1673 HRESULT WINAPI IDirectInputDevice7WImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8W iface,
1674                                                           LPCWSTR lpszFileName,
1675                                                           LPDIENUMEFFECTSINFILECALLBACK pec,
1676                                                           LPVOID pvRef,
1677                                                           DWORD dwFlags)
1678 {
1679     FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", iface, debugstr_w(lpszFileName), pec, pvRef, dwFlags);
1680     
1681     return DI_OK;
1682 }
1683
1684 HRESULT WINAPI IDirectInputDevice7AImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8A iface,
1685                                                           LPCSTR lpszFileName,
1686                                                           DWORD dwEntries,
1687                                                           LPDIFILEEFFECT rgDiFileEft,
1688                                                           DWORD dwFlags)
1689 {
1690     FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", iface, lpszFileName, dwEntries, rgDiFileEft, dwFlags);
1691     
1692     return DI_OK;
1693 }
1694
1695 HRESULT WINAPI IDirectInputDevice7WImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8W iface,
1696                                                           LPCWSTR lpszFileName,
1697                                                           DWORD dwEntries,
1698                                                           LPDIFILEEFFECT rgDiFileEft,
1699                                                           DWORD dwFlags)
1700 {
1701     FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", iface, debugstr_w(lpszFileName), dwEntries, rgDiFileEft, dwFlags);
1702     
1703     return DI_OK;
1704 }
1705
1706 HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface,
1707                                                        LPDIACTIONFORMATW lpdiaf,
1708                                                        LPCWSTR lpszUserName,
1709                                                        DWORD dwFlags)
1710 {
1711     FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
1712 #define X(x) if (dwFlags & x) FIXME("\tdwFlags =|"#x"\n");
1713         X(DIDBAM_DEFAULT)
1714         X(DIDBAM_PRESERVE)
1715         X(DIDBAM_INITIALIZE)
1716         X(DIDBAM_HWDEFAULTS)
1717 #undef X
1718   
1719     return DI_OK;
1720 }
1721
1722 HRESULT WINAPI IDirectInputDevice8WImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
1723                                                      LPDIACTIONFORMATW lpdiaf,
1724                                                      LPCWSTR lpszUserName,
1725                                                      DWORD dwFlags)
1726 {
1727     FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
1728
1729     return DI_OK;
1730 }
1731
1732 HRESULT WINAPI IDirectInputDevice8AImpl_GetImageInfo(LPDIRECTINPUTDEVICE8A iface,
1733                                                      LPDIDEVICEIMAGEINFOHEADERA lpdiDevImageInfoHeader)
1734 {
1735     FIXME("(%p)->(%p): stub !\n", iface, lpdiDevImageInfoHeader);
1736     
1737     return DI_OK;
1738 }
1739
1740 HRESULT WINAPI IDirectInputDevice8WImpl_GetImageInfo(LPDIRECTINPUTDEVICE8W iface,
1741                                                      LPDIDEVICEIMAGEINFOHEADERW lpdiDevImageInfoHeader)
1742 {
1743     FIXME("(%p)->(%p): stub !\n", iface, lpdiDevImageInfoHeader);
1744     
1745     return DI_OK;
1746 }