msxml3: Implement comment node.
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 "winerror.h"
36 #include "dinput.h"
37 #include "device_private.h"
38
39 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
40
41 /******************************************************************************
42  *      Various debugging tools
43  */
44 void _dump_cooperativelevel_DI(DWORD dwFlags) {
45     if (TRACE_ON(dinput)) {
46         unsigned int   i;
47         static const struct {
48             DWORD       mask;
49             const char  *name;
50         } flags[] = {
51 #define FE(x) { x, #x}
52             FE(DISCL_BACKGROUND),
53             FE(DISCL_EXCLUSIVE),
54             FE(DISCL_FOREGROUND),
55             FE(DISCL_NONEXCLUSIVE)
56 #undef FE
57         };
58         for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++)
59             if (flags[i].mask & dwFlags)
60                 DPRINTF("%s ",flags[i].name);
61         DPRINTF("\n");
62     }
63 }
64
65 void _dump_EnumObjects_flags(DWORD dwFlags) {
66     if (TRACE_ON(dinput)) {
67         unsigned int   i;
68         DWORD type, instance;
69         static const struct {
70             DWORD       mask;
71             const char  *name;
72         } flags[] = {
73 #define FE(x) { x, #x}
74             FE(DIDFT_RELAXIS),
75             FE(DIDFT_ABSAXIS),
76             FE(DIDFT_PSHBUTTON),
77             FE(DIDFT_TGLBUTTON),
78             FE(DIDFT_POV),
79             FE(DIDFT_COLLECTION),
80             FE(DIDFT_NODATA),       
81             FE(DIDFT_FFACTUATOR),
82             FE(DIDFT_FFEFFECTTRIGGER),
83             FE(DIDFT_OUTPUT),
84             FE(DIDFT_VENDORDEFINED),
85             FE(DIDFT_ALIAS),
86             FE(DIDFT_OPTIONAL)
87 #undef FE
88         };
89         type = (dwFlags & 0xFF0000FF);
90         instance = ((dwFlags >> 8) & 0xFFFF);
91         DPRINTF("Type:");
92         if (type == DIDFT_ALL) {
93             DPRINTF(" DIDFT_ALL");
94         } else {
95             for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++) {
96                 if (flags[i].mask & type) {
97                     type &= ~flags[i].mask;
98                     DPRINTF(" %s",flags[i].name);
99                 }
100             }
101             if (type) {
102                 DPRINTF(" (unhandled: %08lx)", type);
103             }
104         }
105         DPRINTF(" / Instance: ");
106         if (instance == ((DIDFT_ANYINSTANCE >> 8) & 0xFFFF)) {
107             DPRINTF("DIDFT_ANYINSTANCE");
108         } else {
109             DPRINTF("%3ld", instance);
110         }
111     }
112 }
113
114 void _dump_DIPROPHEADER(LPCDIPROPHEADER diph) {
115     if (TRACE_ON(dinput)) {
116         DPRINTF("  - dwObj = 0x%08lx\n", diph->dwObj);
117         DPRINTF("  - dwHow = %s\n",
118                 ((diph->dwHow == DIPH_DEVICE) ? "DIPH_DEVICE" :
119                  ((diph->dwHow == DIPH_BYOFFSET) ? "DIPH_BYOFFSET" :
120                   ((diph->dwHow == DIPH_BYID)) ? "DIPH_BYID" : "unknown")));
121     }
122 }
123
124 void _dump_OBJECTINSTANCEA(DIDEVICEOBJECTINSTANCEA *ddoi) {
125     if (TRACE_ON(dinput)) {
126         DPRINTF("    - enumerating : %s ('%s') - %2ld - 0x%08lx - %s\n",
127                 debugstr_guid(&ddoi->guidType), _dump_dinput_GUID(&ddoi->guidType), ddoi->dwOfs, ddoi->dwType, ddoi->tszName);
128     }
129 }
130
131 void _dump_OBJECTINSTANCEW(DIDEVICEOBJECTINSTANCEW *ddoi) {
132     if (TRACE_ON(dinput)) {
133         DPRINTF("    - enumerating : %s ('%s'), - %2ld - 0x%08lx - %s\n",
134                 debugstr_guid(&ddoi->guidType), _dump_dinput_GUID(&ddoi->guidType), ddoi->dwOfs, ddoi->dwType, debugstr_w(ddoi->tszName));
135     }
136 }
137
138 /* This function is a helper to convert a GUID into any possible DInput GUID out there */
139 const char *_dump_dinput_GUID(const GUID *guid) {
140     unsigned int i;
141     static const struct {
142         const GUID *guid;
143         const char *name;
144     } guids[] = {
145 #define FE(x) { &x, #x}
146         FE(GUID_XAxis),
147         FE(GUID_YAxis),
148         FE(GUID_ZAxis),
149         FE(GUID_RxAxis),
150         FE(GUID_RyAxis),
151         FE(GUID_RzAxis),
152         FE(GUID_Slider),
153         FE(GUID_Button),
154         FE(GUID_Key),
155         FE(GUID_POV),
156         FE(GUID_Unknown),
157         FE(GUID_SysMouse),
158         FE(GUID_SysKeyboard),
159         FE(GUID_Joystick),
160         FE(GUID_ConstantForce),
161         FE(GUID_RampForce),
162         FE(GUID_Square),
163         FE(GUID_Sine),
164         FE(GUID_Triangle),
165         FE(GUID_SawtoothUp),
166         FE(GUID_SawtoothDown),
167         FE(GUID_Spring),
168         FE(GUID_Damper),
169         FE(GUID_Inertia),
170         FE(GUID_Friction),
171         FE(GUID_CustomForce)
172 #undef FE
173     };
174     if (guid == NULL)
175         return "null GUID";
176     for (i = 0; i < (sizeof(guids) / sizeof(guids[0])); i++) {
177         if (IsEqualGUID(guids[i].guid, guid)) {
178             return guids[i].name;
179         }
180     }
181     return "Unknown GUID";
182 }
183
184 void _dump_DIDATAFORMAT(const DIDATAFORMAT *df) {
185     unsigned int i;
186
187     TRACE("Dumping DIDATAFORMAT structure:\n");
188     TRACE("  - dwSize: %ld\n", df->dwSize);
189     if (df->dwSize != sizeof(DIDATAFORMAT)) {
190         WARN("Non-standard DIDATAFORMAT structure size (%ld instead of %d).\n", df->dwSize, sizeof(DIDATAFORMAT));
191     }
192     TRACE("  - dwObjsize: %ld\n", df->dwObjSize);
193     if (df->dwObjSize != sizeof(DIOBJECTDATAFORMAT)) {
194         WARN("Non-standard DIOBJECTDATAFORMAT structure size (%ld instead of %d).\n", df->dwObjSize, sizeof(DIOBJECTDATAFORMAT));
195     }
196     TRACE("  - dwFlags: 0x%08lx (", df->dwFlags);
197     switch (df->dwFlags) {
198         case DIDF_ABSAXIS: TRACE("DIDF_ABSAXIS"); break;
199         case DIDF_RELAXIS: TRACE("DIDF_RELAXIS"); break;
200         default: TRACE("unknown"); break;
201     }
202     TRACE(")\n");
203     TRACE("  - dwDataSize: %ld\n", df->dwDataSize);
204     TRACE("  - dwNumObjs: %ld\n", df->dwNumObjs);
205     
206     for (i = 0; i < df->dwNumObjs; i++) {
207         TRACE("  - Object %d:\n", i);
208         TRACE("      * GUID: %s ('%s')\n", debugstr_guid(df->rgodf[i].pguid), _dump_dinput_GUID(df->rgodf[i].pguid));
209         TRACE("      * dwOfs: %ld\n", df->rgodf[i].dwOfs);
210         TRACE("      * dwType: 0x%08lx\n", df->rgodf[i].dwType);
211         TRACE("        "); _dump_EnumObjects_flags(df->rgodf[i].dwType); TRACE("\n");
212         TRACE("      * dwFlags: 0x%08lx\n", df->rgodf[i].dwFlags);
213     }
214 }
215
216 /* Conversion between internal data buffer and external data buffer */
217 void fill_DataFormat(void *out, const void *in, DataFormat *df) {
218     int i;
219     char *in_c = (char *) in;
220     char *out_c = (char *) out;
221     
222     if (df->dt == NULL) {
223         /* This means that the app uses Wine's internal data format */
224         memcpy(out, in, df->internal_format_size);
225     } else {
226         for (i = 0; i < df->size; i++) {
227             if (df->dt[i].offset_in >= 0) {
228                 switch (df->dt[i].size) {
229                     case 1:
230                         TRACE("Copying (c) to %d from %d (value %d)\n",
231                               df->dt[i].offset_out, df->dt[i].offset_in, *((char *) (in_c + df->dt[i].offset_in)));
232                         *((char *) (out_c + df->dt[i].offset_out)) = *((char *) (in_c + df->dt[i].offset_in));
233                         break;
234                     
235                     case 2:
236                         TRACE("Copying (s) to %d from %d (value %d)\n",
237                               df->dt[i].offset_out, df->dt[i].offset_in, *((short *) (in_c + df->dt[i].offset_in)));
238                         *((short *) (out_c + df->dt[i].offset_out)) = *((short *) (in_c + df->dt[i].offset_in));
239                         break;
240                     
241                     case 4:
242                         TRACE("Copying (i) to %d from %d (value %d)\n",
243                               df->dt[i].offset_out, df->dt[i].offset_in, *((int *) (in_c + df->dt[i].offset_in)));
244                         *((int *) (out_c + df->dt[i].offset_out)) = *((int *) (in_c + df->dt[i].offset_in));
245                         break;
246                     
247                     default:
248                         memcpy((out_c + df->dt[i].offset_out), (in_c + df->dt[i].offset_in), df->dt[i].size);
249                         break;
250                 }
251             } else {
252                 switch (df->dt[i].size) {
253                     case 1:
254                         TRACE("Copying (c) to %d default value %d\n",
255                               df->dt[i].offset_out, df->dt[i].value);
256                         *((char *) (out_c + df->dt[i].offset_out)) = (char) df->dt[i].value;
257                         break;
258                         
259                     case 2:
260                         TRACE("Copying (s) to %d default value %d\n",
261                               df->dt[i].offset_out, df->dt[i].value);
262                         *((short *) (out_c + df->dt[i].offset_out)) = (short) df->dt[i].value;
263                         break;
264                         
265                     case 4:
266                         TRACE("Copying (i) to %d default value %d\n",
267                               df->dt[i].offset_out, df->dt[i].value);
268                         *((int *) (out_c + df->dt[i].offset_out)) = (int) df->dt[i].value;
269                         break;
270                         
271                     default:
272                         memset((out_c + df->dt[i].offset_out), df->dt[i].size, 0);
273                         break;
274                 }
275             }
276         }
277     }
278 }
279
280 void release_DataFormat(DataFormat * format)
281 {
282     TRACE("Deleting DataTransform :\n");
283
284     HeapFree(GetProcessHeap(), 0, format->dt);
285 }
286
287 DataFormat *create_DataFormat(const DIDATAFORMAT *wine_format, LPCDIDATAFORMAT asked_format, int *offset) {
288     DataFormat *ret;
289     DataTransform *dt;
290     unsigned int i, j;
291     int same = 1;
292     int *done;
293     int index = 0;
294     DWORD next = 0;
295     
296     ret = HeapAlloc(GetProcessHeap(), 0, sizeof(DataFormat));
297     
298     done = HeapAlloc(GetProcessHeap(), 0, sizeof(int) * asked_format->dwNumObjs);
299     memset(done, 0, sizeof(int) * asked_format->dwNumObjs);
300     
301     dt = HeapAlloc(GetProcessHeap(), 0, asked_format->dwNumObjs * sizeof(DataTransform));
302     
303     TRACE("Creating DataTransform :\n");
304     
305     for (i = 0; i < wine_format->dwNumObjs; i++) {
306         offset[i] = -1;
307         
308         for (j = 0; j < asked_format->dwNumObjs; j++) {
309             if (done[j] == 1)
310                 continue;
311             
312             if (/* Check if the application either requests any GUID and if not, it if matches
313                  * the GUID of the Wine object.
314                  */
315                 ((asked_format->rgodf[j].pguid == NULL) ||
316                  (wine_format->rgodf[i].pguid == NULL) ||
317                  (IsEqualGUID(wine_format->rgodf[i].pguid, asked_format->rgodf[j].pguid)))
318                 &&
319                 (/* Then check if it accepts any instance id, and if not, if it matches Wine's
320                   * instance id.
321                   */
322                  (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == 0xFFFF) ||
323                  (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == 0x00FF) || /* This is mentionned in no DX docs, but it works fine - tested on WinXP */
324                  (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == DIDFT_GETINSTANCE(wine_format->rgodf[i].dwType)))
325                 &&
326                 ( /* Then if the asked type matches the one Wine provides */
327                  wine_format->rgodf[i].dwType & asked_format->rgodf[j].dwType)) {
328                 
329                 done[j] = 1;
330                 
331                 TRACE("Matching :\n");
332                 TRACE("   - Asked (%d) :\n", j);
333                 TRACE("       * GUID: %s ('%s')\n",
334                       debugstr_guid(asked_format->rgodf[j].pguid),
335                       _dump_dinput_GUID(asked_format->rgodf[j].pguid));
336                 TRACE("       * Offset: %3ld\n", asked_format->rgodf[j].dwOfs);
337                 TRACE("       * dwType: %08lx\n", asked_format->rgodf[j].dwType);
338                 TRACE("         "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
339                 
340                 TRACE("   - Wine  (%d) :\n", i);
341                 TRACE("       * GUID: %s ('%s')\n",
342                       debugstr_guid(wine_format->rgodf[i].pguid),
343                       _dump_dinput_GUID(wine_format->rgodf[i].pguid));
344                 TRACE("       * Offset: %3ld\n", wine_format->rgodf[i].dwOfs);
345                 TRACE("       * dwType: %08lx\n", wine_format->rgodf[i].dwType);
346                 TRACE("         "); _dump_EnumObjects_flags(wine_format->rgodf[i].dwType); TRACE("\n");
347                 
348                 if (wine_format->rgodf[i].dwType & DIDFT_BUTTON)
349                     dt[index].size = sizeof(BYTE);
350                 else
351                     dt[index].size = sizeof(DWORD);
352                 dt[index].offset_in = wine_format->rgodf[i].dwOfs;
353                 if (asked_format->rgodf[j].dwOfs < next) {
354                     WARN("bad format: dwOfs=%ld, changing to %ld\n", asked_format->rgodf[j].dwOfs, next);
355                     dt[index].offset_out = next;
356                     offset[i] = next;
357                 } else {
358                     dt[index].offset_out = asked_format->rgodf[j].dwOfs;
359                     offset[i] = asked_format->rgodf[j].dwOfs;
360                 }
361                 dt[index].value = 0;
362                 next = next + dt[index].size;
363                 
364                 if (wine_format->rgodf[i].dwOfs != dt[index].offset_out)
365                     same = 0;
366                 
367                 index++;
368                 break;
369             }
370         }
371         
372         if (j == asked_format->dwNumObjs)
373             same = 0;
374     }
375     
376     TRACE("Setting to default value :\n");
377     for (j = 0; j < asked_format->dwNumObjs; j++) {
378         if (done[j] == 0) {
379             TRACE("   - Asked (%d) :\n", j);
380             TRACE("       * GUID: %s ('%s')\n",
381                   debugstr_guid(asked_format->rgodf[j].pguid),
382                   _dump_dinput_GUID(asked_format->rgodf[j].pguid));
383             TRACE("       * Offset: %3ld\n", asked_format->rgodf[j].dwOfs);
384             TRACE("       * dwType: %08lx\n", asked_format->rgodf[j].dwType);
385             TRACE("         "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
386             
387             if (asked_format->rgodf[j].dwType & DIDFT_BUTTON)
388                 dt[index].size = sizeof(BYTE);
389             else
390                 dt[index].size = sizeof(DWORD);
391             dt[index].offset_in  = -1;
392             dt[index].offset_out = asked_format->rgodf[j].dwOfs;
393             dt[index].value = 0;
394             index++;
395             
396             same = 0;
397         }
398     }
399     
400     ret->internal_format_size = wine_format->dwDataSize;
401     ret->size = index;
402     if (same) {
403         ret->dt = NULL;
404         HeapFree(GetProcessHeap(), 0, dt);
405     } else {
406         ret->dt = dt;
407     }
408     
409     HeapFree(GetProcessHeap(), 0, done);
410     
411     return ret;
412 }
413
414 BOOL DIEnumDevicesCallbackAtoW(LPCDIDEVICEOBJECTINSTANCEA lpddi, LPVOID lpvRef) {
415     DIDEVICEOBJECTINSTANCEW ddtmp;
416     device_enumobjects_AtoWcb_data* data;
417
418     data = (device_enumobjects_AtoWcb_data*) lpvRef;
419     
420     memset(&ddtmp, 0, sizeof(ddtmp));
421     
422     ddtmp.dwSize = sizeof(DIDEVICEINSTANCEW);
423     ddtmp.guidType     = lpddi->guidType;
424     ddtmp.dwOfs        = lpddi->dwOfs;
425     ddtmp.dwType       = lpddi->dwType;
426     ddtmp.dwFlags      = lpddi->dwFlags;
427     MultiByteToWideChar(CP_ACP, 0, lpddi->tszName, -1, ddtmp.tszName, MAX_PATH);
428     
429     if (lpddi->dwSize == sizeof(DIDEVICEINSTANCEA)) {
430         /**
431          * if dwSize < sizeof(DIDEVICEINSTANCEA of DInput version >= 5)
432          *  force feedback and other newer datas aren't available
433          */
434         ddtmp.dwFFMaxForce        = lpddi->dwFFMaxForce;
435         ddtmp.dwFFForceResolution = lpddi->dwFFForceResolution;
436         ddtmp.wCollectionNumber   = lpddi->wCollectionNumber;
437         ddtmp.wDesignatorIndex    = lpddi->wDesignatorIndex;
438         ddtmp.wUsagePage          = lpddi->wUsagePage;
439         ddtmp.wUsage              = lpddi->wUsage;
440         ddtmp.dwDimension         = lpddi->dwDimension;
441         ddtmp.wExponent           = lpddi->wExponent;
442         ddtmp.wReserved           = lpddi->wReserved;
443     }
444     return data->lpCallBack(&ddtmp, data->lpvRef);
445 }
446
447 /******************************************************************************
448  *      IDirectInputDeviceA
449  */
450
451 HRESULT WINAPI IDirectInputDevice2AImpl_SetDataFormat(
452         LPDIRECTINPUTDEVICE8A iface,LPCDIDATAFORMAT df
453 ) {
454     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
455     
456     TRACE("(this=%p,%p)\n",This,df);
457     
458     _dump_DIDATAFORMAT(df);
459     
460     return DI_OK;
461 }
462
463 HRESULT WINAPI IDirectInputDevice2AImpl_SetCooperativeLevel(
464         LPDIRECTINPUTDEVICE8A iface,HWND hwnd,DWORD dwflags
465 ) {
466     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
467     TRACE("(this=%p,%p,0x%08lx)\n",This,hwnd,dwflags);
468     if (TRACE_ON(dinput)) {
469         TRACE(" cooperative level : ");
470         _dump_cooperativelevel_DI(dwflags);
471     }
472     return DI_OK;
473 }
474
475 HRESULT WINAPI IDirectInputDevice2AImpl_SetEventNotification(
476         LPDIRECTINPUTDEVICE8A iface,HANDLE hnd
477 ) {
478     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
479     FIXME("(this=%p,%p): stub\n",This,hnd);
480     return DI_OK;
481 }
482
483 ULONG WINAPI IDirectInputDevice2AImpl_Release(LPDIRECTINPUTDEVICE8A iface)
484 {
485     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
486     ULONG ref;
487     ref = InterlockedDecrement(&(This->ref));
488     if (ref == 0)
489         HeapFree(GetProcessHeap(),0,This);
490     return ref;
491 }
492
493 HRESULT WINAPI IDirectInputDevice2AImpl_QueryInterface(
494         LPDIRECTINPUTDEVICE8A iface,REFIID riid,LPVOID *ppobj
495 )
496 {
497     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
498     
499     TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
500     if (IsEqualGUID(&IID_IUnknown,riid)) {
501         IDirectInputDevice2_AddRef(iface);
502         *ppobj = This;
503         return DI_OK;
504     }
505     if (IsEqualGUID(&IID_IDirectInputDeviceA,riid)) {
506         IDirectInputDevice2_AddRef(iface);
507         *ppobj = This;
508         return DI_OK;
509     }
510     if (IsEqualGUID(&IID_IDirectInputDevice2A,riid)) {
511         IDirectInputDevice2_AddRef(iface);
512         *ppobj = This;
513         return DI_OK;
514     }
515     if (IsEqualGUID(&IID_IDirectInputDevice7A,riid)) {
516         IDirectInputDevice7_AddRef(iface);
517         *ppobj = This;
518         return DI_OK;
519     }
520     if (IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
521         IDirectInputDevice8_AddRef(iface);
522         *ppobj = This;
523         return DI_OK;
524     }
525     TRACE("Unsupported interface !\n");
526     return E_FAIL;
527 }
528
529 HRESULT WINAPI IDirectInputDevice2WImpl_QueryInterface(
530         LPDIRECTINPUTDEVICE8W iface,REFIID riid,LPVOID *ppobj
531 )
532 {
533     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
534     
535     TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
536     if (IsEqualGUID(&IID_IUnknown,riid)) {
537         IDirectInputDevice2_AddRef(iface);
538         *ppobj = This;
539         return DI_OK;
540     }
541     if (IsEqualGUID(&IID_IDirectInputDeviceW,riid)) {
542         IDirectInputDevice2_AddRef(iface);
543         *ppobj = This;
544         return DI_OK;
545     }
546     if (IsEqualGUID(&IID_IDirectInputDevice2W,riid)) {
547         IDirectInputDevice2_AddRef(iface);
548         *ppobj = This;
549         return DI_OK;
550     }
551     if (IsEqualGUID(&IID_IDirectInputDevice7W,riid)) {
552         IDirectInputDevice7_AddRef(iface);
553         *ppobj = This;
554         return DI_OK;
555     }
556     if (IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
557         IDirectInputDevice8_AddRef(iface);
558         *ppobj = This;
559         return DI_OK;
560     }
561     TRACE("Unsupported interface !\n");
562     return E_FAIL;
563 }
564
565 ULONG WINAPI IDirectInputDevice2AImpl_AddRef(
566         LPDIRECTINPUTDEVICE8A iface)
567 {
568     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
569     return InterlockedIncrement(&(This->ref));
570 }
571
572 HRESULT WINAPI IDirectInputDevice2AImpl_EnumObjects(
573         LPDIRECTINPUTDEVICE8A iface,
574         LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback,
575         LPVOID lpvRef,
576         DWORD dwFlags)
577 {
578     FIXME("(this=%p,%p,%p,%08lx): stub!\n", iface, lpCallback, lpvRef, dwFlags);
579     if (TRACE_ON(dinput)) {
580         DPRINTF("  - flags = ");
581         _dump_EnumObjects_flags(dwFlags);
582         DPRINTF("\n");
583     }
584     
585     return DI_OK;
586 }
587
588 HRESULT WINAPI IDirectInputDevice2WImpl_EnumObjects(
589         LPDIRECTINPUTDEVICE8W iface,
590         LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback,
591         LPVOID lpvRef,
592         DWORD dwFlags)
593 {
594     FIXME("(this=%p,%p,%p,%08lx): stub!\n", iface, lpCallback, lpvRef, dwFlags);
595     if (TRACE_ON(dinput)) {
596         DPRINTF("  - flags = ");
597         _dump_EnumObjects_flags(dwFlags);
598         DPRINTF("\n");
599     }
600     
601     return DI_OK;
602 }
603
604 HRESULT WINAPI IDirectInputDevice2AImpl_GetProperty(
605         LPDIRECTINPUTDEVICE8A iface,
606         REFGUID rguid,
607         LPDIPROPHEADER pdiph)
608 {
609     FIXME("(this=%p,%s,%p): stub!\n",
610           iface, debugstr_guid(rguid), pdiph);
611     
612     if (TRACE_ON(dinput))
613         _dump_DIPROPHEADER(pdiph);
614     
615     return DI_OK;
616 }
617
618 HRESULT WINAPI IDirectInputDevice2AImpl_GetObjectInfo(
619         LPDIRECTINPUTDEVICE8A iface,
620         LPDIDEVICEOBJECTINSTANCEA pdidoi,
621         DWORD dwObj,
622         DWORD dwHow)
623 {
624     FIXME("(this=%p,%p,%ld,0x%08lx): stub!\n",
625           iface, pdidoi, dwObj, dwHow);
626     
627     return DI_OK;
628 }
629
630 HRESULT WINAPI IDirectInputDevice2WImpl_GetObjectInfo(
631         LPDIRECTINPUTDEVICE8W iface,
632         LPDIDEVICEOBJECTINSTANCEW pdidoi,
633         DWORD dwObj,
634         DWORD dwHow)
635 {
636     FIXME("(this=%p,%p,%ld,0x%08lx): stub!\n",
637           iface, pdidoi, dwObj, dwHow);
638     
639     return DI_OK;
640 }
641
642 HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceInfo(
643         LPDIRECTINPUTDEVICE8A iface,
644         LPDIDEVICEINSTANCEA pdidi)
645 {
646     FIXME("(this=%p,%p): stub!\n",
647           iface, pdidi);
648     
649     return DI_OK;
650 }
651
652 HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceInfo(
653         LPDIRECTINPUTDEVICE8W iface,
654         LPDIDEVICEINSTANCEW pdidi)
655 {
656     FIXME("(this=%p,%p): stub!\n",
657           iface, pdidi);
658     
659     return DI_OK;
660 }
661
662 HRESULT WINAPI IDirectInputDevice2AImpl_RunControlPanel(
663         LPDIRECTINPUTDEVICE8A iface,
664         HWND hwndOwner,
665         DWORD dwFlags)
666 {
667     FIXME("(this=%p,%p,0x%08lx): stub!\n",
668           iface, hwndOwner, dwFlags);
669
670     return DI_OK;
671 }
672
673 HRESULT WINAPI IDirectInputDevice2AImpl_Initialize(
674         LPDIRECTINPUTDEVICE8A iface,
675         HINSTANCE hinst,
676         DWORD dwVersion,
677         REFGUID rguid)
678 {
679     FIXME("(this=%p,%p,%ld,%s): stub!\n",
680           iface, hinst, dwVersion, debugstr_guid(rguid));
681     return DI_OK;
682 }
683
684 /******************************************************************************
685  *      IDirectInputDevice2A
686  */
687
688 HRESULT WINAPI IDirectInputDevice2AImpl_CreateEffect(
689         LPDIRECTINPUTDEVICE8A iface,
690         REFGUID rguid,
691         LPCDIEFFECT lpeff,
692         LPDIRECTINPUTEFFECT *ppdef,
693         LPUNKNOWN pUnkOuter)
694 {
695     FIXME("(this=%p,%s,%p,%p,%p): stub!\n",
696           iface, debugstr_guid(rguid), lpeff, ppdef, pUnkOuter);
697     return DI_OK;
698 }
699
700 HRESULT WINAPI IDirectInputDevice2AImpl_EnumEffects(
701         LPDIRECTINPUTDEVICE8A iface,
702         LPDIENUMEFFECTSCALLBACKA lpCallback,
703         LPVOID lpvRef,
704         DWORD dwFlags)
705 {
706     FIXME("(this=%p,%p,%p,0x%08lx): stub!\n",
707           iface, lpCallback, lpvRef, dwFlags);
708     
709     return DI_OK;
710 }
711
712 HRESULT WINAPI IDirectInputDevice2WImpl_EnumEffects(
713         LPDIRECTINPUTDEVICE8W iface,
714         LPDIENUMEFFECTSCALLBACKW lpCallback,
715         LPVOID lpvRef,
716         DWORD dwFlags)
717 {
718     FIXME("(this=%p,%p,%p,0x%08lx): stub!\n",
719           iface, lpCallback, lpvRef, dwFlags);
720     
721     return DI_OK;
722 }
723
724 HRESULT WINAPI IDirectInputDevice2AImpl_GetEffectInfo(
725         LPDIRECTINPUTDEVICE8A iface,
726         LPDIEFFECTINFOA lpdei,
727         REFGUID rguid)
728 {
729     FIXME("(this=%p,%p,%s): stub!\n",
730           iface, lpdei, debugstr_guid(rguid));
731     return DI_OK;
732 }
733
734 HRESULT WINAPI IDirectInputDevice2WImpl_GetEffectInfo(
735         LPDIRECTINPUTDEVICE8W iface,
736         LPDIEFFECTINFOW lpdei,
737         REFGUID rguid)
738 {
739     FIXME("(this=%p,%p,%s): stub!\n",
740           iface, lpdei, debugstr_guid(rguid));
741     return DI_OK;
742 }
743
744 HRESULT WINAPI IDirectInputDevice2AImpl_GetForceFeedbackState(
745         LPDIRECTINPUTDEVICE8A iface,
746         LPDWORD pdwOut)
747 {
748     FIXME("(this=%p,%p): stub!\n",
749           iface, pdwOut);
750     return DI_OK;
751 }
752
753 HRESULT WINAPI IDirectInputDevice2AImpl_SendForceFeedbackCommand(
754         LPDIRECTINPUTDEVICE8A iface,
755         DWORD dwFlags)
756 {
757     FIXME("(this=%p,0x%08lx): stub!\n",
758           iface, dwFlags);
759     return DI_OK;
760 }
761
762 HRESULT WINAPI IDirectInputDevice2AImpl_EnumCreatedEffectObjects(
763         LPDIRECTINPUTDEVICE8A iface,
764         LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback,
765         LPVOID lpvRef,
766         DWORD dwFlags)
767 {
768     FIXME("(this=%p,%p,%p,0x%08lx): stub!\n",
769           iface, lpCallback, lpvRef, dwFlags);
770     return DI_OK;
771 }
772
773 HRESULT WINAPI IDirectInputDevice2AImpl_Escape(
774         LPDIRECTINPUTDEVICE8A iface,
775         LPDIEFFESCAPE lpDIEEsc)
776 {
777     FIXME("(this=%p,%p): stub!\n",
778           iface, lpDIEEsc);
779     return DI_OK;
780 }
781
782 HRESULT WINAPI IDirectInputDevice2AImpl_Poll(
783         LPDIRECTINPUTDEVICE8A iface)
784 {
785     /* Because wine devices do not need to be polled, just return DI_NOEFFECT */
786     return DI_NOEFFECT;
787 }
788
789 HRESULT WINAPI IDirectInputDevice2AImpl_SendDeviceData(
790         LPDIRECTINPUTDEVICE8A iface,
791         DWORD cbObjectData,
792         LPCDIDEVICEOBJECTDATA rgdod,
793         LPDWORD pdwInOut,
794         DWORD dwFlags)
795 {
796     FIXME("(this=%p,0x%08lx,%p,%p,0x%08lx): stub!\n",
797           iface, cbObjectData, rgdod, pdwInOut, dwFlags);
798     
799     return DI_OK;
800 }
801
802 HRESULT WINAPI IDirectInputDevice7AImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8A iface,
803                                                           LPCSTR lpszFileName,
804                                                           LPDIENUMEFFECTSINFILECALLBACK pec,
805                                                           LPVOID pvRef,
806                                                           DWORD dwFlags)
807 {
808     FIXME("(%p)->(%s,%p,%p,%08lx): stub !\n", iface, lpszFileName, pec, pvRef, dwFlags);
809     
810     return DI_OK;
811 }
812
813 HRESULT WINAPI IDirectInputDevice7WImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8W iface,
814                                                           LPCWSTR lpszFileName,
815                                                           LPDIENUMEFFECTSINFILECALLBACK pec,
816                                                           LPVOID pvRef,
817                                                           DWORD dwFlags)
818 {
819     FIXME("(%p)->(%s,%p,%p,%08lx): stub !\n", iface, debugstr_w(lpszFileName), pec, pvRef, dwFlags);
820     
821     return DI_OK;
822 }
823
824 HRESULT WINAPI IDirectInputDevice7AImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8A iface,
825                                                           LPCSTR lpszFileName,
826                                                           DWORD dwEntries,
827                                                           LPDIFILEEFFECT rgDiFileEft,
828                                                           DWORD dwFlags)
829 {
830     FIXME("(%p)->(%s,%08lx,%p,%08lx): stub !\n", iface, lpszFileName, dwEntries, rgDiFileEft, dwFlags);
831     
832     return DI_OK;
833 }
834
835 HRESULT WINAPI IDirectInputDevice7WImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8W iface,
836                                                           LPCWSTR lpszFileName,
837                                                           DWORD dwEntries,
838                                                           LPDIFILEEFFECT rgDiFileEft,
839                                                           DWORD dwFlags)
840 {
841     FIXME("(%p)->(%s,%08lx,%p,%08lx): stub !\n", iface, debugstr_w(lpszFileName), dwEntries, rgDiFileEft, dwFlags);
842     
843     return DI_OK;
844 }
845
846 HRESULT WINAPI IDirectInputDevice8AImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface,
847                                                        LPDIACTIONFORMATA lpdiaf,
848                                                        LPCSTR lpszUserName,
849                                                        DWORD dwFlags)
850 {
851     FIXME("(%p)->(%p,%s,%08lx): stub !\n", iface, lpdiaf, lpszUserName, dwFlags);
852     
853     return DI_OK;
854 }
855
856 HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface,
857                                                        LPDIACTIONFORMATW lpdiaf,
858                                                        LPCWSTR lpszUserName,
859                                                        DWORD dwFlags)
860 {
861     FIXME("(%p)->(%p,%s,%08lx): stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
862   
863     return DI_OK;
864 }
865
866 HRESULT WINAPI IDirectInputDevice8AImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface,
867                                                      LPDIACTIONFORMATA lpdiaf,
868                                                      LPCSTR lpszUserName,
869                                                      DWORD dwFlags)
870 {
871     FIXME("(%p)->(%p,%s,%08lx): stub !\n", iface, lpdiaf, lpszUserName, dwFlags);
872     
873     return DI_OK;
874 }
875
876 HRESULT WINAPI IDirectInputDevice8WImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
877                                                      LPDIACTIONFORMATW lpdiaf,
878                                                      LPCWSTR lpszUserName,
879                                                      DWORD dwFlags)
880 {
881     FIXME("(%p)->(%p,%s,%08lx): stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
882     
883     return DI_OK;
884 }
885
886 HRESULT WINAPI IDirectInputDevice8AImpl_GetImageInfo(LPDIRECTINPUTDEVICE8A iface,
887                                                      LPDIDEVICEIMAGEINFOHEADERA lpdiDevImageInfoHeader)
888 {
889     FIXME("(%p)->(%p): stub !\n", iface, lpdiDevImageInfoHeader);
890     
891     return DI_OK;
892 }
893
894 HRESULT WINAPI IDirectInputDevice8WImpl_GetImageInfo(LPDIRECTINPUTDEVICE8W iface,
895                                                      LPDIDEVICEIMAGEINFOHEADERW lpdiDevImageInfoHeader)
896 {
897     FIXME("(%p)->(%p): stub !\n", iface, lpdiDevImageInfoHeader);
898     
899     return DI_OK;
900 }