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