dinput: Freed effect should remove itself from the parent's list of effects. Add...
[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 debugstr_guid(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             if (asked_format->rgodf[j].dwType & DIDFT_POV)
456                 dt[index].value = -1;
457             else
458                 dt[index].value = 0;
459             index++;
460
461             same = 0;
462         }
463     }
464     
465     format->internal_format_size = format->wine_df->dwDataSize;
466     format->size = index;
467     if (same) {
468         HeapFree(GetProcessHeap(), 0, dt);
469         dt = NULL;
470     }
471     format->dt = dt;
472
473     HeapFree(GetProcessHeap(), 0, done);
474
475     return DI_OK;
476
477 failed:
478     HeapFree(GetProcessHeap(), 0, done);
479     HeapFree(GetProcessHeap(), 0, dt);
480     format->dt = NULL;
481     HeapFree(GetProcessHeap(), 0, format->offsets);
482     format->offsets = NULL;
483     HeapFree(GetProcessHeap(), 0, format->user_df);
484     format->user_df = NULL;
485
486     return DIERR_OUTOFMEMORY;
487 }
488
489 /* find an object by it's offset in a data format */
490 static int offset_to_object(const DataFormat *df, int offset)
491 {
492     int i;
493
494     if (!df->offsets) return -1;
495
496     for (i = 0; i < df->wine_df->dwNumObjs; i++)
497         if (df->offsets[i] == offset) return i;
498
499     return -1;
500 }
501
502 int id_to_object(LPCDIDATAFORMAT df, int id)
503 {
504     int i;
505
506     id &= 0x00ffffff;
507     for (i = 0; i < df->dwNumObjs; i++)
508         if ((dataformat_to_odf(df, i)->dwType & 0x00ffffff) == id)
509             return i;
510
511     return -1;
512 }
513
514 int id_to_offset(const DataFormat *df, int id)
515 {
516     int obj = id_to_object(df->wine_df, id);
517
518     return obj >= 0 && df->offsets ? df->offsets[obj] : -1;
519 }
520
521 int find_property(const DataFormat *df, LPCDIPROPHEADER ph)
522 {
523     switch (ph->dwHow)
524     {
525         case DIPH_BYID:     return id_to_object(df->wine_df, ph->dwObj);
526         case DIPH_BYOFFSET: return offset_to_object(df, ph->dwObj);
527     }
528     FIXME("Unhandled ph->dwHow=='%04X'\n", (unsigned int)ph->dwHow);
529
530     return -1;
531 }
532
533
534 BOOL DIEnumDevicesCallbackAtoW(LPCDIDEVICEOBJECTINSTANCEA lpddi, LPVOID lpvRef) {
535     DIDEVICEOBJECTINSTANCEW ddtmp;
536     device_enumobjects_AtoWcb_data* data;
537
538     data = (device_enumobjects_AtoWcb_data*) lpvRef;
539     
540     memset(&ddtmp, 0, sizeof(ddtmp));
541     
542     ddtmp.dwSize = sizeof(DIDEVICEINSTANCEW);
543     ddtmp.guidType     = lpddi->guidType;
544     ddtmp.dwOfs        = lpddi->dwOfs;
545     ddtmp.dwType       = lpddi->dwType;
546     ddtmp.dwFlags      = lpddi->dwFlags;
547     MultiByteToWideChar(CP_ACP, 0, lpddi->tszName, -1, ddtmp.tszName, MAX_PATH);
548     
549     if (lpddi->dwSize == sizeof(DIDEVICEINSTANCEA)) {
550         /**
551          * if dwSize < sizeof(DIDEVICEINSTANCEA of DInput version >= 5)
552          *  force feedback and other newer data aren't available
553          */
554         ddtmp.dwFFMaxForce        = lpddi->dwFFMaxForce;
555         ddtmp.dwFFForceResolution = lpddi->dwFFForceResolution;
556         ddtmp.wCollectionNumber   = lpddi->wCollectionNumber;
557         ddtmp.wDesignatorIndex    = lpddi->wDesignatorIndex;
558         ddtmp.wUsagePage          = lpddi->wUsagePage;
559         ddtmp.wUsage              = lpddi->wUsage;
560         ddtmp.dwDimension         = lpddi->dwDimension;
561         ddtmp.wExponent           = lpddi->wExponent;
562         ddtmp.wReserved           = lpddi->wReserved;
563     }
564     return data->lpCallBack(&ddtmp, data->lpvRef);
565 }
566
567 /******************************************************************************
568  *      queue_event - add new event to the ring queue
569  */
570
571 void queue_event(LPDIRECTINPUTDEVICE8A iface, int ofs, DWORD data, DWORD time, DWORD seq)
572 {
573     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
574     int next_pos;
575
576     /* Event is being set regardless of the queue state */
577     if (This->hEvent) SetEvent(This->hEvent);
578
579     if (!This->queue_len || This->overflow || ofs < 0) return;
580
581     next_pos = (This->queue_head + 1) % This->queue_len;
582     if (next_pos == This->queue_tail)
583     {
584         TRACE(" queue overflowed\n");
585         This->overflow = TRUE;
586         return;
587     }
588
589     TRACE(" queueing %d at offset %d (queue head %d / size %d)\n",
590           data, ofs, This->queue_head, This->queue_len);
591
592     This->data_queue[This->queue_head].dwOfs       = ofs;
593     This->data_queue[This->queue_head].dwData      = data;
594     This->data_queue[This->queue_head].dwTimeStamp = time;
595     This->data_queue[This->queue_head].dwSequence  = seq;
596     This->queue_head = next_pos;
597     /* Send event if asked */
598 }
599
600 /******************************************************************************
601  *      Acquire
602  */
603
604 HRESULT WINAPI IDirectInputDevice2AImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
605 {
606     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
607     HRESULT res;
608
609     if (!This->data_format.user_df) return DIERR_INVALIDPARAM;
610     if (This->dwCoopLevel & DISCL_FOREGROUND && This->win != GetForegroundWindow())
611         return DIERR_OTHERAPPHASPRIO;
612
613     EnterCriticalSection(&This->crit);
614     res = This->acquired ? S_FALSE : DI_OK;
615     This->acquired = 1;
616     if (res == DI_OK)
617     {
618         This->queue_head = This->queue_tail = This->overflow = 0;
619         check_dinput_hooks(iface);
620     }
621     LeaveCriticalSection(&This->crit);
622
623     return res;
624 }
625
626 /******************************************************************************
627  *      Unacquire
628  */
629
630 HRESULT WINAPI IDirectInputDevice2AImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
631 {
632     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
633     HRESULT res;
634
635     EnterCriticalSection(&This->crit);
636     res = !This->acquired ? DI_NOEFFECT : DI_OK;
637     This->acquired = 0;
638     if (res == DI_OK)
639         check_dinput_hooks(iface);
640     LeaveCriticalSection(&This->crit);
641
642     return res;
643 }
644
645 /******************************************************************************
646  *      IDirectInputDeviceA
647  */
648
649 HRESULT WINAPI IDirectInputDevice2AImpl_SetDataFormat(
650         LPDIRECTINPUTDEVICE8A iface, LPCDIDATAFORMAT df)
651 {
652     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
653     HRESULT res = DI_OK;
654
655     if (!df) return E_POINTER;
656     TRACE("(%p) %p\n", This, df);
657     _dump_DIDATAFORMAT(df);
658
659     if (df->dwSize != sizeof(DIDATAFORMAT)) return DIERR_INVALIDPARAM;
660     if (This->acquired) return DIERR_ACQUIRED;
661
662     EnterCriticalSection(&This->crit);
663
664     release_DataFormat(&This->data_format);
665     res = create_DataFormat(df, &This->data_format);
666
667     LeaveCriticalSection(&This->crit);
668     return res;
669 }
670
671 /******************************************************************************
672   *     SetCooperativeLevel
673   *
674   *  Set cooperative level and the source window for the events.
675   */
676 HRESULT WINAPI IDirectInputDevice2AImpl_SetCooperativeLevel(
677         LPDIRECTINPUTDEVICE8A iface, HWND hwnd, DWORD dwflags)
678 {
679     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
680
681     TRACE("(%p) %p,0x%08x\n", This, hwnd, dwflags);
682     _dump_cooperativelevel_DI(dwflags);
683
684     if ((dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == 0 ||
685         (dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE) ||
686         (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == 0 ||
687         (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == (DISCL_FOREGROUND | DISCL_BACKGROUND))
688         return DIERR_INVALIDPARAM;
689
690     if (dwflags == (DISCL_NONEXCLUSIVE | DISCL_BACKGROUND))
691         hwnd = GetDesktopWindow();
692
693     if (!hwnd) return E_HANDLE;
694
695     /* For security reasons native does not allow exclusive background level
696        for mouse and keyboard only */
697     if (dwflags & DISCL_EXCLUSIVE && dwflags & DISCL_BACKGROUND &&
698         (IsEqualGUID(&This->guid, &GUID_SysMouse) ||
699          IsEqualGUID(&This->guid, &GUID_SysKeyboard)))
700         return DIERR_UNSUPPORTED;
701
702     /* Store the window which asks for the mouse */
703     EnterCriticalSection(&This->crit);
704     This->win = hwnd;
705     This->dwCoopLevel = dwflags;
706     LeaveCriticalSection(&This->crit);
707
708     return DI_OK;
709 }
710
711 /******************************************************************************
712   *     SetEventNotification : specifies event to be sent on state change
713   */
714 HRESULT WINAPI IDirectInputDevice2AImpl_SetEventNotification(
715         LPDIRECTINPUTDEVICE8A iface, HANDLE event)
716 {
717     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
718
719     TRACE("(%p) %p\n", This, event);
720
721     EnterCriticalSection(&This->crit);
722     This->hEvent = event;
723     LeaveCriticalSection(&This->crit);
724     return DI_OK;
725 }
726
727 ULONG WINAPI IDirectInputDevice2AImpl_Release(LPDIRECTINPUTDEVICE8A iface)
728 {
729     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
730     ULONG ref;
731
732     ref = InterlockedDecrement(&(This->ref));
733     if (ref) return ref;
734
735     IDirectInputDevice_Unacquire(iface);
736     /* Reset the FF state, free all effects, etc */
737     IDirectInputDevice8_SendForceFeedbackCommand(iface, DISFFC_RESET);
738
739     HeapFree(GetProcessHeap(), 0, This->data_queue);
740
741     /* Free data format */
742     HeapFree(GetProcessHeap(), 0, This->data_format.wine_df->rgodf);
743     HeapFree(GetProcessHeap(), 0, This->data_format.wine_df);
744     release_DataFormat(&This->data_format);
745
746     EnterCriticalSection( &This->dinput->crit );
747     list_remove( &This->entry );
748     LeaveCriticalSection( &This->dinput->crit );
749
750     IDirectInput_Release((LPDIRECTINPUTDEVICE8A)This->dinput);
751     This->crit.DebugInfo->Spare[0] = 0;
752     DeleteCriticalSection(&This->crit);
753
754     HeapFree(GetProcessHeap(), 0, This);
755
756     return DI_OK;
757 }
758
759 HRESULT WINAPI IDirectInputDevice2AImpl_QueryInterface(
760         LPDIRECTINPUTDEVICE8A iface,REFIID riid,LPVOID *ppobj
761 )
762 {
763     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
764     
765     TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
766     if (IsEqualGUID(&IID_IUnknown,riid)) {
767         IDirectInputDevice2_AddRef(iface);
768         *ppobj = This;
769         return DI_OK;
770     }
771     if (IsEqualGUID(&IID_IDirectInputDeviceA,riid)) {
772         IDirectInputDevice2_AddRef(iface);
773         *ppobj = This;
774         return DI_OK;
775     }
776     if (IsEqualGUID(&IID_IDirectInputDevice2A,riid)) {
777         IDirectInputDevice2_AddRef(iface);
778         *ppobj = This;
779         return DI_OK;
780     }
781     if (IsEqualGUID(&IID_IDirectInputDevice7A,riid)) {
782         IDirectInputDevice7_AddRef(iface);
783         *ppobj = This;
784         return DI_OK;
785     }
786     if (IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
787         IDirectInputDevice8_AddRef(iface);
788         *ppobj = This;
789         return DI_OK;
790     }
791     TRACE("Unsupported interface !\n");
792     return E_FAIL;
793 }
794
795 HRESULT WINAPI IDirectInputDevice2WImpl_QueryInterface(
796         LPDIRECTINPUTDEVICE8W iface,REFIID riid,LPVOID *ppobj
797 )
798 {
799     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
800     
801     TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
802     if (IsEqualGUID(&IID_IUnknown,riid)) {
803         IDirectInputDevice2_AddRef(iface);
804         *ppobj = This;
805         return DI_OK;
806     }
807     if (IsEqualGUID(&IID_IDirectInputDeviceW,riid)) {
808         IDirectInputDevice2_AddRef(iface);
809         *ppobj = This;
810         return DI_OK;
811     }
812     if (IsEqualGUID(&IID_IDirectInputDevice2W,riid)) {
813         IDirectInputDevice2_AddRef(iface);
814         *ppobj = This;
815         return DI_OK;
816     }
817     if (IsEqualGUID(&IID_IDirectInputDevice7W,riid)) {
818         IDirectInputDevice7_AddRef(iface);
819         *ppobj = This;
820         return DI_OK;
821     }
822     if (IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
823         IDirectInputDevice8_AddRef(iface);
824         *ppobj = This;
825         return DI_OK;
826     }
827     TRACE("Unsupported interface !\n");
828     return E_FAIL;
829 }
830
831 ULONG WINAPI IDirectInputDevice2AImpl_AddRef(
832         LPDIRECTINPUTDEVICE8A iface)
833 {
834     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
835     return InterlockedIncrement(&(This->ref));
836 }
837
838 HRESULT WINAPI IDirectInputDevice2AImpl_EnumObjects(LPDIRECTINPUTDEVICE8A iface,
839         LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback, LPVOID lpvRef, DWORD dwFlags)
840 {
841     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
842     DIDEVICEOBJECTINSTANCEA ddoi;
843     int i;
844
845     TRACE("(%p) %p,%p flags:%08x)\n", iface, lpCallback, lpvRef, dwFlags);
846     TRACE("  - flags = ");
847     _dump_EnumObjects_flags(dwFlags);
848     TRACE("\n");
849
850     /* Only the fields till dwFFMaxForce are relevant */
851     memset(&ddoi, 0, sizeof(ddoi));
852     ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce);
853
854     for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++)
855     {
856         LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(This->data_format.wine_df, i);
857
858         if (dwFlags != DIDFT_ALL && !(dwFlags & DIEFT_GETTYPE(odf->dwType))) continue;
859         if (IDirectInputDevice_GetObjectInfo(iface, &ddoi, odf->dwType, DIPH_BYID) != DI_OK)
860             continue;
861
862         if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) break;
863     }
864
865     return DI_OK;
866 }
867
868 HRESULT WINAPI IDirectInputDevice2WImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface,
869         LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback, LPVOID lpvRef, DWORD dwFlags)
870 {
871     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
872     DIDEVICEOBJECTINSTANCEW ddoi;
873     int i;
874
875     TRACE("(%p) %p,%p flags:%08x)\n", iface, lpCallback, lpvRef, dwFlags);
876     TRACE("  - flags = ");
877     _dump_EnumObjects_flags(dwFlags);
878     TRACE("\n");
879
880     /* Only the fields till dwFFMaxForce are relevant */
881     memset(&ddoi, 0, sizeof(ddoi));
882     ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEW, dwFFMaxForce);
883
884     for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++)
885     {
886         LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(This->data_format.wine_df, i);
887
888         if (dwFlags != DIDFT_ALL && !(dwFlags & DIEFT_GETTYPE(odf->dwType))) continue;
889         if (IDirectInputDevice_GetObjectInfo(iface, &ddoi, odf->dwType, DIPH_BYID) != DI_OK)
890             continue;
891
892         if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) break;
893     }
894
895     return DI_OK;
896 }
897
898 /******************************************************************************
899  *      GetProperty
900  */
901
902 HRESULT WINAPI IDirectInputDevice2AImpl_GetProperty(
903         LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPDIPROPHEADER pdiph)
904 {
905     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
906
907     TRACE("(%p) %s,%p\n", iface, debugstr_guid(rguid), pdiph);
908     _dump_DIPROPHEADER(pdiph);
909
910     if (HIWORD(rguid)) return DI_OK;
911
912     switch (LOWORD(rguid))
913     {
914         case (DWORD) DIPROP_BUFFERSIZE:
915         {
916             LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
917
918             if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
919
920             pd->dwData = This->queue_len;
921             TRACE("buffersize = %d\n", pd->dwData);
922             break;
923         }
924         default:
925             WARN("Unknown property %s\n", debugstr_guid(rguid));
926             break;
927     }
928
929     return DI_OK;
930 }
931
932 /******************************************************************************
933  *      SetProperty
934  */
935
936 HRESULT WINAPI IDirectInputDevice2AImpl_SetProperty(
937         LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPCDIPROPHEADER pdiph)
938 {
939     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
940
941     TRACE("(%p) %s,%p\n", iface, debugstr_guid(rguid), pdiph);
942     _dump_DIPROPHEADER(pdiph);
943
944     if (HIWORD(rguid)) return DI_OK;
945
946     switch (LOWORD(rguid))
947     {
948         case (DWORD) DIPROP_AXISMODE:
949         {
950             LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph;
951
952             if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
953             if (pdiph->dwHow == DIPH_DEVICE && pdiph->dwObj) return DIERR_INVALIDPARAM;
954             if (This->acquired) return DIERR_ACQUIRED;
955             if (pdiph->dwHow != DIPH_DEVICE) return DIERR_UNSUPPORTED;
956             if (!This->data_format.user_df) return DI_OK;
957
958             TRACE("Axis mode: %s\n", pd->dwData == DIPROPAXISMODE_ABS ? "absolute" :
959                                                                         "relative");
960
961             EnterCriticalSection(&This->crit);
962             This->data_format.user_df->dwFlags &= ~DIDFT_AXIS;
963             This->data_format.user_df->dwFlags |= pd->dwData == DIPROPAXISMODE_ABS ?
964                                                   DIDF_ABSAXIS : DIDF_RELAXIS;
965             LeaveCriticalSection(&This->crit);
966             break;
967         }
968         case (DWORD) DIPROP_BUFFERSIZE:
969         {
970             LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph;
971
972             if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
973             if (This->acquired) return DIERR_ACQUIRED;
974
975             TRACE("buffersize = %d\n", pd->dwData);
976
977             EnterCriticalSection(&This->crit);
978             HeapFree(GetProcessHeap(), 0, This->data_queue);
979
980             This->data_queue = !pd->dwData ? NULL : HeapAlloc(GetProcessHeap(), 0,
981                                 pd->dwData * sizeof(DIDEVICEOBJECTDATA));
982             This->queue_head = This->queue_tail = This->overflow = 0;
983             This->queue_len  = pd->dwData;
984
985             LeaveCriticalSection(&This->crit);
986             break;
987         }
988         default:
989             WARN("Unknown property %s\n", debugstr_guid(rguid));
990             return DIERR_UNSUPPORTED;
991     }
992
993     return DI_OK;
994 }
995
996 HRESULT WINAPI IDirectInputDevice2AImpl_GetObjectInfo(
997         LPDIRECTINPUTDEVICE8A iface,
998         LPDIDEVICEOBJECTINSTANCEA pdidoi,
999         DWORD dwObj,
1000         DWORD dwHow)
1001 {
1002     DIDEVICEOBJECTINSTANCEW didoiW;
1003     HRESULT res;
1004
1005     if (!pdidoi ||
1006         (pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCEA) &&
1007          pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCE_DX3A)))
1008         return DIERR_INVALIDPARAM;
1009
1010     didoiW.dwSize = sizeof(didoiW);
1011     res = IDirectInputDevice2WImpl_GetObjectInfo((LPDIRECTINPUTDEVICE8W)iface, &didoiW, dwObj, dwHow);
1012     if (res == DI_OK)
1013     {
1014         DWORD dwSize = pdidoi->dwSize;
1015
1016         memset(pdidoi, 0, pdidoi->dwSize);
1017         pdidoi->dwSize   = dwSize;
1018         pdidoi->guidType = didoiW.guidType;
1019         pdidoi->dwOfs    = didoiW.dwOfs;
1020         pdidoi->dwType   = didoiW.dwType;
1021         pdidoi->dwFlags  = didoiW.dwFlags;
1022     }
1023
1024     return res;
1025 }
1026
1027 HRESULT WINAPI IDirectInputDevice2WImpl_GetObjectInfo(
1028         LPDIRECTINPUTDEVICE8W iface,
1029         LPDIDEVICEOBJECTINSTANCEW pdidoi,
1030         DWORD dwObj,
1031         DWORD dwHow)
1032 {
1033     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
1034     DWORD dwSize;
1035     LPDIOBJECTDATAFORMAT odf;
1036     int idx = -1;
1037
1038     TRACE("(%p) %d(0x%08x) -> %p\n", This, dwHow, dwObj, pdidoi);
1039
1040     if (!pdidoi ||
1041         (pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCEW) &&
1042          pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCE_DX3W)))
1043         return DIERR_INVALIDPARAM;
1044
1045     switch (dwHow)
1046     {
1047     case DIPH_BYOFFSET:
1048         if (!This->data_format.offsets) break;
1049         for (idx = This->data_format.wine_df->dwNumObjs - 1; idx >= 0; idx--)
1050             if (This->data_format.offsets[idx] == dwObj) break;
1051         break;
1052     case DIPH_BYID:
1053         dwObj &= 0x00ffffff;
1054         for (idx = This->data_format.wine_df->dwNumObjs - 1; idx >= 0; idx--)
1055             if ((dataformat_to_odf(This->data_format.wine_df, idx)->dwType & 0x00ffffff) == dwObj)
1056                 break;
1057         break;
1058
1059     case DIPH_BYUSAGE:
1060         FIXME("dwHow = DIPH_BYUSAGE not implemented\n");
1061         break;
1062     default:
1063         WARN("invalid parameter: dwHow = %08x\n", dwHow);
1064         return DIERR_INVALIDPARAM;
1065     }
1066     if (idx < 0) return DIERR_OBJECTNOTFOUND;
1067
1068     odf = dataformat_to_odf(This->data_format.wine_df, idx);
1069     dwSize = pdidoi->dwSize; /* save due to memset below */
1070     memset(pdidoi, 0, pdidoi->dwSize);
1071     pdidoi->dwSize   = dwSize;
1072     if (odf->pguid) pdidoi->guidType = *odf->pguid;
1073     pdidoi->dwOfs    = This->data_format.offsets ? This->data_format.offsets[idx] : odf->dwOfs;
1074     pdidoi->dwType   = odf->dwType;
1075     pdidoi->dwFlags  = odf->dwFlags;
1076
1077     return DI_OK;
1078 }
1079
1080 HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceData(
1081         LPDIRECTINPUTDEVICE8A iface, DWORD dodsize, LPDIDEVICEOBJECTDATA dod,
1082         LPDWORD entries, DWORD flags)
1083 {
1084     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
1085     HRESULT ret = DI_OK;
1086     int len;
1087
1088     TRACE("(%p) %p -> %p(%d) x%d, 0x%08x\n",
1089           This, dod, entries, entries ? *entries : 0, dodsize, flags);
1090
1091     if (!This->acquired)
1092         return DIERR_NOTACQUIRED;
1093     if (!This->queue_len)
1094         return DIERR_NOTBUFFERED;
1095     if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3))
1096         return DIERR_INVALIDPARAM;
1097
1098     IDirectInputDevice2_Poll(iface);
1099     EnterCriticalSection(&This->crit);
1100
1101     len = This->queue_head - This->queue_tail;
1102     if (len < 0) len += This->queue_len;
1103
1104     if ((*entries != INFINITE) && (len > *entries)) len = *entries;
1105
1106     if (dod)
1107     {
1108         int i;
1109         for (i = 0; i < len; i++)
1110         {
1111             int n = (This->queue_tail + i) % This->queue_len;
1112             memcpy((char *)dod + dodsize * i, This->data_queue + n, dodsize);
1113         }
1114     }
1115     *entries = len;
1116
1117     if (This->overflow)
1118         ret = DI_BUFFEROVERFLOW;
1119
1120     if (!(flags & DIGDD_PEEK))
1121     {
1122         /* Advance reading position */
1123         This->queue_tail = (This->queue_tail + len) % This->queue_len;
1124         This->overflow = FALSE;
1125     }
1126
1127     LeaveCriticalSection(&This->crit);
1128
1129     TRACE("Returning %d events queued\n", *entries);
1130     return ret;
1131 }
1132
1133 HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceInfo(
1134         LPDIRECTINPUTDEVICE8A iface,
1135         LPDIDEVICEINSTANCEA pdidi)
1136 {
1137     FIXME("(this=%p,%p): stub!\n",
1138           iface, pdidi);
1139     
1140     return DI_OK;
1141 }
1142
1143 HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceInfo(
1144         LPDIRECTINPUTDEVICE8W iface,
1145         LPDIDEVICEINSTANCEW pdidi)
1146 {
1147     FIXME("(this=%p,%p): stub!\n",
1148           iface, pdidi);
1149     
1150     return DI_OK;
1151 }
1152
1153 HRESULT WINAPI IDirectInputDevice2AImpl_RunControlPanel(
1154         LPDIRECTINPUTDEVICE8A iface,
1155         HWND hwndOwner,
1156         DWORD dwFlags)
1157 {
1158     FIXME("(this=%p,%p,0x%08x): stub!\n",
1159           iface, hwndOwner, dwFlags);
1160
1161     return DI_OK;
1162 }
1163
1164 HRESULT WINAPI IDirectInputDevice2AImpl_Initialize(
1165         LPDIRECTINPUTDEVICE8A iface,
1166         HINSTANCE hinst,
1167         DWORD dwVersion,
1168         REFGUID rguid)
1169 {
1170     FIXME("(this=%p,%p,%d,%s): stub!\n",
1171           iface, hinst, dwVersion, debugstr_guid(rguid));
1172     return DI_OK;
1173 }
1174
1175 /******************************************************************************
1176  *      IDirectInputDevice2A
1177  */
1178
1179 HRESULT WINAPI IDirectInputDevice2AImpl_CreateEffect(
1180         LPDIRECTINPUTDEVICE8A iface,
1181         REFGUID rguid,
1182         LPCDIEFFECT lpeff,
1183         LPDIRECTINPUTEFFECT *ppdef,
1184         LPUNKNOWN pUnkOuter)
1185 {
1186     FIXME("(this=%p,%s,%p,%p,%p): stub!\n",
1187           iface, debugstr_guid(rguid), lpeff, ppdef, pUnkOuter);
1188     return DI_OK;
1189 }
1190
1191 HRESULT WINAPI IDirectInputDevice2AImpl_EnumEffects(
1192         LPDIRECTINPUTDEVICE8A iface,
1193         LPDIENUMEFFECTSCALLBACKA lpCallback,
1194         LPVOID lpvRef,
1195         DWORD dwFlags)
1196 {
1197     FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1198           iface, lpCallback, lpvRef, dwFlags);
1199     
1200     return DI_OK;
1201 }
1202
1203 HRESULT WINAPI IDirectInputDevice2WImpl_EnumEffects(
1204         LPDIRECTINPUTDEVICE8W iface,
1205         LPDIENUMEFFECTSCALLBACKW lpCallback,
1206         LPVOID lpvRef,
1207         DWORD dwFlags)
1208 {
1209     FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1210           iface, lpCallback, lpvRef, dwFlags);
1211     
1212     return DI_OK;
1213 }
1214
1215 HRESULT WINAPI IDirectInputDevice2AImpl_GetEffectInfo(
1216         LPDIRECTINPUTDEVICE8A iface,
1217         LPDIEFFECTINFOA lpdei,
1218         REFGUID rguid)
1219 {
1220     FIXME("(this=%p,%p,%s): stub!\n",
1221           iface, lpdei, debugstr_guid(rguid));
1222     return DI_OK;
1223 }
1224
1225 HRESULT WINAPI IDirectInputDevice2WImpl_GetEffectInfo(
1226         LPDIRECTINPUTDEVICE8W iface,
1227         LPDIEFFECTINFOW lpdei,
1228         REFGUID rguid)
1229 {
1230     FIXME("(this=%p,%p,%s): stub!\n",
1231           iface, lpdei, debugstr_guid(rguid));
1232     return DI_OK;
1233 }
1234
1235 HRESULT WINAPI IDirectInputDevice2AImpl_GetForceFeedbackState(
1236         LPDIRECTINPUTDEVICE8A iface,
1237         LPDWORD pdwOut)
1238 {
1239     FIXME("(this=%p,%p): stub!\n",
1240           iface, pdwOut);
1241     return DI_OK;
1242 }
1243
1244 HRESULT WINAPI IDirectInputDevice2AImpl_SendForceFeedbackCommand(
1245         LPDIRECTINPUTDEVICE8A iface,
1246         DWORD dwFlags)
1247 {
1248     TRACE("(%p) 0x%08x:\n", iface, dwFlags);
1249     return DI_NOEFFECT;
1250 }
1251
1252 HRESULT WINAPI IDirectInputDevice2AImpl_EnumCreatedEffectObjects(
1253         LPDIRECTINPUTDEVICE8A iface,
1254         LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback,
1255         LPVOID lpvRef,
1256         DWORD dwFlags)
1257 {
1258     FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1259           iface, lpCallback, lpvRef, dwFlags);
1260     return DI_OK;
1261 }
1262
1263 HRESULT WINAPI IDirectInputDevice2AImpl_Escape(
1264         LPDIRECTINPUTDEVICE8A iface,
1265         LPDIEFFESCAPE lpDIEEsc)
1266 {
1267     FIXME("(this=%p,%p): stub!\n",
1268           iface, lpDIEEsc);
1269     return DI_OK;
1270 }
1271
1272 HRESULT WINAPI IDirectInputDevice2AImpl_Poll(
1273         LPDIRECTINPUTDEVICE8A iface)
1274 {
1275     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
1276
1277     if (!This->acquired) return DIERR_NOTACQUIRED;
1278     /* Because wine devices do not need to be polled, just return DI_NOEFFECT */
1279     return DI_NOEFFECT;
1280 }
1281
1282 HRESULT WINAPI IDirectInputDevice2AImpl_SendDeviceData(
1283         LPDIRECTINPUTDEVICE8A iface,
1284         DWORD cbObjectData,
1285         LPCDIDEVICEOBJECTDATA rgdod,
1286         LPDWORD pdwInOut,
1287         DWORD dwFlags)
1288 {
1289     FIXME("(this=%p,0x%08x,%p,%p,0x%08x): stub!\n",
1290           iface, cbObjectData, rgdod, pdwInOut, dwFlags);
1291     
1292     return DI_OK;
1293 }
1294
1295 HRESULT WINAPI IDirectInputDevice7AImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8A iface,
1296                                                           LPCSTR lpszFileName,
1297                                                           LPDIENUMEFFECTSINFILECALLBACK pec,
1298                                                           LPVOID pvRef,
1299                                                           DWORD dwFlags)
1300 {
1301     FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", iface, lpszFileName, pec, pvRef, dwFlags);
1302     
1303     return DI_OK;
1304 }
1305
1306 HRESULT WINAPI IDirectInputDevice7WImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8W iface,
1307                                                           LPCWSTR lpszFileName,
1308                                                           LPDIENUMEFFECTSINFILECALLBACK pec,
1309                                                           LPVOID pvRef,
1310                                                           DWORD dwFlags)
1311 {
1312     FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", iface, debugstr_w(lpszFileName), pec, pvRef, dwFlags);
1313     
1314     return DI_OK;
1315 }
1316
1317 HRESULT WINAPI IDirectInputDevice7AImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8A iface,
1318                                                           LPCSTR lpszFileName,
1319                                                           DWORD dwEntries,
1320                                                           LPDIFILEEFFECT rgDiFileEft,
1321                                                           DWORD dwFlags)
1322 {
1323     FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", iface, lpszFileName, dwEntries, rgDiFileEft, dwFlags);
1324     
1325     return DI_OK;
1326 }
1327
1328 HRESULT WINAPI IDirectInputDevice7WImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8W iface,
1329                                                           LPCWSTR lpszFileName,
1330                                                           DWORD dwEntries,
1331                                                           LPDIFILEEFFECT rgDiFileEft,
1332                                                           DWORD dwFlags)
1333 {
1334     FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", iface, debugstr_w(lpszFileName), dwEntries, rgDiFileEft, dwFlags);
1335     
1336     return DI_OK;
1337 }
1338
1339 HRESULT WINAPI IDirectInputDevice8AImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface,
1340                                                        LPDIACTIONFORMATA lpdiaf,
1341                                                        LPCSTR lpszUserName,
1342                                                        DWORD dwFlags)
1343 {
1344     FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, lpszUserName, dwFlags);
1345 #define X(x) if (dwFlags & x) FIXME("\tdwFlags =|"#x"\n");
1346         X(DIDBAM_DEFAULT)
1347         X(DIDBAM_PRESERVE)
1348         X(DIDBAM_INITIALIZE)
1349         X(DIDBAM_HWDEFAULTS)
1350 #undef X
1351     _dump_diactionformatA(lpdiaf);
1352     return DI_OK;
1353 }
1354
1355 HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface,
1356                                                        LPDIACTIONFORMATW lpdiaf,
1357                                                        LPCWSTR lpszUserName,
1358                                                        DWORD dwFlags)
1359 {
1360     FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
1361 #define X(x) if (dwFlags & x) FIXME("\tdwFlags =|"#x"\n");
1362         X(DIDBAM_DEFAULT)
1363         X(DIDBAM_PRESERVE)
1364         X(DIDBAM_INITIALIZE)
1365         X(DIDBAM_HWDEFAULTS)
1366 #undef X
1367   
1368     return DI_OK;
1369 }
1370
1371 HRESULT WINAPI IDirectInputDevice8AImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface,
1372                                                      LPDIACTIONFORMATA lpdiaf,
1373                                                      LPCSTR lpszUserName,
1374                                                      DWORD dwFlags)
1375 {
1376     FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, lpszUserName, dwFlags);
1377     
1378     return DI_OK;
1379 }
1380
1381 HRESULT WINAPI IDirectInputDevice8WImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
1382                                                      LPDIACTIONFORMATW lpdiaf,
1383                                                      LPCWSTR lpszUserName,
1384                                                      DWORD dwFlags)
1385 {
1386     FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
1387     
1388     return DI_OK;
1389 }
1390
1391 HRESULT WINAPI IDirectInputDevice8AImpl_GetImageInfo(LPDIRECTINPUTDEVICE8A iface,
1392                                                      LPDIDEVICEIMAGEINFOHEADERA lpdiDevImageInfoHeader)
1393 {
1394     FIXME("(%p)->(%p): stub !\n", iface, lpdiDevImageInfoHeader);
1395     
1396     return DI_OK;
1397 }
1398
1399 HRESULT WINAPI IDirectInputDevice8WImpl_GetImageInfo(LPDIRECTINPUTDEVICE8W iface,
1400                                                      LPDIDEVICEIMAGEINFOHEADERW lpdiDevImageInfoHeader)
1401 {
1402     FIXME("(%p)->(%p): stub !\n", iface, lpdiDevImageInfoHeader);
1403     
1404     return DI_OK;
1405 }