rsaenh: Add a few more tests which check the decryption strings.
[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         for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++)
63             if (flags[i].mask & dwFlags)
64                 DPRINTF("%s ",flags[i].name);
65         DPRINTF("\n");
66     }
67 }
68
69 void _dump_EnumObjects_flags(DWORD dwFlags) {
70     if (TRACE_ON(dinput)) {
71         unsigned int   i;
72         DWORD type, instance;
73         static const struct {
74             DWORD       mask;
75             const char  *name;
76         } flags[] = {
77 #define FE(x) { x, #x}
78             FE(DIDFT_RELAXIS),
79             FE(DIDFT_ABSAXIS),
80             FE(DIDFT_PSHBUTTON),
81             FE(DIDFT_TGLBUTTON),
82             FE(DIDFT_POV),
83             FE(DIDFT_COLLECTION),
84             FE(DIDFT_NODATA),       
85             FE(DIDFT_FFACTUATOR),
86             FE(DIDFT_FFEFFECTTRIGGER),
87             FE(DIDFT_OUTPUT),
88             FE(DIDFT_VENDORDEFINED),
89             FE(DIDFT_ALIAS),
90             FE(DIDFT_OPTIONAL)
91 #undef FE
92         };
93         type = (dwFlags & 0xFF0000FF);
94         instance = ((dwFlags >> 8) & 0xFFFF);
95         DPRINTF("Type:");
96         if (type == DIDFT_ALL) {
97             DPRINTF(" DIDFT_ALL");
98         } else {
99             for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++) {
100                 if (flags[i].mask & type) {
101                     type &= ~flags[i].mask;
102                     DPRINTF(" %s",flags[i].name);
103                 }
104             }
105             if (type) {
106                 DPRINTF(" (unhandled: %08x)", type);
107             }
108         }
109         DPRINTF(" / Instance: ");
110         if (instance == ((DIDFT_ANYINSTANCE >> 8) & 0xFFFF)) {
111             DPRINTF("DIDFT_ANYINSTANCE");
112         } else {
113             DPRINTF("%3d", instance);
114         }
115     }
116 }
117
118 void _dump_DIPROPHEADER(LPCDIPROPHEADER diph) {
119     if (TRACE_ON(dinput)) {
120         DPRINTF("  - dwObj = 0x%08x\n", diph->dwObj);
121         DPRINTF("  - dwHow = %s\n",
122                 ((diph->dwHow == DIPH_DEVICE) ? "DIPH_DEVICE" :
123                  ((diph->dwHow == DIPH_BYOFFSET) ? "DIPH_BYOFFSET" :
124                   ((diph->dwHow == DIPH_BYID)) ? "DIPH_BYID" : "unknown")));
125     }
126 }
127
128 void _dump_OBJECTINSTANCEA(const DIDEVICEOBJECTINSTANCEA *ddoi) {
129     if (TRACE_ON(dinput)) {
130         DPRINTF("    - 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
135 void _dump_OBJECTINSTANCEW(const DIDEVICEOBJECTINSTANCEW *ddoi) {
136     if (TRACE_ON(dinput)) {
137         DPRINTF("    - enumerating : %s ('%s'), - %2d - 0x%08x - %s\n",
138                 debugstr_guid(&ddoi->guidType), _dump_dinput_GUID(&ddoi->guidType), ddoi->dwOfs, ddoi->dwType, debugstr_w(ddoi->tszName));
139     }
140 }
141
142 /* This function is a helper to convert a GUID into any possible DInput GUID out there */
143 const char *_dump_dinput_GUID(const GUID *guid) {
144     unsigned int i;
145     static const struct {
146         const GUID *guid;
147         const char *name;
148     } guids[] = {
149 #define FE(x) { &x, #x}
150         FE(GUID_XAxis),
151         FE(GUID_YAxis),
152         FE(GUID_ZAxis),
153         FE(GUID_RxAxis),
154         FE(GUID_RyAxis),
155         FE(GUID_RzAxis),
156         FE(GUID_Slider),
157         FE(GUID_Button),
158         FE(GUID_Key),
159         FE(GUID_POV),
160         FE(GUID_Unknown),
161         FE(GUID_SysMouse),
162         FE(GUID_SysKeyboard),
163         FE(GUID_Joystick),
164         FE(GUID_ConstantForce),
165         FE(GUID_RampForce),
166         FE(GUID_Square),
167         FE(GUID_Sine),
168         FE(GUID_Triangle),
169         FE(GUID_SawtoothUp),
170         FE(GUID_SawtoothDown),
171         FE(GUID_Spring),
172         FE(GUID_Damper),
173         FE(GUID_Inertia),
174         FE(GUID_Friction),
175         FE(GUID_CustomForce)
176 #undef FE
177     };
178     if (guid == NULL)
179         return "null GUID";
180     for (i = 0; i < (sizeof(guids) / sizeof(guids[0])); i++) {
181         if (IsEqualGUID(guids[i].guid, guid)) {
182             return guids[i].name;
183         }
184     }
185     return "Unknown GUID";
186 }
187
188 void _dump_DIDATAFORMAT(const DIDATAFORMAT *df) {
189     unsigned int i;
190
191     TRACE("Dumping DIDATAFORMAT structure:\n");
192     TRACE("  - dwSize: %d\n", df->dwSize);
193     if (df->dwSize != sizeof(DIDATAFORMAT)) {
194         WARN("Non-standard DIDATAFORMAT structure size %d\n", df->dwSize);
195     }
196     TRACE("  - dwObjsize: %d\n", df->dwObjSize);
197     if (df->dwObjSize != sizeof(DIOBJECTDATAFORMAT)) {
198         WARN("Non-standard DIOBJECTDATAFORMAT structure size %d\n", df->dwObjSize);
199     }
200     TRACE("  - dwFlags: 0x%08x (", df->dwFlags);
201     switch (df->dwFlags) {
202         case DIDF_ABSAXIS: TRACE("DIDF_ABSAXIS"); break;
203         case DIDF_RELAXIS: TRACE("DIDF_RELAXIS"); break;
204         default: TRACE("unknown"); break;
205     }
206     TRACE(")\n");
207     TRACE("  - dwDataSize: %d\n", df->dwDataSize);
208     TRACE("  - dwNumObjs: %d\n", df->dwNumObjs);
209     
210     for (i = 0; i < df->dwNumObjs; i++) {
211         TRACE("  - Object %d:\n", i);
212         TRACE("      * GUID: %s ('%s')\n", debugstr_guid(df->rgodf[i].pguid), _dump_dinput_GUID(df->rgodf[i].pguid));
213         TRACE("      * dwOfs: %d\n", df->rgodf[i].dwOfs);
214         TRACE("      * dwType: 0x%08x\n", df->rgodf[i].dwType);
215         TRACE("        "); _dump_EnumObjects_flags(df->rgodf[i].dwType); TRACE("\n");
216         TRACE("      * dwFlags: 0x%08x\n", df->rgodf[i].dwFlags);
217     }
218 }
219
220 /******************************************************************************
221  * Get the default and the app-specific config keys.
222  */
223 BOOL get_app_key(HKEY *defkey, HKEY *appkey)
224 {
225     char buffer[MAX_PATH+16];
226     DWORD len;
227
228     *appkey = 0;
229
230     /* @@ Wine registry key: HKCU\Software\Wine\DirectInput */
231     if (RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\DirectInput", defkey))
232         *defkey = 0;
233
234     len = GetModuleFileNameA(0, buffer, MAX_PATH);
235     if (len && len < MAX_PATH)
236     {
237         HKEY tmpkey;
238
239         /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DirectInput */
240         if (!RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey))
241         {
242             char *p, *appname = buffer;
243             if ((p = strrchr(appname, '/'))) appname = p + 1;
244             if ((p = strrchr(appname, '\\'))) appname = p + 1;
245             strcat(appname, "\\DirectInput");
246
247             if (RegOpenKeyA(tmpkey, appname, appkey)) *appkey = 0;
248             RegCloseKey(tmpkey);
249         }
250     }
251
252     return *defkey || *appkey;
253 }
254
255 /******************************************************************************
256  * Get a config key from either the app-specific or the default config
257  */
258 DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
259                              char *buffer, DWORD size )
260 {
261     if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE)buffer, &size ))
262         return 0;
263
264     if (defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE)buffer, &size ))
265         return 0;
266
267     return ERROR_FILE_NOT_FOUND;
268 }
269
270 /* Conversion between internal data buffer and external data buffer */
271 void fill_DataFormat(void *out, const void *in, const DataFormat *df) {
272     int i;
273     const char *in_c = in;
274     char *out_c = (char *) out;
275
276     if (df->dt == NULL) {
277         /* This means that the app uses Wine's internal data format */
278         memcpy(out, in, df->internal_format_size);
279     } else {
280         for (i = 0; i < df->size; i++) {
281             if (df->dt[i].offset_in >= 0) {
282                 switch (df->dt[i].size) {
283                     case 1:
284                         TRACE("Copying (c) to %d from %d (value %d)\n",
285                               df->dt[i].offset_out, df->dt[i].offset_in, *(in_c + df->dt[i].offset_in));
286                         *(out_c + df->dt[i].offset_out) = *(in_c + df->dt[i].offset_in);
287                         break;
288
289                     case 2:
290                         TRACE("Copying (s) to %d from %d (value %d)\n",
291                               df->dt[i].offset_out, df->dt[i].offset_in, *((const short *)(in_c + df->dt[i].offset_in)));
292                         *((short *)(out_c + df->dt[i].offset_out)) = *((const short *)(in_c + df->dt[i].offset_in));
293                         break;
294
295                     case 4:
296                         TRACE("Copying (i) to %d from %d (value %d)\n",
297                               df->dt[i].offset_out, df->dt[i].offset_in, *((const int *)(in_c + df->dt[i].offset_in)));
298                         *((int *)(out_c + df->dt[i].offset_out)) = *((const int *)(in_c + df->dt[i].offset_in));
299                         break;
300
301                     default:
302                         memcpy((out_c + df->dt[i].offset_out), (in_c + df->dt[i].offset_in), df->dt[i].size);
303                         break;
304                 }
305             } else {
306                 switch (df->dt[i].size) {
307                     case 1:
308                         TRACE("Copying (c) to %d default value %d\n",
309                               df->dt[i].offset_out, df->dt[i].value);
310                         *(out_c + df->dt[i].offset_out) = (char) df->dt[i].value;
311                         break;
312                         
313                     case 2:
314                         TRACE("Copying (s) to %d default value %d\n",
315                               df->dt[i].offset_out, df->dt[i].value);
316                         *((short *) (out_c + df->dt[i].offset_out)) = (short) df->dt[i].value;
317                         break;
318                         
319                     case 4:
320                         TRACE("Copying (i) to %d default value %d\n",
321                               df->dt[i].offset_out, df->dt[i].value);
322                         *((int *) (out_c + df->dt[i].offset_out)) = (int) df->dt[i].value;
323                         break;
324                         
325                     default:
326                         memset((out_c + df->dt[i].offset_out), 0, df->dt[i].size);
327                         break;
328                 }
329             }
330         }
331     }
332 }
333
334 void release_DataFormat(DataFormat * format)
335 {
336     TRACE("Deleting DataFormat: %p\n", format);
337
338     HeapFree(GetProcessHeap(), 0, format->dt);
339     format->dt = NULL;
340     HeapFree(GetProcessHeap(), 0, format->offsets);
341     format->offsets = NULL;
342     HeapFree(GetProcessHeap(), 0, format->user_df);
343     format->user_df = NULL;
344 }
345
346 inline LPDIOBJECTDATAFORMAT dataformat_to_odf(LPCDIDATAFORMAT df, int idx)
347 {
348     if (idx < 0 || idx >= df->dwNumObjs) return NULL;
349     return (LPDIOBJECTDATAFORMAT)((LPBYTE)df->rgodf + idx * df->dwObjSize);
350 }
351
352 HRESULT create_DataFormat(LPCDIDATAFORMAT asked_format, DataFormat *format)
353 {
354     DataTransform *dt;
355     unsigned int i, j;
356     int same = 1;
357     int *done;
358     int index = 0;
359     DWORD next = 0;
360
361     if (!format->wine_df) return DIERR_INVALIDPARAM;
362     done = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, asked_format->dwNumObjs * sizeof(int));
363     dt = HeapAlloc(GetProcessHeap(), 0, asked_format->dwNumObjs * sizeof(DataTransform));
364     if (!dt || !done) goto failed;
365
366     if (!(format->offsets = HeapAlloc(GetProcessHeap(), 0, format->wine_df->dwNumObjs * sizeof(int))))
367         goto failed;
368
369     if (!(format->user_df = HeapAlloc(GetProcessHeap(), 0, asked_format->dwSize)))
370         goto failed;
371     memcpy(format->user_df, asked_format, asked_format->dwSize);
372
373     TRACE("Creating DataTransform :\n");
374     
375     for (i = 0; i < format->wine_df->dwNumObjs; i++)
376     {
377         format->offsets[i] = -1;
378
379         for (j = 0; j < asked_format->dwNumObjs; j++) {
380             if (done[j] == 1)
381                 continue;
382             
383             if (/* Check if the application either requests any GUID and if not, it if matches
384                  * the GUID of the Wine object.
385                  */
386                 ((asked_format->rgodf[j].pguid == NULL) ||
387                  (format->wine_df->rgodf[i].pguid == NULL) ||
388                  (IsEqualGUID(format->wine_df->rgodf[i].pguid, asked_format->rgodf[j].pguid)))
389                 &&
390                 (/* Then check if it accepts any instance id, and if not, if it matches Wine's
391                   * instance id.
392                   */
393                  ((asked_format->rgodf[j].dwType & DIDFT_INSTANCEMASK) == DIDFT_ANYINSTANCE) ||
394                  (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == 0x00FF) || /* This is mentionned in no DX docs, but it works fine - tested on WinXP */
395                  (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == DIDFT_GETINSTANCE(format->wine_df->rgodf[i].dwType)))
396                 &&
397                 ( /* Then if the asked type matches the one Wine provides */
398                  DIDFT_GETTYPE(asked_format->rgodf[j].dwType) & format->wine_df->rgodf[i].dwType))
399             {
400                 done[j] = 1;
401                 
402                 TRACE("Matching :\n");
403                 TRACE("   - Asked (%d) :\n", j);
404                 TRACE("       * GUID: %s ('%s')\n",
405                       debugstr_guid(asked_format->rgodf[j].pguid),
406                       _dump_dinput_GUID(asked_format->rgodf[j].pguid));
407                 TRACE("       * Offset: %3d\n", asked_format->rgodf[j].dwOfs);
408                 TRACE("       * dwType: %08x\n", asked_format->rgodf[j].dwType);
409                 TRACE("         "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
410                 
411                 TRACE("   - Wine  (%d) :\n", i);
412                 TRACE("       * GUID: %s ('%s')\n",
413                       debugstr_guid(format->wine_df->rgodf[i].pguid),
414                       _dump_dinput_GUID(format->wine_df->rgodf[i].pguid));
415                 TRACE("       * Offset: %3d\n", format->wine_df->rgodf[i].dwOfs);
416                 TRACE("       * dwType: %08x\n", format->wine_df->rgodf[i].dwType);
417                 TRACE("         "); _dump_EnumObjects_flags(format->wine_df->rgodf[i].dwType); TRACE("\n");
418                 
419                 if (format->wine_df->rgodf[i].dwType & DIDFT_BUTTON)
420                     dt[index].size = sizeof(BYTE);
421                 else
422                     dt[index].size = sizeof(DWORD);
423                 dt[index].offset_in = format->wine_df->rgodf[i].dwOfs;
424                 dt[index].offset_out = asked_format->rgodf[j].dwOfs;
425                 format->offsets[i]   = asked_format->rgodf[j].dwOfs;
426                 dt[index].value = 0;
427                 next = next + dt[index].size;
428                 
429                 if (format->wine_df->rgodf[i].dwOfs != dt[index].offset_out)
430                     same = 0;
431                 
432                 index++;
433                 break;
434             }
435         }
436         
437         if (j == asked_format->dwNumObjs)
438             same = 0;
439     }
440     
441     TRACE("Setting to default value :\n");
442     for (j = 0; j < asked_format->dwNumObjs; j++) {
443         if (done[j] == 0) {
444             TRACE("   - Asked (%d) :\n", j);
445             TRACE("       * GUID: %s ('%s')\n",
446                   debugstr_guid(asked_format->rgodf[j].pguid),
447                   _dump_dinput_GUID(asked_format->rgodf[j].pguid));
448             TRACE("       * Offset: %3d\n", asked_format->rgodf[j].dwOfs);
449             TRACE("       * dwType: %08x\n", asked_format->rgodf[j].dwType);
450             TRACE("         "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
451             
452             if (asked_format->rgodf[j].dwType & DIDFT_BUTTON)
453                 dt[index].size = sizeof(BYTE);
454             else
455                 dt[index].size = sizeof(DWORD);
456             dt[index].offset_in  = -1;
457             dt[index].offset_out = asked_format->rgodf[j].dwOfs;
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 datas 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     TRACE(" cooperative level : ");
683     _dump_cooperativelevel_DI(dwflags);
684
685     if ((dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == 0 ||
686         (dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE) ||
687         (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == 0 ||
688         (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == (DISCL_FOREGROUND | DISCL_BACKGROUND))
689         return DIERR_INVALIDPARAM;
690
691     if (dwflags == (DISCL_NONEXCLUSIVE | DISCL_BACKGROUND))
692         hwnd = GetDesktopWindow();
693
694     if (!hwnd) return E_HANDLE;
695
696     /* For security reasons native does not allow exclusive background level
697        for mouse and keyboard only */
698     if (dwflags & DISCL_EXCLUSIVE && dwflags & DISCL_BACKGROUND &&
699         (IsEqualGUID(&This->guid, &GUID_SysMouse) ||
700          IsEqualGUID(&This->guid, &GUID_SysKeyboard)))
701         return DIERR_UNSUPPORTED;
702
703     /* Store the window which asks for the mouse */
704     EnterCriticalSection(&This->crit);
705     This->win = hwnd;
706     This->dwCoopLevel = dwflags;
707     LeaveCriticalSection(&This->crit);
708
709     return DI_OK;
710 }
711
712 /******************************************************************************
713   *     SetEventNotification : specifies event to be sent on state change
714   */
715 HRESULT WINAPI IDirectInputDevice2AImpl_SetEventNotification(
716         LPDIRECTINPUTDEVICE8A iface, HANDLE event)
717 {
718     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
719
720     TRACE("(%p) %p\n", This, event);
721
722     EnterCriticalSection(&This->crit);
723     This->hEvent = event;
724     LeaveCriticalSection(&This->crit);
725     return DI_OK;
726 }
727
728 ULONG WINAPI IDirectInputDevice2AImpl_Release(LPDIRECTINPUTDEVICE8A iface)
729 {
730     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
731     ULONG ref;
732
733     ref = InterlockedDecrement(&(This->ref));
734     if (ref) return ref;
735
736     IDirectInputDevice_Unacquire(iface);
737     /* Reset the FF state, free all effects, etc */
738     IDirectInputDevice8_SendForceFeedbackCommand(iface, DISFFC_RESET);
739
740     HeapFree(GetProcessHeap(), 0, This->data_queue);
741
742     /* Free data format */
743     HeapFree(GetProcessHeap(), 0, This->data_format.wine_df->rgodf);
744     HeapFree(GetProcessHeap(), 0, This->data_format.wine_df);
745     release_DataFormat(&This->data_format);
746
747     EnterCriticalSection( &This->dinput->crit );
748     list_remove( &This->entry );
749     LeaveCriticalSection( &This->dinput->crit );
750
751     IDirectInput_Release((LPDIRECTINPUTDEVICE8A)This->dinput);
752     This->crit.DebugInfo->Spare[0] = 0;
753     DeleteCriticalSection(&This->crit);
754
755     HeapFree(GetProcessHeap(), 0, This);
756
757     return DI_OK;
758 }
759
760 HRESULT WINAPI IDirectInputDevice2AImpl_QueryInterface(
761         LPDIRECTINPUTDEVICE8A iface,REFIID riid,LPVOID *ppobj
762 )
763 {
764     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
765     
766     TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
767     if (IsEqualGUID(&IID_IUnknown,riid)) {
768         IDirectInputDevice2_AddRef(iface);
769         *ppobj = This;
770         return DI_OK;
771     }
772     if (IsEqualGUID(&IID_IDirectInputDeviceA,riid)) {
773         IDirectInputDevice2_AddRef(iface);
774         *ppobj = This;
775         return DI_OK;
776     }
777     if (IsEqualGUID(&IID_IDirectInputDevice2A,riid)) {
778         IDirectInputDevice2_AddRef(iface);
779         *ppobj = This;
780         return DI_OK;
781     }
782     if (IsEqualGUID(&IID_IDirectInputDevice7A,riid)) {
783         IDirectInputDevice7_AddRef(iface);
784         *ppobj = This;
785         return DI_OK;
786     }
787     if (IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
788         IDirectInputDevice8_AddRef(iface);
789         *ppobj = This;
790         return DI_OK;
791     }
792     TRACE("Unsupported interface !\n");
793     return E_FAIL;
794 }
795
796 HRESULT WINAPI IDirectInputDevice2WImpl_QueryInterface(
797         LPDIRECTINPUTDEVICE8W iface,REFIID riid,LPVOID *ppobj
798 )
799 {
800     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
801     
802     TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
803     if (IsEqualGUID(&IID_IUnknown,riid)) {
804         IDirectInputDevice2_AddRef(iface);
805         *ppobj = This;
806         return DI_OK;
807     }
808     if (IsEqualGUID(&IID_IDirectInputDeviceW,riid)) {
809         IDirectInputDevice2_AddRef(iface);
810         *ppobj = This;
811         return DI_OK;
812     }
813     if (IsEqualGUID(&IID_IDirectInputDevice2W,riid)) {
814         IDirectInputDevice2_AddRef(iface);
815         *ppobj = This;
816         return DI_OK;
817     }
818     if (IsEqualGUID(&IID_IDirectInputDevice7W,riid)) {
819         IDirectInputDevice7_AddRef(iface);
820         *ppobj = This;
821         return DI_OK;
822     }
823     if (IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
824         IDirectInputDevice8_AddRef(iface);
825         *ppobj = This;
826         return DI_OK;
827     }
828     TRACE("Unsupported interface !\n");
829     return E_FAIL;
830 }
831
832 ULONG WINAPI IDirectInputDevice2AImpl_AddRef(
833         LPDIRECTINPUTDEVICE8A iface)
834 {
835     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
836     return InterlockedIncrement(&(This->ref));
837 }
838
839 HRESULT WINAPI IDirectInputDevice2AImpl_EnumObjects(LPDIRECTINPUTDEVICE8A iface,
840         LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback, LPVOID lpvRef, DWORD dwFlags)
841 {
842     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
843     DIDEVICEOBJECTINSTANCEA ddoi;
844     int i;
845
846     TRACE("(%p) %p,%p flags:%08x)\n", iface, lpCallback, lpvRef, dwFlags);
847     TRACE("  - flags = ");
848     _dump_EnumObjects_flags(dwFlags);
849     TRACE("\n");
850
851     /* Only the fields till dwFFMaxForce are relevant */
852     memset(&ddoi, 0, sizeof(ddoi));
853     ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce);
854
855     for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++)
856     {
857         LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(This->data_format.wine_df, i);
858
859         if (dwFlags != DIDFT_ALL && !(dwFlags & DIEFT_GETTYPE(odf->dwType))) continue;
860         if (IDirectInputDevice_GetObjectInfo(iface, &ddoi, odf->dwType, DIPH_BYID) != DI_OK)
861             continue;
862
863         if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) break;
864     }
865
866     return DI_OK;
867 }
868
869 HRESULT WINAPI IDirectInputDevice2WImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface,
870         LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback, LPVOID lpvRef, DWORD dwFlags)
871 {
872     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
873     DIDEVICEOBJECTINSTANCEW ddoi;
874     int i;
875
876     TRACE("(%p) %p,%p flags:%08x)\n", iface, lpCallback, lpvRef, dwFlags);
877     TRACE("  - flags = ");
878     _dump_EnumObjects_flags(dwFlags);
879     TRACE("\n");
880
881     /* Only the fields till dwFFMaxForce are relevant */
882     memset(&ddoi, 0, sizeof(ddoi));
883     ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEW, dwFFMaxForce);
884
885     for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++)
886     {
887         LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(This->data_format.wine_df, i);
888
889         if (dwFlags != DIDFT_ALL && !(dwFlags & DIEFT_GETTYPE(odf->dwType))) continue;
890         if (IDirectInputDevice_GetObjectInfo(iface, &ddoi, odf->dwType, DIPH_BYID) != DI_OK)
891             continue;
892
893         if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) break;
894     }
895
896     return DI_OK;
897 }
898
899 /******************************************************************************
900  *      GetProperty
901  */
902
903 HRESULT WINAPI IDirectInputDevice2AImpl_GetProperty(
904         LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPDIPROPHEADER pdiph)
905 {
906     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
907
908     TRACE("(%p) %s,%p\n", iface, debugstr_guid(rguid), pdiph);
909     _dump_DIPROPHEADER(pdiph);
910
911     if (HIWORD(rguid)) return DI_OK;
912
913     switch (LOWORD(rguid))
914     {
915         case (DWORD) DIPROP_BUFFERSIZE:
916         {
917             LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
918
919             if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
920
921             pd->dwData = This->queue_len;
922             TRACE("buffersize = %d\n", pd->dwData);
923             break;
924         }
925         default:
926             WARN("Unknown property %s\n", debugstr_guid(rguid));
927             break;
928     }
929
930     return DI_OK;
931 }
932
933 /******************************************************************************
934  *      SetProperty
935  */
936
937 HRESULT WINAPI IDirectInputDevice2AImpl_SetProperty(
938         LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPCDIPROPHEADER pdiph)
939 {
940     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
941
942     TRACE("(%p) %s,%p\n", iface, debugstr_guid(rguid), pdiph);
943     _dump_DIPROPHEADER(pdiph);
944
945     if (HIWORD(rguid)) return DI_OK;
946
947     switch (LOWORD(rguid))
948     {
949         case (DWORD) DIPROP_AXISMODE:
950         {
951             LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph;
952
953             if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
954             if (pdiph->dwHow == DIPH_DEVICE && pdiph->dwObj) return DIERR_INVALIDPARAM;
955             if (This->acquired) return DIERR_ACQUIRED;
956             if (pdiph->dwHow != DIPH_DEVICE) return DIERR_UNSUPPORTED;
957             if (!This->data_format.user_df) return DI_OK;
958
959             TRACE("Axis mode: %s\n", pd->dwData == DIPROPAXISMODE_ABS ? "absolute" :
960                                                                         "relative");
961
962             EnterCriticalSection(&This->crit);
963             This->data_format.user_df->dwFlags &= ~DIDFT_AXIS;
964             This->data_format.user_df->dwFlags |= pd->dwData == DIPROPAXISMODE_ABS ?
965                                                   DIDF_ABSAXIS : DIDF_RELAXIS;
966             LeaveCriticalSection(&This->crit);
967             break;
968         }
969         case (DWORD) DIPROP_BUFFERSIZE:
970         {
971             LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph;
972
973             if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
974             if (This->acquired) return DIERR_ACQUIRED;
975
976             TRACE("buffersize = %d\n", pd->dwData);
977
978             EnterCriticalSection(&This->crit);
979             HeapFree(GetProcessHeap(), 0, This->data_queue);
980
981             This->data_queue = !pd->dwData ? NULL : HeapAlloc(GetProcessHeap(), 0,
982                                 pd->dwData * sizeof(DIDEVICEOBJECTDATA));
983             This->queue_head = This->queue_tail = This->overflow = 0;
984             This->queue_len  = pd->dwData;
985
986             LeaveCriticalSection(&This->crit);
987             break;
988         }
989         default:
990             WARN("Unknown property %s\n", debugstr_guid(rguid));
991             return DIERR_UNSUPPORTED;
992     }
993
994     return DI_OK;
995 }
996
997 HRESULT WINAPI IDirectInputDevice2AImpl_GetObjectInfo(
998         LPDIRECTINPUTDEVICE8A iface,
999         LPDIDEVICEOBJECTINSTANCEA pdidoi,
1000         DWORD dwObj,
1001         DWORD dwHow)
1002 {
1003     DIDEVICEOBJECTINSTANCEW didoiW;
1004     HRESULT res;
1005
1006     if (!pdidoi ||
1007         (pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCEA) &&
1008          pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCE_DX3A)))
1009         return DIERR_INVALIDPARAM;
1010
1011     didoiW.dwSize = sizeof(didoiW);
1012     res = IDirectInputDevice2WImpl_GetObjectInfo((LPDIRECTINPUTDEVICE8W)iface, &didoiW, dwObj, dwHow);
1013     if (res == DI_OK)
1014     {
1015         DWORD dwSize = pdidoi->dwSize;
1016
1017         memset(pdidoi, 0, pdidoi->dwSize);
1018         pdidoi->dwSize   = dwSize;
1019         pdidoi->guidType = didoiW.guidType;
1020         pdidoi->dwOfs    = didoiW.dwOfs;
1021         pdidoi->dwType   = didoiW.dwType;
1022         pdidoi->dwFlags  = didoiW.dwFlags;
1023     }
1024
1025     return res;
1026 }
1027
1028 HRESULT WINAPI IDirectInputDevice2WImpl_GetObjectInfo(
1029         LPDIRECTINPUTDEVICE8W iface,
1030         LPDIDEVICEOBJECTINSTANCEW pdidoi,
1031         DWORD dwObj,
1032         DWORD dwHow)
1033 {
1034     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
1035     DWORD dwSize;
1036     LPDIOBJECTDATAFORMAT odf;
1037     int idx = -1;
1038
1039     TRACE("(%p) %d(0x%08x) -> %p\n", This, dwHow, dwObj, pdidoi);
1040
1041     if (!pdidoi ||
1042         (pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCEW) &&
1043          pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCE_DX3W)))
1044         return DIERR_INVALIDPARAM;
1045
1046     switch (dwHow)
1047     {
1048     case DIPH_BYOFFSET:
1049         if (!This->data_format.offsets) break;
1050         for (idx = This->data_format.wine_df->dwNumObjs - 1; idx >= 0; idx--)
1051             if (This->data_format.offsets[idx] == dwObj) break;
1052         break;
1053     case DIPH_BYID:
1054         dwObj &= 0x00ffffff;
1055         for (idx = This->data_format.wine_df->dwNumObjs - 1; idx >= 0; idx--)
1056             if ((dataformat_to_odf(This->data_format.wine_df, idx)->dwType & 0x00ffffff) == dwObj)
1057                 break;
1058         break;
1059
1060     case DIPH_BYUSAGE:
1061         FIXME("dwHow = DIPH_BYUSAGE not implemented\n");
1062         break;
1063     default:
1064         WARN("invalid parameter: dwHow = %08x\n", dwHow);
1065         return DIERR_INVALIDPARAM;
1066     }
1067     if (idx < 0) return DIERR_OBJECTNOTFOUND;
1068
1069     odf = dataformat_to_odf(This->data_format.wine_df, idx);
1070     dwSize = pdidoi->dwSize; /* save due to memset below */
1071     memset(pdidoi, 0, pdidoi->dwSize);
1072     pdidoi->dwSize   = dwSize;
1073     if (odf->pguid) pdidoi->guidType = *odf->pguid;
1074     pdidoi->dwOfs    = This->data_format.offsets ? This->data_format.offsets[idx] : odf->dwOfs;
1075     pdidoi->dwType   = odf->dwType;
1076     pdidoi->dwFlags  = odf->dwFlags;
1077
1078     return DI_OK;
1079 }
1080
1081 HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceData(
1082         LPDIRECTINPUTDEVICE8A iface, DWORD dodsize, LPDIDEVICEOBJECTDATA dod,
1083         LPDWORD entries, DWORD flags)
1084 {
1085     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
1086     HRESULT ret = DI_OK;
1087     int len;
1088
1089     TRACE("(%p) %p -> %p(%d) x%d, 0x%08x\n",
1090           This, dod, entries, entries ? *entries : 0, dodsize, flags);
1091
1092     if (!This->acquired)
1093         return DIERR_NOTACQUIRED;
1094     if (!This->queue_len)
1095         return DIERR_NOTBUFFERED;
1096     if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3))
1097         return DIERR_INVALIDPARAM;
1098
1099     IDirectInputDevice2_Poll(iface);
1100     EnterCriticalSection(&This->crit);
1101
1102     len = This->queue_head - This->queue_tail;
1103     if (len < 0) len += This->queue_len;
1104
1105     if ((*entries != INFINITE) && (len > *entries)) len = *entries;
1106
1107     if (dod)
1108     {
1109         int i;
1110         for (i = 0; i < len; i++)
1111         {
1112             int n = (This->queue_tail + i) % This->queue_len;
1113             memcpy((char *)dod + dodsize * i, This->data_queue + n, dodsize);
1114         }
1115     }
1116     *entries = len;
1117
1118     if (This->overflow)
1119         ret = DI_BUFFEROVERFLOW;
1120
1121     if (!(flags & DIGDD_PEEK))
1122     {
1123         /* Advance reading position */
1124         This->queue_tail = (This->queue_tail + len) % This->queue_len;
1125         This->overflow = FALSE;
1126     }
1127
1128     LeaveCriticalSection(&This->crit);
1129
1130     TRACE("Returning %d events queued\n", *entries);
1131     return ret;
1132 }
1133
1134 HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceInfo(
1135         LPDIRECTINPUTDEVICE8A iface,
1136         LPDIDEVICEINSTANCEA pdidi)
1137 {
1138     FIXME("(this=%p,%p): stub!\n",
1139           iface, pdidi);
1140     
1141     return DI_OK;
1142 }
1143
1144 HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceInfo(
1145         LPDIRECTINPUTDEVICE8W iface,
1146         LPDIDEVICEINSTANCEW pdidi)
1147 {
1148     FIXME("(this=%p,%p): stub!\n",
1149           iface, pdidi);
1150     
1151     return DI_OK;
1152 }
1153
1154 HRESULT WINAPI IDirectInputDevice2AImpl_RunControlPanel(
1155         LPDIRECTINPUTDEVICE8A iface,
1156         HWND hwndOwner,
1157         DWORD dwFlags)
1158 {
1159     FIXME("(this=%p,%p,0x%08x): stub!\n",
1160           iface, hwndOwner, dwFlags);
1161
1162     return DI_OK;
1163 }
1164
1165 HRESULT WINAPI IDirectInputDevice2AImpl_Initialize(
1166         LPDIRECTINPUTDEVICE8A iface,
1167         HINSTANCE hinst,
1168         DWORD dwVersion,
1169         REFGUID rguid)
1170 {
1171     FIXME("(this=%p,%p,%d,%s): stub!\n",
1172           iface, hinst, dwVersion, debugstr_guid(rguid));
1173     return DI_OK;
1174 }
1175
1176 /******************************************************************************
1177  *      IDirectInputDevice2A
1178  */
1179
1180 HRESULT WINAPI IDirectInputDevice2AImpl_CreateEffect(
1181         LPDIRECTINPUTDEVICE8A iface,
1182         REFGUID rguid,
1183         LPCDIEFFECT lpeff,
1184         LPDIRECTINPUTEFFECT *ppdef,
1185         LPUNKNOWN pUnkOuter)
1186 {
1187     FIXME("(this=%p,%s,%p,%p,%p): stub!\n",
1188           iface, debugstr_guid(rguid), lpeff, ppdef, pUnkOuter);
1189     return DI_OK;
1190 }
1191
1192 HRESULT WINAPI IDirectInputDevice2AImpl_EnumEffects(
1193         LPDIRECTINPUTDEVICE8A iface,
1194         LPDIENUMEFFECTSCALLBACKA lpCallback,
1195         LPVOID lpvRef,
1196         DWORD dwFlags)
1197 {
1198     FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1199           iface, lpCallback, lpvRef, dwFlags);
1200     
1201     return DI_OK;
1202 }
1203
1204 HRESULT WINAPI IDirectInputDevice2WImpl_EnumEffects(
1205         LPDIRECTINPUTDEVICE8W iface,
1206         LPDIENUMEFFECTSCALLBACKW lpCallback,
1207         LPVOID lpvRef,
1208         DWORD dwFlags)
1209 {
1210     FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1211           iface, lpCallback, lpvRef, dwFlags);
1212     
1213     return DI_OK;
1214 }
1215
1216 HRESULT WINAPI IDirectInputDevice2AImpl_GetEffectInfo(
1217         LPDIRECTINPUTDEVICE8A iface,
1218         LPDIEFFECTINFOA lpdei,
1219         REFGUID rguid)
1220 {
1221     FIXME("(this=%p,%p,%s): stub!\n",
1222           iface, lpdei, debugstr_guid(rguid));
1223     return DI_OK;
1224 }
1225
1226 HRESULT WINAPI IDirectInputDevice2WImpl_GetEffectInfo(
1227         LPDIRECTINPUTDEVICE8W iface,
1228         LPDIEFFECTINFOW lpdei,
1229         REFGUID rguid)
1230 {
1231     FIXME("(this=%p,%p,%s): stub!\n",
1232           iface, lpdei, debugstr_guid(rguid));
1233     return DI_OK;
1234 }
1235
1236 HRESULT WINAPI IDirectInputDevice2AImpl_GetForceFeedbackState(
1237         LPDIRECTINPUTDEVICE8A iface,
1238         LPDWORD pdwOut)
1239 {
1240     FIXME("(this=%p,%p): stub!\n",
1241           iface, pdwOut);
1242     return DI_OK;
1243 }
1244
1245 HRESULT WINAPI IDirectInputDevice2AImpl_SendForceFeedbackCommand(
1246         LPDIRECTINPUTDEVICE8A iface,
1247         DWORD dwFlags)
1248 {
1249     TRACE("(%p) 0x%08x:\n", iface, dwFlags);
1250     return DI_NOEFFECT;
1251 }
1252
1253 HRESULT WINAPI IDirectInputDevice2AImpl_EnumCreatedEffectObjects(
1254         LPDIRECTINPUTDEVICE8A iface,
1255         LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback,
1256         LPVOID lpvRef,
1257         DWORD dwFlags)
1258 {
1259     FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1260           iface, lpCallback, lpvRef, dwFlags);
1261     return DI_OK;
1262 }
1263
1264 HRESULT WINAPI IDirectInputDevice2AImpl_Escape(
1265         LPDIRECTINPUTDEVICE8A iface,
1266         LPDIEFFESCAPE lpDIEEsc)
1267 {
1268     FIXME("(this=%p,%p): stub!\n",
1269           iface, lpDIEEsc);
1270     return DI_OK;
1271 }
1272
1273 HRESULT WINAPI IDirectInputDevice2AImpl_Poll(
1274         LPDIRECTINPUTDEVICE8A iface)
1275 {
1276     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
1277
1278     if (!This->acquired) return DIERR_NOTACQUIRED;
1279     /* Because wine devices do not need to be polled, just return DI_NOEFFECT */
1280     return DI_NOEFFECT;
1281 }
1282
1283 HRESULT WINAPI IDirectInputDevice2AImpl_SendDeviceData(
1284         LPDIRECTINPUTDEVICE8A iface,
1285         DWORD cbObjectData,
1286         LPCDIDEVICEOBJECTDATA rgdod,
1287         LPDWORD pdwInOut,
1288         DWORD dwFlags)
1289 {
1290     FIXME("(this=%p,0x%08x,%p,%p,0x%08x): stub!\n",
1291           iface, cbObjectData, rgdod, pdwInOut, dwFlags);
1292     
1293     return DI_OK;
1294 }
1295
1296 HRESULT WINAPI IDirectInputDevice7AImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8A iface,
1297                                                           LPCSTR lpszFileName,
1298                                                           LPDIENUMEFFECTSINFILECALLBACK pec,
1299                                                           LPVOID pvRef,
1300                                                           DWORD dwFlags)
1301 {
1302     FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", iface, lpszFileName, pec, pvRef, dwFlags);
1303     
1304     return DI_OK;
1305 }
1306
1307 HRESULT WINAPI IDirectInputDevice7WImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8W iface,
1308                                                           LPCWSTR lpszFileName,
1309                                                           LPDIENUMEFFECTSINFILECALLBACK pec,
1310                                                           LPVOID pvRef,
1311                                                           DWORD dwFlags)
1312 {
1313     FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", iface, debugstr_w(lpszFileName), pec, pvRef, dwFlags);
1314     
1315     return DI_OK;
1316 }
1317
1318 HRESULT WINAPI IDirectInputDevice7AImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8A iface,
1319                                                           LPCSTR lpszFileName,
1320                                                           DWORD dwEntries,
1321                                                           LPDIFILEEFFECT rgDiFileEft,
1322                                                           DWORD dwFlags)
1323 {
1324     FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", iface, lpszFileName, dwEntries, rgDiFileEft, dwFlags);
1325     
1326     return DI_OK;
1327 }
1328
1329 HRESULT WINAPI IDirectInputDevice7WImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8W iface,
1330                                                           LPCWSTR lpszFileName,
1331                                                           DWORD dwEntries,
1332                                                           LPDIFILEEFFECT rgDiFileEft,
1333                                                           DWORD dwFlags)
1334 {
1335     FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", iface, debugstr_w(lpszFileName), dwEntries, rgDiFileEft, dwFlags);
1336     
1337     return DI_OK;
1338 }
1339
1340 HRESULT WINAPI IDirectInputDevice8AImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface,
1341                                                        LPDIACTIONFORMATA lpdiaf,
1342                                                        LPCSTR lpszUserName,
1343                                                        DWORD dwFlags)
1344 {
1345     FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, lpszUserName, dwFlags);
1346     
1347     return DI_OK;
1348 }
1349
1350 HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface,
1351                                                        LPDIACTIONFORMATW lpdiaf,
1352                                                        LPCWSTR lpszUserName,
1353                                                        DWORD dwFlags)
1354 {
1355     FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
1356   
1357     return DI_OK;
1358 }
1359
1360 HRESULT WINAPI IDirectInputDevice8AImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface,
1361                                                      LPDIACTIONFORMATA lpdiaf,
1362                                                      LPCSTR lpszUserName,
1363                                                      DWORD dwFlags)
1364 {
1365     FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, lpszUserName, dwFlags);
1366     
1367     return DI_OK;
1368 }
1369
1370 HRESULT WINAPI IDirectInputDevice8WImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
1371                                                      LPDIACTIONFORMATW lpdiaf,
1372                                                      LPCWSTR lpszUserName,
1373                                                      DWORD dwFlags)
1374 {
1375     FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
1376     
1377     return DI_OK;
1378 }
1379
1380 HRESULT WINAPI IDirectInputDevice8AImpl_GetImageInfo(LPDIRECTINPUTDEVICE8A iface,
1381                                                      LPDIDEVICEIMAGEINFOHEADERA lpdiDevImageInfoHeader)
1382 {
1383     FIXME("(%p)->(%p): stub !\n", iface, lpdiDevImageInfoHeader);
1384     
1385     return DI_OK;
1386 }
1387
1388 HRESULT WINAPI IDirectInputDevice8WImpl_GetImageInfo(LPDIRECTINPUTDEVICE8W iface,
1389                                                      LPDIDEVICEIMAGEINFOHEADERW lpdiDevImageInfoHeader)
1390 {
1391     FIXME("(%p)->(%p): stub !\n", iface, lpdiDevImageInfoHeader);
1392     
1393     return DI_OK;
1394 }