wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / dinput / device.c
blob0b1a6d9b96d4bc5b59c26a59ec795816155f13e7
1 /* DirectInput Device
3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998,1999 Lionel Ulmer
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.
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.
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
22 /* This file contains all the Device specific functions that can be used as stubs
23 by real device implementations.
25 It also contains all the helper functions.
27 #include "config.h"
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"
42 #define WM_WINE_NOTIFY_ACTIVITY WM_USER
44 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
46 static inline IDirectInputDeviceImpl *impl_from_IDirectInputDevice8A(IDirectInputDevice8A *iface)
48 return CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8A_iface);
50 static inline IDirectInputDeviceImpl *impl_from_IDirectInputDevice8W(IDirectInputDevice8W *iface)
52 return CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8W_iface);
55 static inline IDirectInputDevice8A *IDirectInputDevice8A_from_impl(IDirectInputDeviceImpl *This)
57 return &This->IDirectInputDevice8A_iface;
59 static inline IDirectInputDevice8W *IDirectInputDevice8W_from_impl(IDirectInputDeviceImpl *This)
61 return &This->IDirectInputDevice8W_iface;
64 /******************************************************************************
65 * Various debugging tools
67 static void _dump_cooperativelevel_DI(DWORD dwFlags) {
68 if (TRACE_ON(dinput)) {
69 unsigned int i;
70 static const struct {
71 DWORD mask;
72 const char *name;
73 } flags[] = {
74 #define FE(x) { x, #x}
75 FE(DISCL_BACKGROUND),
76 FE(DISCL_EXCLUSIVE),
77 FE(DISCL_FOREGROUND),
78 FE(DISCL_NONEXCLUSIVE),
79 FE(DISCL_NOWINKEY)
80 #undef FE
82 TRACE(" cooperative level : ");
83 for (i = 0; i < ARRAY_SIZE(flags); i++)
84 if (flags[i].mask & dwFlags)
85 TRACE("%s ",flags[i].name);
86 TRACE("\n");
90 static void _dump_ObjectDataFormat_flags(DWORD dwFlags) {
91 unsigned int i;
92 static const struct {
93 DWORD mask;
94 const char *name;
95 } flags[] = {
96 #define FE(x) { x, #x}
97 FE(DIDOI_FFACTUATOR),
98 FE(DIDOI_FFEFFECTTRIGGER),
99 FE(DIDOI_POLLED),
100 FE(DIDOI_GUIDISUSAGE)
101 #undef FE
104 if (!dwFlags) return;
106 TRACE("Flags:");
108 /* First the flags */
109 for (i = 0; i < ARRAY_SIZE(flags); i++) {
110 if (flags[i].mask & dwFlags)
111 TRACE(" %s",flags[i].name);
114 /* Now specific values */
115 #define FE(x) case x: TRACE(" "#x); break
116 switch (dwFlags & DIDOI_ASPECTMASK) {
117 FE(DIDOI_ASPECTACCEL);
118 FE(DIDOI_ASPECTFORCE);
119 FE(DIDOI_ASPECTPOSITION);
120 FE(DIDOI_ASPECTVELOCITY);
122 #undef FE
126 static void _dump_EnumObjects_flags(DWORD dwFlags) {
127 if (TRACE_ON(dinput)) {
128 unsigned int i;
129 DWORD type, instance;
130 static const struct {
131 DWORD mask;
132 const char *name;
133 } flags[] = {
134 #define FE(x) { x, #x}
135 FE(DIDFT_RELAXIS),
136 FE(DIDFT_ABSAXIS),
137 FE(DIDFT_PSHBUTTON),
138 FE(DIDFT_TGLBUTTON),
139 FE(DIDFT_POV),
140 FE(DIDFT_COLLECTION),
141 FE(DIDFT_NODATA),
142 FE(DIDFT_FFACTUATOR),
143 FE(DIDFT_FFEFFECTTRIGGER),
144 FE(DIDFT_OUTPUT),
145 FE(DIDFT_VENDORDEFINED),
146 FE(DIDFT_ALIAS),
147 FE(DIDFT_OPTIONAL)
148 #undef FE
150 type = (dwFlags & 0xFF0000FF);
151 instance = ((dwFlags >> 8) & 0xFFFF);
152 TRACE("Type:");
153 if (type == DIDFT_ALL) {
154 TRACE(" DIDFT_ALL");
155 } else {
156 for (i = 0; i < ARRAY_SIZE(flags); i++) {
157 if (flags[i].mask & type) {
158 type &= ~flags[i].mask;
159 TRACE(" %s",flags[i].name);
162 if (type) {
163 TRACE(" (unhandled: %08x)", type);
166 TRACE(" / Instance: ");
167 if (instance == ((DIDFT_ANYINSTANCE >> 8) & 0xFFFF)) {
168 TRACE("DIDFT_ANYINSTANCE");
169 } else {
170 TRACE("%3d", instance);
175 void _dump_DIPROPHEADER(LPCDIPROPHEADER diph) {
176 if (TRACE_ON(dinput)) {
177 TRACE(" - dwObj = 0x%08x\n", diph->dwObj);
178 TRACE(" - dwHow = %s\n",
179 ((diph->dwHow == DIPH_DEVICE) ? "DIPH_DEVICE" :
180 ((diph->dwHow == DIPH_BYOFFSET) ? "DIPH_BYOFFSET" :
181 ((diph->dwHow == DIPH_BYID)) ? "DIPH_BYID" : "unknown")));
185 void _dump_OBJECTINSTANCEA(const DIDEVICEOBJECTINSTANCEA *ddoi) {
186 TRACE(" - enumerating : %s ('%s') - %2d - 0x%08x - %s - 0x%x\n",
187 debugstr_guid(&ddoi->guidType), _dump_dinput_GUID(&ddoi->guidType), ddoi->dwOfs, ddoi->dwType, ddoi->tszName, ddoi->dwFlags);
190 void _dump_OBJECTINSTANCEW(const DIDEVICEOBJECTINSTANCEW *ddoi) {
191 TRACE(" - enumerating : %s ('%s'), - %2d - 0x%08x - %s - 0x%x\n",
192 debugstr_guid(&ddoi->guidType), _dump_dinput_GUID(&ddoi->guidType), ddoi->dwOfs, ddoi->dwType, debugstr_w(ddoi->tszName), ddoi->dwFlags);
195 /* This function is a helper to convert a GUID into any possible DInput GUID out there */
196 const char *_dump_dinput_GUID(const GUID *guid) {
197 unsigned int i;
198 static const struct {
199 const GUID *guid;
200 const char *name;
201 } guids[] = {
202 #define FE(x) { &x, #x}
203 FE(GUID_XAxis),
204 FE(GUID_YAxis),
205 FE(GUID_ZAxis),
206 FE(GUID_RxAxis),
207 FE(GUID_RyAxis),
208 FE(GUID_RzAxis),
209 FE(GUID_Slider),
210 FE(GUID_Button),
211 FE(GUID_Key),
212 FE(GUID_POV),
213 FE(GUID_Unknown),
214 FE(GUID_SysMouse),
215 FE(GUID_SysKeyboard),
216 FE(GUID_Joystick),
217 FE(GUID_ConstantForce),
218 FE(GUID_RampForce),
219 FE(GUID_Square),
220 FE(GUID_Sine),
221 FE(GUID_Triangle),
222 FE(GUID_SawtoothUp),
223 FE(GUID_SawtoothDown),
224 FE(GUID_Spring),
225 FE(GUID_Damper),
226 FE(GUID_Inertia),
227 FE(GUID_Friction),
228 FE(GUID_CustomForce)
229 #undef FE
231 if (guid == NULL)
232 return "null GUID";
233 for (i = 0; i < ARRAY_SIZE(guids); i++) {
234 if (IsEqualGUID(guids[i].guid, guid)) {
235 return guids[i].name;
238 return debugstr_guid(guid);
241 void _dump_DIDATAFORMAT(const DIDATAFORMAT *df) {
242 unsigned int i;
244 TRACE("Dumping DIDATAFORMAT structure:\n");
245 TRACE(" - dwSize: %d\n", df->dwSize);
246 if (df->dwSize != sizeof(DIDATAFORMAT)) {
247 WARN("Non-standard DIDATAFORMAT structure size %d\n", df->dwSize);
249 TRACE(" - dwObjsize: %d\n", df->dwObjSize);
250 if (df->dwObjSize != sizeof(DIOBJECTDATAFORMAT)) {
251 WARN("Non-standard DIOBJECTDATAFORMAT structure size %d\n", df->dwObjSize);
253 TRACE(" - dwFlags: 0x%08x (", df->dwFlags);
254 switch (df->dwFlags) {
255 case DIDF_ABSAXIS: TRACE("DIDF_ABSAXIS"); break;
256 case DIDF_RELAXIS: TRACE("DIDF_RELAXIS"); break;
257 default: TRACE("unknown"); break;
259 TRACE(")\n");
260 TRACE(" - dwDataSize: %d\n", df->dwDataSize);
261 TRACE(" - dwNumObjs: %d\n", df->dwNumObjs);
263 for (i = 0; i < df->dwNumObjs; i++) {
264 TRACE(" - Object %d:\n", i);
265 TRACE(" * GUID: %s ('%s')\n", debugstr_guid(df->rgodf[i].pguid), _dump_dinput_GUID(df->rgodf[i].pguid));
266 TRACE(" * dwOfs: %d\n", df->rgodf[i].dwOfs);
267 TRACE(" * dwType: 0x%08x\n", df->rgodf[i].dwType);
268 TRACE(" "); _dump_EnumObjects_flags(df->rgodf[i].dwType); TRACE("\n");
269 TRACE(" * dwFlags: 0x%08x\n", df->rgodf[i].dwFlags);
270 TRACE(" "); _dump_ObjectDataFormat_flags(df->rgodf[i].dwFlags); TRACE("\n");
274 /******************************************************************************
275 * Get the default and the app-specific config keys.
277 BOOL get_app_key(HKEY *defkey, HKEY *appkey)
279 char buffer[MAX_PATH+16];
280 DWORD len;
282 *appkey = 0;
284 /* @@ Wine registry key: HKCU\Software\Wine\DirectInput */
285 if (RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\DirectInput", defkey))
286 *defkey = 0;
288 len = GetModuleFileNameA(0, buffer, MAX_PATH);
289 if (len && len < MAX_PATH)
291 HKEY tmpkey;
293 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DirectInput */
294 if (!RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey))
296 char *p, *appname = buffer;
297 if ((p = strrchr(appname, '/'))) appname = p + 1;
298 if ((p = strrchr(appname, '\\'))) appname = p + 1;
299 strcat(appname, "\\DirectInput");
301 if (RegOpenKeyA(tmpkey, appname, appkey)) *appkey = 0;
302 RegCloseKey(tmpkey);
306 return *defkey || *appkey;
309 /******************************************************************************
310 * Get a config key from either the app-specific or the default config
312 DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
313 char *buffer, DWORD size )
315 if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE)buffer, &size ))
316 return 0;
318 if (defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE)buffer, &size ))
319 return 0;
321 return ERROR_FILE_NOT_FOUND;
324 /* Conversion between internal data buffer and external data buffer */
325 void fill_DataFormat(void *out, DWORD size, const void *in, const DataFormat *df)
327 int i;
328 const char *in_c = in;
329 char *out_c = out;
331 memset(out, 0, size);
332 if (df->dt == NULL) {
333 /* This means that the app uses Wine's internal data format */
334 memcpy(out, in, min(size, df->internal_format_size));
335 } else {
336 for (i = 0; i < df->size; i++) {
337 if (df->dt[i].offset_in >= 0) {
338 switch (df->dt[i].size) {
339 case 1:
340 TRACE("Copying (c) to %d from %d (value %d)\n",
341 df->dt[i].offset_out, df->dt[i].offset_in, *(in_c + df->dt[i].offset_in));
342 *(out_c + df->dt[i].offset_out) = *(in_c + df->dt[i].offset_in);
343 break;
345 case 2:
346 TRACE("Copying (s) to %d from %d (value %d)\n",
347 df->dt[i].offset_out, df->dt[i].offset_in, *((const short *)(in_c + df->dt[i].offset_in)));
348 *((short *)(out_c + df->dt[i].offset_out)) = *((const short *)(in_c + df->dt[i].offset_in));
349 break;
351 case 4:
352 TRACE("Copying (i) to %d from %d (value %d)\n",
353 df->dt[i].offset_out, df->dt[i].offset_in, *((const int *)(in_c + df->dt[i].offset_in)));
354 *((int *)(out_c + df->dt[i].offset_out)) = *((const int *)(in_c + df->dt[i].offset_in));
355 break;
357 default:
358 memcpy((out_c + df->dt[i].offset_out), (in_c + df->dt[i].offset_in), df->dt[i].size);
359 break;
361 } else {
362 switch (df->dt[i].size) {
363 case 1:
364 TRACE("Copying (c) to %d default value %d\n",
365 df->dt[i].offset_out, df->dt[i].value);
366 *(out_c + df->dt[i].offset_out) = (char) df->dt[i].value;
367 break;
369 case 2:
370 TRACE("Copying (s) to %d default value %d\n",
371 df->dt[i].offset_out, df->dt[i].value);
372 *((short *) (out_c + df->dt[i].offset_out)) = (short) df->dt[i].value;
373 break;
375 case 4:
376 TRACE("Copying (i) to %d default value %d\n",
377 df->dt[i].offset_out, df->dt[i].value);
378 *((int *) (out_c + df->dt[i].offset_out)) = df->dt[i].value;
379 break;
381 default:
382 memset((out_c + df->dt[i].offset_out), 0, df->dt[i].size);
383 break;
390 void release_DataFormat(DataFormat * format)
392 TRACE("Deleting DataFormat: %p\n", format);
394 HeapFree(GetProcessHeap(), 0, format->dt);
395 format->dt = NULL;
396 HeapFree(GetProcessHeap(), 0, format->offsets);
397 format->offsets = NULL;
398 HeapFree(GetProcessHeap(), 0, format->user_df);
399 format->user_df = NULL;
402 static inline LPDIOBJECTDATAFORMAT dataformat_to_odf(LPCDIDATAFORMAT df, int idx)
404 if (idx < 0 || idx >= df->dwNumObjs) return NULL;
405 return (LPDIOBJECTDATAFORMAT)((LPBYTE)df->rgodf + idx * df->dwObjSize);
408 /* dataformat_to_odf_by_type
409 * Find the Nth object of the selected type in the DataFormat
411 LPDIOBJECTDATAFORMAT dataformat_to_odf_by_type(LPCDIDATAFORMAT df, int n, DWORD type)
413 int i, nfound = 0;
415 for (i=0; i < df->dwNumObjs; i++)
417 LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(df, i);
419 if (odf->dwType & type)
421 if (n == nfound)
422 return odf;
424 nfound++;
428 return NULL;
431 static HRESULT create_DataFormat(LPCDIDATAFORMAT asked_format, DataFormat *format)
433 DataTransform *dt;
434 unsigned int i, j;
435 int same = 1;
436 int *done;
437 int index = 0;
438 DWORD next = 0;
440 if (!format->wine_df) return DIERR_INVALIDPARAM;
441 done = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, asked_format->dwNumObjs * sizeof(int));
442 dt = HeapAlloc(GetProcessHeap(), 0, asked_format->dwNumObjs * sizeof(DataTransform));
443 if (!dt || !done) goto failed;
445 if (!(format->offsets = HeapAlloc(GetProcessHeap(), 0, format->wine_df->dwNumObjs * sizeof(int))))
446 goto failed;
448 if (!(format->user_df = HeapAlloc(GetProcessHeap(), 0, asked_format->dwSize)))
449 goto failed;
450 memcpy(format->user_df, asked_format, asked_format->dwSize);
452 TRACE("Creating DataTransform :\n");
454 for (i = 0; i < format->wine_df->dwNumObjs; i++)
456 format->offsets[i] = -1;
458 for (j = 0; j < asked_format->dwNumObjs; j++) {
459 if (done[j] == 1)
460 continue;
462 if (/* Check if the application either requests any GUID and if not, it if matches
463 * the GUID of the Wine object.
465 ((asked_format->rgodf[j].pguid == NULL) ||
466 (format->wine_df->rgodf[i].pguid == NULL) ||
467 (IsEqualGUID(format->wine_df->rgodf[i].pguid, asked_format->rgodf[j].pguid)))
469 (/* Then check if it accepts any instance id, and if not, if it matches Wine's
470 * instance id.
472 ((asked_format->rgodf[j].dwType & DIDFT_INSTANCEMASK) == DIDFT_ANYINSTANCE) ||
473 (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == 0x00FF) || /* This is mentioned in no DX docs, but it works fine - tested on WinXP */
474 (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == DIDFT_GETINSTANCE(format->wine_df->rgodf[i].dwType)))
476 ( /* Then if the asked type matches the one Wine provides */
477 DIDFT_GETTYPE(asked_format->rgodf[j].dwType) & format->wine_df->rgodf[i].dwType))
479 done[j] = 1;
481 TRACE("Matching :\n");
482 TRACE(" - Asked (%d) :\n", j);
483 TRACE(" * GUID: %s ('%s')\n",
484 debugstr_guid(asked_format->rgodf[j].pguid),
485 _dump_dinput_GUID(asked_format->rgodf[j].pguid));
486 TRACE(" * Offset: %3d\n", asked_format->rgodf[j].dwOfs);
487 TRACE(" * dwType: 0x%08x\n", asked_format->rgodf[j].dwType);
488 TRACE(" "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
489 TRACE(" * dwFlags: 0x%08x\n", asked_format->rgodf[j].dwFlags);
490 TRACE(" "); _dump_ObjectDataFormat_flags(asked_format->rgodf[j].dwFlags); TRACE("\n");
492 TRACE(" - Wine (%d) :\n", i);
493 TRACE(" * GUID: %s ('%s')\n",
494 debugstr_guid(format->wine_df->rgodf[i].pguid),
495 _dump_dinput_GUID(format->wine_df->rgodf[i].pguid));
496 TRACE(" * Offset: %3d\n", format->wine_df->rgodf[i].dwOfs);
497 TRACE(" * dwType: 0x%08x\n", format->wine_df->rgodf[i].dwType);
498 TRACE(" "); _dump_EnumObjects_flags(format->wine_df->rgodf[i].dwType); TRACE("\n");
499 TRACE(" * dwFlags: 0x%08x\n", format->wine_df->rgodf[i].dwFlags);
500 TRACE(" "); _dump_ObjectDataFormat_flags(format->wine_df->rgodf[i].dwFlags); TRACE("\n");
502 if (format->wine_df->rgodf[i].dwType & DIDFT_BUTTON)
503 dt[index].size = sizeof(BYTE);
504 else
505 dt[index].size = sizeof(DWORD);
506 dt[index].offset_in = format->wine_df->rgodf[i].dwOfs;
507 dt[index].offset_out = asked_format->rgodf[j].dwOfs;
508 format->offsets[i] = asked_format->rgodf[j].dwOfs;
509 dt[index].value = 0;
510 next = next + dt[index].size;
512 if (format->wine_df->rgodf[i].dwOfs != dt[index].offset_out)
513 same = 0;
515 index++;
516 break;
521 TRACE("Setting to default value :\n");
522 for (j = 0; j < asked_format->dwNumObjs; j++) {
523 if (done[j] == 0) {
524 TRACE(" - Asked (%d) :\n", j);
525 TRACE(" * GUID: %s ('%s')\n",
526 debugstr_guid(asked_format->rgodf[j].pguid),
527 _dump_dinput_GUID(asked_format->rgodf[j].pguid));
528 TRACE(" * Offset: %3d\n", asked_format->rgodf[j].dwOfs);
529 TRACE(" * dwType: 0x%08x\n", asked_format->rgodf[j].dwType);
530 TRACE(" "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
531 TRACE(" * dwFlags: 0x%08x\n", asked_format->rgodf[j].dwFlags);
532 TRACE(" "); _dump_ObjectDataFormat_flags(asked_format->rgodf[j].dwFlags); TRACE("\n");
534 if (asked_format->rgodf[j].dwType & DIDFT_BUTTON)
535 dt[index].size = sizeof(BYTE);
536 else
537 dt[index].size = sizeof(DWORD);
538 dt[index].offset_in = -1;
539 dt[index].offset_out = asked_format->rgodf[j].dwOfs;
540 if (asked_format->rgodf[j].dwType & DIDFT_POV)
541 dt[index].value = -1;
542 else
543 dt[index].value = 0;
544 index++;
546 same = 0;
550 format->internal_format_size = format->wine_df->dwDataSize;
551 format->size = index;
552 if (same) {
553 HeapFree(GetProcessHeap(), 0, dt);
554 dt = NULL;
556 format->dt = dt;
558 HeapFree(GetProcessHeap(), 0, done);
560 return DI_OK;
562 failed:
563 HeapFree(GetProcessHeap(), 0, done);
564 HeapFree(GetProcessHeap(), 0, dt);
565 format->dt = NULL;
566 HeapFree(GetProcessHeap(), 0, format->offsets);
567 format->offsets = NULL;
568 HeapFree(GetProcessHeap(), 0, format->user_df);
569 format->user_df = NULL;
571 return DIERR_OUTOFMEMORY;
574 static int verify_offset(const DataFormat *df, int offset)
576 int i;
578 if (!df->offsets)
579 return -1;
581 for (i = df->wine_df->dwNumObjs - 1; i >= 0; i--)
583 if (df->offsets[i] == offset)
584 return offset;
587 return -1;
590 /* find an object by its offset in a data format */
591 static int offset_to_object(const DataFormat *df, int offset)
593 int i;
595 if (!df->offsets) return -1;
597 for (i = 0; i < df->wine_df->dwNumObjs; i++)
598 if (df->offsets[i] == offset) return i;
600 return -1;
603 int id_to_object(LPCDIDATAFORMAT df, int id)
605 int i;
607 id &= 0x00ffffff;
608 for (i = 0; i < df->dwNumObjs; i++)
609 if ((dataformat_to_odf(df, i)->dwType & 0x00ffffff) == id)
610 return i;
612 return -1;
615 static int id_to_offset(const DataFormat *df, int id)
617 int obj = id_to_object(df->wine_df, id);
619 return obj >= 0 && df->offsets ? df->offsets[obj] : -1;
622 int find_property(const DataFormat *df, LPCDIPROPHEADER ph)
624 switch (ph->dwHow)
626 case DIPH_BYID: return id_to_object(df->wine_df, ph->dwObj);
627 case DIPH_BYOFFSET: return offset_to_object(df, ph->dwObj);
629 FIXME("Unhandled ph->dwHow=='%04X'\n", (unsigned int)ph->dwHow);
631 return -1;
634 static DWORD semantic_to_obj_id(IDirectInputDeviceImpl* This, DWORD dwSemantic)
636 DWORD type = (0x0000ff00 & dwSemantic) >> 8;
637 DWORD offset = 0x000000ff & dwSemantic;
638 DWORD obj_instance = 0;
639 BOOL found = FALSE;
640 int i;
642 for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++)
644 LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(This->data_format.wine_df, i);
646 if (odf->dwOfs == offset)
648 obj_instance = DIDFT_GETINSTANCE(odf->dwType);
649 found = TRUE;
650 break;
654 if (!found) return 0;
656 if (type & DIDFT_AXIS) type = DIDFT_RELAXIS;
657 if (type & DIDFT_BUTTON) type = DIDFT_PSHBUTTON;
659 return type | (0x0000ff00 & (obj_instance << 8));
663 * get_mapping_key
664 * Retrieves an open registry key to save the mapping, parametrized for an username,
665 * specific device and specific action mapping guid.
667 static HKEY get_mapping_key(const WCHAR *device, const WCHAR *username, const WCHAR *guid)
669 static const WCHAR subkey[] = {
670 'S','o','f','t','w','a','r','e','\\',
671 'W','i','n','e','\\',
672 'D','i','r','e','c','t','I','n','p','u','t','\\',
673 'M','a','p','p','i','n','g','s','\\','%','s','\\','%','s','\\','%','s','\0'};
674 HKEY hkey;
675 WCHAR *keyname;
677 keyname = HeapAlloc(GetProcessHeap(), 0,
678 sizeof(WCHAR) * (lstrlenW(subkey) + strlenW(username) + strlenW(device) + strlenW(guid)));
679 sprintfW(keyname, subkey, username, device, guid);
681 /* The key used is HKCU\Software\Wine\DirectInput\Mappings\[username]\[device]\[mapping_guid] */
682 if (RegCreateKeyW(HKEY_CURRENT_USER, keyname, &hkey))
683 hkey = 0;
685 HeapFree(GetProcessHeap(), 0, keyname);
687 return hkey;
690 static HRESULT save_mapping_settings(IDirectInputDevice8W *iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUsername)
692 WCHAR *guid_str = NULL;
693 DIDEVICEINSTANCEW didev;
694 HKEY hkey;
695 int i;
697 didev.dwSize = sizeof(didev);
698 IDirectInputDevice8_GetDeviceInfo(iface, &didev);
700 if (StringFromCLSID(&lpdiaf->guidActionMap, &guid_str) != S_OK)
701 return DI_SETTINGSNOTSAVED;
703 hkey = get_mapping_key(didev.tszInstanceName, lpszUsername, guid_str);
705 if (!hkey)
707 CoTaskMemFree(guid_str);
708 return DI_SETTINGSNOTSAVED;
711 /* Write each of the actions mapped for this device.
712 Format is "dwSemantic"="dwObjID" and key is of type REG_DWORD
714 for (i = 0; i < lpdiaf->dwNumActions; i++)
716 static const WCHAR format[] = {'%','x','\0'};
717 WCHAR label[9];
719 if (IsEqualGUID(&didev.guidInstance, &lpdiaf->rgoAction[i].guidInstance) &&
720 lpdiaf->rgoAction[i].dwHow != DIAH_UNMAPPED)
722 sprintfW(label, format, lpdiaf->rgoAction[i].dwSemantic);
723 RegSetValueExW(hkey, label, 0, REG_DWORD, (const BYTE*) &lpdiaf->rgoAction[i].dwObjID, sizeof(DWORD));
727 RegCloseKey(hkey);
728 CoTaskMemFree(guid_str);
730 return DI_OK;
733 static BOOL load_mapping_settings(IDirectInputDeviceImpl *This, LPDIACTIONFORMATW lpdiaf, const WCHAR *username)
735 HKEY hkey;
736 WCHAR *guid_str;
737 DIDEVICEINSTANCEW didev;
738 int i, mapped = 0;
740 didev.dwSize = sizeof(didev);
741 IDirectInputDevice8_GetDeviceInfo(&This->IDirectInputDevice8W_iface, &didev);
743 if (StringFromCLSID(&lpdiaf->guidActionMap, &guid_str) != S_OK)
744 return FALSE;
746 hkey = get_mapping_key(didev.tszInstanceName, username, guid_str);
748 if (!hkey)
750 CoTaskMemFree(guid_str);
751 return FALSE;
754 /* Try to read each action in the DIACTIONFORMAT from registry */
755 for (i = 0; i < lpdiaf->dwNumActions; i++)
757 static const WCHAR format[] = {'%','x','\0'};
758 DWORD id, size = sizeof(DWORD);
759 WCHAR label[9];
761 sprintfW(label, format, lpdiaf->rgoAction[i].dwSemantic);
763 if (!RegQueryValueExW(hkey, label, 0, NULL, (LPBYTE) &id, &size))
765 lpdiaf->rgoAction[i].dwObjID = id;
766 lpdiaf->rgoAction[i].guidInstance = didev.guidInstance;
767 lpdiaf->rgoAction[i].dwHow = DIAH_DEFAULT;
768 mapped += 1;
772 RegCloseKey(hkey);
773 CoTaskMemFree(guid_str);
775 return mapped > 0;
778 static BOOL set_app_data(IDirectInputDeviceImpl *dev, int offset, UINT_PTR app_data)
780 int num_actions = dev->num_actions;
781 ActionMap *action_map = dev->action_map, *target_map = NULL;
783 if (num_actions == 0)
785 num_actions = 1;
786 action_map = HeapAlloc(GetProcessHeap(), 0, sizeof(ActionMap));
787 if (!action_map) return FALSE;
788 target_map = &action_map[0];
790 else
792 int i;
793 for (i = 0; i < num_actions; i++)
795 if (dev->action_map[i].offset != offset) continue;
796 target_map = &dev->action_map[i];
797 break;
800 if (!target_map)
802 num_actions++;
803 action_map = HeapReAlloc(GetProcessHeap(), 0, action_map, sizeof(ActionMap)*num_actions);
804 if (!action_map) return FALSE;
805 target_map = &action_map[num_actions-1];
809 target_map->offset = offset;
810 target_map->uAppData = app_data;
812 dev->action_map = action_map;
813 dev->num_actions = num_actions;
815 return TRUE;
818 HRESULT _build_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags, DWORD devMask, LPCDIDATAFORMAT df)
820 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
821 WCHAR username[MAX_PATH];
822 DWORD username_size = MAX_PATH;
823 int i;
824 BOOL load_success = FALSE, has_actions = FALSE;
826 /* Unless asked the contrary by these flags, try to load a previous mapping */
827 if (!(dwFlags & DIDBAM_HWDEFAULTS))
829 /* Retrieve logged user name if necessary */
830 if (lpszUserName == NULL)
831 GetUserNameW(username, &username_size);
832 else
833 lstrcpynW(username, lpszUserName, MAX_PATH);
835 load_success = load_mapping_settings(This, lpdiaf, username);
838 if (load_success) return DI_OK;
840 for (i=0; i < lpdiaf->dwNumActions; i++)
842 /* Don't touch a user configured action */
843 if (lpdiaf->rgoAction[i].dwHow == DIAH_USERCONFIG) continue;
845 if ((lpdiaf->rgoAction[i].dwSemantic & devMask) == devMask)
847 DWORD obj_id = semantic_to_obj_id(This, lpdiaf->rgoAction[i].dwSemantic);
848 DWORD type = DIDFT_GETTYPE(obj_id);
849 DWORD inst = DIDFT_GETINSTANCE(obj_id);
851 LPDIOBJECTDATAFORMAT odf;
853 if (type == DIDFT_PSHBUTTON) type = DIDFT_BUTTON;
854 if (type == DIDFT_RELAXIS) type = DIDFT_AXIS;
856 /* Make sure the object exists */
857 odf = dataformat_to_odf_by_type(df, inst, type);
859 if (odf != NULL)
861 lpdiaf->rgoAction[i].dwObjID = obj_id;
862 lpdiaf->rgoAction[i].guidInstance = This->guid;
863 lpdiaf->rgoAction[i].dwHow = DIAH_DEFAULT;
864 has_actions = TRUE;
867 else if (!(dwFlags & DIDBAM_PRESERVE))
869 /* We must clear action data belonging to other devices */
870 memset(&lpdiaf->rgoAction[i].guidInstance, 0, sizeof(GUID));
871 lpdiaf->rgoAction[i].dwHow = DIAH_UNMAPPED;
875 if (!has_actions) return DI_NOEFFECT;
877 return IDirectInputDevice8WImpl_BuildActionMap(iface, lpdiaf, lpszUserName, dwFlags);
880 HRESULT _set_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags, LPCDIDATAFORMAT df)
882 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
883 DIDATAFORMAT data_format;
884 DIOBJECTDATAFORMAT *obj_df = NULL;
885 DIPROPDWORD dp;
886 DIPROPRANGE dpr;
887 DIPROPSTRING dps;
888 WCHAR username[MAX_PATH];
889 DWORD username_size = MAX_PATH;
890 int i, action = 0, num_actions = 0;
891 unsigned int offset = 0;
892 ActionMap *action_map;
894 if (This->acquired) return DIERR_ACQUIRED;
896 data_format.dwSize = sizeof(data_format);
897 data_format.dwObjSize = sizeof(DIOBJECTDATAFORMAT);
898 data_format.dwFlags = DIDF_RELAXIS;
899 data_format.dwDataSize = lpdiaf->dwDataSize;
901 /* Count the actions */
902 for (i=0; i < lpdiaf->dwNumActions; i++)
903 if (IsEqualGUID(&This->guid, &lpdiaf->rgoAction[i].guidInstance))
904 num_actions++;
906 if (num_actions == 0) return DI_NOEFFECT;
908 /* Construct the dataformat and actionmap */
909 obj_df = HeapAlloc(GetProcessHeap(), 0, sizeof(DIOBJECTDATAFORMAT)*num_actions);
910 data_format.rgodf = (LPDIOBJECTDATAFORMAT)obj_df;
911 data_format.dwNumObjs = num_actions;
913 action_map = HeapAlloc(GetProcessHeap(), 0, sizeof(ActionMap)*num_actions);
915 for (i = 0; i < lpdiaf->dwNumActions; i++)
917 if (IsEqualGUID(&This->guid, &lpdiaf->rgoAction[i].guidInstance))
919 DWORD inst = DIDFT_GETINSTANCE(lpdiaf->rgoAction[i].dwObjID);
920 DWORD type = DIDFT_GETTYPE(lpdiaf->rgoAction[i].dwObjID);
921 LPDIOBJECTDATAFORMAT obj;
923 if (type == DIDFT_PSHBUTTON) type = DIDFT_BUTTON;
924 if (type == DIDFT_RELAXIS) type = DIDFT_AXIS;
926 obj = dataformat_to_odf_by_type(df, inst, type);
928 memcpy(&obj_df[action], obj, df->dwObjSize);
930 action_map[action].uAppData = lpdiaf->rgoAction[i].uAppData;
931 action_map[action].offset = offset;
932 obj_df[action].dwOfs = offset;
933 offset += (type & DIDFT_BUTTON) ? 1 : 4;
935 action++;
939 IDirectInputDevice8_SetDataFormat(iface, &data_format);
941 This->action_map = action_map;
942 This->num_actions = num_actions;
944 HeapFree(GetProcessHeap(), 0, obj_df);
946 /* Set the device properties according to the action format */
947 dpr.diph.dwSize = sizeof(DIPROPRANGE);
948 dpr.lMin = lpdiaf->lAxisMin;
949 dpr.lMax = lpdiaf->lAxisMax;
950 dpr.diph.dwHeaderSize = sizeof(DIPROPHEADER);
951 dpr.diph.dwHow = DIPH_DEVICE;
952 IDirectInputDevice8_SetProperty(iface, DIPROP_RANGE, &dpr.diph);
954 if (lpdiaf->dwBufferSize > 0)
956 dp.diph.dwSize = sizeof(DIPROPDWORD);
957 dp.dwData = lpdiaf->dwBufferSize;
958 dp.diph.dwHeaderSize = sizeof(DIPROPHEADER);
959 dp.diph.dwHow = DIPH_DEVICE;
960 IDirectInputDevice8_SetProperty(iface, DIPROP_BUFFERSIZE, &dp.diph);
963 /* Retrieve logged user name if necessary */
964 if (lpszUserName == NULL)
965 GetUserNameW(username, &username_size);
966 else
967 lstrcpynW(username, lpszUserName, MAX_PATH);
969 dps.diph.dwSize = sizeof(dps);
970 dps.diph.dwHeaderSize = sizeof(DIPROPHEADER);
971 dps.diph.dwObj = 0;
972 dps.diph.dwHow = DIPH_DEVICE;
973 if (dwFlags & DIDSAM_NOUSER)
974 dps.wsz[0] = '\0';
975 else
976 lstrcpynW(dps.wsz, username, ARRAY_SIZE(dps.wsz));
977 IDirectInputDevice8_SetProperty(iface, DIPROP_USERNAME, &dps.diph);
979 /* Save the settings to disk */
980 save_mapping_settings(iface, lpdiaf, username);
982 return DI_OK;
985 /******************************************************************************
986 * queue_event - add new event to the ring queue
989 void queue_event(LPDIRECTINPUTDEVICE8A iface, int inst_id, DWORD data, DWORD time, DWORD seq)
991 static ULONGLONG notify_ms = 0;
992 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
993 int next_pos, ofs = id_to_offset(&This->data_format, inst_id);
994 ULONGLONG time_ms = GetTickCount64();
996 /* Event is being set regardless of the queue state */
997 if (This->hEvent) SetEvent(This->hEvent);
999 if (time_ms - notify_ms > 1000)
1001 PostMessageW(GetDesktopWindow(), WM_WINE_NOTIFY_ACTIVITY, 0, 0);
1002 notify_ms = time_ms;
1005 if (!This->queue_len || This->overflow || ofs < 0) return;
1007 next_pos = (This->queue_head + 1) % This->queue_len;
1008 if (next_pos == This->queue_tail)
1010 TRACE(" queue overflowed\n");
1011 This->overflow = TRUE;
1012 return;
1015 TRACE(" queueing %d at offset %d (queue head %d / size %d)\n",
1016 data, ofs, This->queue_head, This->queue_len);
1018 This->data_queue[This->queue_head].dwOfs = ofs;
1019 This->data_queue[This->queue_head].dwData = data;
1020 This->data_queue[This->queue_head].dwTimeStamp = time;
1021 This->data_queue[This->queue_head].dwSequence = seq;
1022 This->data_queue[This->queue_head].uAppData = -1;
1024 /* Set uAppData by means of action mapping */
1025 if (This->num_actions > 0)
1027 int i;
1028 for (i=0; i < This->num_actions; i++)
1030 if (This->action_map[i].offset == ofs)
1032 TRACE("Offset %d mapped to uAppData %lu\n", ofs, This->action_map[i].uAppData);
1033 This->data_queue[This->queue_head].uAppData = This->action_map[i].uAppData;
1034 break;
1039 This->queue_head = next_pos;
1040 /* Send event if asked */
1043 /******************************************************************************
1044 * Acquire
1047 HRESULT WINAPI IDirectInputDevice2WImpl_Acquire(LPDIRECTINPUTDEVICE8W iface)
1049 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1050 HRESULT res;
1052 TRACE("(%p)\n", This);
1054 if (!This->data_format.user_df) return DIERR_INVALIDPARAM;
1055 if (This->dwCoopLevel & DISCL_FOREGROUND && This->win != GetForegroundWindow())
1056 return DIERR_OTHERAPPHASPRIO;
1058 EnterCriticalSection(&This->crit);
1059 res = This->acquired ? S_FALSE : DI_OK;
1060 This->acquired = 1;
1061 LeaveCriticalSection(&This->crit);
1062 if (res != DI_OK) return res;
1064 dinput_hooks_acquire_device(iface);
1065 check_dinput_hooks(iface, TRUE);
1067 return res;
1070 HRESULT WINAPI IDirectInputDevice2AImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
1072 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1073 return IDirectInputDevice2WImpl_Acquire(IDirectInputDevice8W_from_impl(This));
1077 /******************************************************************************
1078 * Unacquire
1081 HRESULT WINAPI IDirectInputDevice2WImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface)
1083 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1084 HRESULT res;
1086 TRACE("(%p)\n", This);
1088 EnterCriticalSection(&This->crit);
1089 res = !This->acquired ? DI_NOEFFECT : DI_OK;
1090 This->acquired = 0;
1091 LeaveCriticalSection(&This->crit);
1092 if (res != DI_OK) return res;
1094 dinput_hooks_unacquire_device(iface);
1095 check_dinput_hooks(iface, FALSE);
1097 return res;
1100 HRESULT WINAPI IDirectInputDevice2AImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
1102 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1103 return IDirectInputDevice2WImpl_Unacquire(IDirectInputDevice8W_from_impl(This));
1106 /******************************************************************************
1107 * IDirectInputDeviceA
1110 HRESULT WINAPI IDirectInputDevice2WImpl_SetDataFormat(LPDIRECTINPUTDEVICE8W iface, LPCDIDATAFORMAT df)
1112 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1113 HRESULT res = DI_OK;
1115 if (!df) return E_POINTER;
1116 TRACE("(%p) %p\n", This, df);
1117 _dump_DIDATAFORMAT(df);
1119 if (df->dwSize != sizeof(DIDATAFORMAT)) return DIERR_INVALIDPARAM;
1120 if (This->acquired) return DIERR_ACQUIRED;
1122 EnterCriticalSection(&This->crit);
1124 HeapFree(GetProcessHeap(), 0, This->action_map);
1125 This->action_map = NULL;
1126 This->num_actions = 0;
1128 release_DataFormat(&This->data_format);
1129 res = create_DataFormat(df, &This->data_format);
1131 LeaveCriticalSection(&This->crit);
1132 return res;
1135 HRESULT WINAPI IDirectInputDevice2AImpl_SetDataFormat(LPDIRECTINPUTDEVICE8A iface, LPCDIDATAFORMAT df)
1137 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1138 return IDirectInputDevice2WImpl_SetDataFormat(IDirectInputDevice8W_from_impl(This), df);
1141 /******************************************************************************
1142 * SetCooperativeLevel
1144 * Set cooperative level and the source window for the events.
1146 HRESULT WINAPI IDirectInputDevice2WImpl_SetCooperativeLevel(LPDIRECTINPUTDEVICE8W iface, HWND hwnd, DWORD dwflags)
1148 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1150 TRACE("(%p) %p,0x%08x\n", This, hwnd, dwflags);
1151 _dump_cooperativelevel_DI(dwflags);
1153 if ((dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == 0 ||
1154 (dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE) ||
1155 (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == 0 ||
1156 (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == (DISCL_FOREGROUND | DISCL_BACKGROUND))
1157 return DIERR_INVALIDPARAM;
1159 if (hwnd && GetWindowLongW(hwnd, GWL_STYLE) & WS_CHILD) return E_HANDLE;
1161 if (!hwnd && dwflags == (DISCL_NONEXCLUSIVE | DISCL_BACKGROUND))
1162 hwnd = GetDesktopWindow();
1164 if (!IsWindow(hwnd)) return E_HANDLE;
1166 /* For security reasons native does not allow exclusive background level
1167 for mouse and keyboard only */
1168 if (dwflags & DISCL_EXCLUSIVE && dwflags & DISCL_BACKGROUND &&
1169 (IsEqualGUID(&This->guid, &GUID_SysMouse) ||
1170 IsEqualGUID(&This->guid, &GUID_SysKeyboard)))
1171 return DIERR_UNSUPPORTED;
1173 /* Store the window which asks for the mouse */
1174 EnterCriticalSection(&This->crit);
1175 This->win = hwnd;
1176 This->dwCoopLevel = dwflags;
1177 LeaveCriticalSection(&This->crit);
1179 return DI_OK;
1182 HRESULT WINAPI IDirectInputDevice2AImpl_SetCooperativeLevel(LPDIRECTINPUTDEVICE8A iface, HWND hwnd, DWORD dwflags)
1184 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1185 return IDirectInputDevice2WImpl_SetCooperativeLevel(IDirectInputDevice8W_from_impl(This), hwnd, dwflags);
1188 /******************************************************************************
1189 * SetEventNotification : specifies event to be sent on state change
1191 HRESULT WINAPI IDirectInputDevice2WImpl_SetEventNotification(LPDIRECTINPUTDEVICE8W iface, HANDLE event)
1193 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1195 TRACE("(%p) %p\n", This, event);
1197 EnterCriticalSection(&This->crit);
1198 This->hEvent = event;
1199 LeaveCriticalSection(&This->crit);
1200 return DI_OK;
1203 HRESULT WINAPI IDirectInputDevice2AImpl_SetEventNotification(LPDIRECTINPUTDEVICE8A iface, HANDLE event)
1205 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1206 return IDirectInputDevice2WImpl_SetEventNotification(IDirectInputDevice8W_from_impl(This), event);
1210 ULONG WINAPI IDirectInputDevice2WImpl_Release(LPDIRECTINPUTDEVICE8W iface)
1212 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1213 ULONG ref = InterlockedDecrement(&(This->ref));
1215 TRACE("(%p) ref %d\n", This, ref);
1217 if (ref) return ref;
1219 IDirectInputDevice_Unacquire(iface);
1220 /* Reset the FF state, free all effects, etc */
1221 IDirectInputDevice8_SendForceFeedbackCommand(iface, DISFFC_RESET);
1223 HeapFree(GetProcessHeap(), 0, This->data_queue);
1225 /* Free data format */
1226 HeapFree(GetProcessHeap(), 0, This->data_format.wine_df->rgodf);
1227 HeapFree(GetProcessHeap(), 0, This->data_format.wine_df);
1228 release_DataFormat(&This->data_format);
1230 /* Free action mapping */
1231 HeapFree(GetProcessHeap(), 0, This->action_map);
1233 IDirectInput_Release(&This->dinput->IDirectInput7A_iface);
1234 This->crit.DebugInfo->Spare[0] = 0;
1235 DeleteCriticalSection(&This->crit);
1237 HeapFree(GetProcessHeap(), 0, This);
1239 return ref;
1242 ULONG WINAPI IDirectInputDevice2AImpl_Release(LPDIRECTINPUTDEVICE8A iface)
1244 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1245 return IDirectInputDevice2WImpl_Release(IDirectInputDevice8W_from_impl(This));
1248 HRESULT WINAPI IDirectInputDevice2WImpl_QueryInterface(LPDIRECTINPUTDEVICE8W iface, REFIID riid, LPVOID *ppobj)
1250 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1252 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), ppobj);
1253 if (IsEqualGUID(&IID_IUnknown, riid) ||
1254 IsEqualGUID(&IID_IDirectInputDeviceA, riid) ||
1255 IsEqualGUID(&IID_IDirectInputDevice2A, riid) ||
1256 IsEqualGUID(&IID_IDirectInputDevice7A, riid) ||
1257 IsEqualGUID(&IID_IDirectInputDevice8A, riid))
1259 IDirectInputDevice2_AddRef(iface);
1260 *ppobj = IDirectInputDevice8A_from_impl(This);
1261 return DI_OK;
1263 if (IsEqualGUID(&IID_IDirectInputDeviceW, riid) ||
1264 IsEqualGUID(&IID_IDirectInputDevice2W, riid) ||
1265 IsEqualGUID(&IID_IDirectInputDevice7W, riid) ||
1266 IsEqualGUID(&IID_IDirectInputDevice8W, riid))
1268 IDirectInputDevice2_AddRef(iface);
1269 *ppobj = IDirectInputDevice8W_from_impl(This);
1270 return DI_OK;
1273 WARN("Unsupported interface!\n");
1274 return E_NOINTERFACE;
1277 HRESULT WINAPI IDirectInputDevice2AImpl_QueryInterface(LPDIRECTINPUTDEVICE8A iface, REFIID riid, LPVOID *ppobj)
1279 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1280 return IDirectInputDevice2WImpl_QueryInterface(IDirectInputDevice8W_from_impl(This), riid, ppobj);
1283 ULONG WINAPI IDirectInputDevice2WImpl_AddRef(LPDIRECTINPUTDEVICE8W iface)
1285 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1286 ULONG ref = InterlockedIncrement(&This->ref);
1287 TRACE( "(%p) ref %d\n", This, ref );
1288 return ref;
1291 ULONG WINAPI IDirectInputDevice2AImpl_AddRef(LPDIRECTINPUTDEVICE8A iface)
1293 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1294 return IDirectInputDevice2WImpl_AddRef(IDirectInputDevice8W_from_impl(This));
1297 HRESULT WINAPI IDirectInputDevice2AImpl_EnumObjects(LPDIRECTINPUTDEVICE8A iface,
1298 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback, LPVOID lpvRef, DWORD dwFlags)
1300 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1301 DIDEVICEOBJECTINSTANCEA ddoi;
1302 int i;
1304 TRACE("(%p)->(%p,%p flags:%08x)\n", This, lpCallback, lpvRef, dwFlags);
1305 TRACE(" - flags = ");
1306 _dump_EnumObjects_flags(dwFlags);
1307 TRACE("\n");
1309 /* Only the fields till dwFFMaxForce are relevant */
1310 memset(&ddoi, 0, sizeof(ddoi));
1311 ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce);
1313 for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++)
1315 LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(This->data_format.wine_df, i);
1317 if (dwFlags != DIDFT_ALL && !(dwFlags & DIDFT_GETTYPE(odf->dwType))) continue;
1318 if (IDirectInputDevice_GetObjectInfo(iface, &ddoi, odf->dwType, DIPH_BYID) != DI_OK)
1319 continue;
1321 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) break;
1324 return DI_OK;
1327 HRESULT WINAPI IDirectInputDevice2WImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface,
1328 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback, LPVOID lpvRef, DWORD dwFlags)
1330 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1331 DIDEVICEOBJECTINSTANCEW ddoi;
1332 int i;
1334 TRACE("(%p)->(%p,%p flags:%08x)\n", This, lpCallback, lpvRef, dwFlags);
1335 TRACE(" - flags = ");
1336 _dump_EnumObjects_flags(dwFlags);
1337 TRACE("\n");
1339 /* Only the fields till dwFFMaxForce are relevant */
1340 memset(&ddoi, 0, sizeof(ddoi));
1341 ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEW, dwFFMaxForce);
1343 for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++)
1345 LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(This->data_format.wine_df, i);
1347 if (dwFlags != DIDFT_ALL && !(dwFlags & DIDFT_GETTYPE(odf->dwType))) continue;
1348 if (IDirectInputDevice_GetObjectInfo(iface, &ddoi, odf->dwType, DIPH_BYID) != DI_OK)
1349 continue;
1351 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) break;
1354 return DI_OK;
1357 /******************************************************************************
1358 * GetProperty
1361 HRESULT WINAPI IDirectInputDevice2WImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface, REFGUID rguid, LPDIPROPHEADER pdiph)
1363 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1365 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(rguid), pdiph);
1366 _dump_DIPROPHEADER(pdiph);
1368 if (!IS_DIPROP(rguid)) return DI_OK;
1370 switch (LOWORD(rguid))
1372 case (DWORD_PTR) DIPROP_BUFFERSIZE:
1374 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
1376 if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
1378 pd->dwData = This->buffersize;
1379 TRACE("buffersize = %d\n", pd->dwData);
1380 break;
1382 case (DWORD_PTR) DIPROP_USERNAME:
1384 LPDIPROPSTRING ps = (LPDIPROPSTRING)pdiph;
1385 struct DevicePlayer *device_player;
1387 if (pdiph->dwSize != sizeof(DIPROPSTRING)) return DIERR_INVALIDPARAM;
1389 LIST_FOR_EACH_ENTRY(device_player, &This->dinput->device_players,
1390 struct DevicePlayer, entry)
1392 if (IsEqualGUID(&device_player->instance_guid, &This->guid))
1394 if (*device_player->username)
1396 lstrcpynW(ps->wsz, device_player->username, ARRAY_SIZE(ps->wsz));
1397 return DI_OK;
1399 else break;
1402 return S_FALSE;
1404 case (DWORD_PTR) DIPROP_VIDPID:
1405 FIXME("DIPROP_VIDPID not implemented\n");
1406 return DIERR_UNSUPPORTED;
1407 default:
1408 FIXME("Unknown property %s\n", debugstr_guid(rguid));
1409 return DIERR_INVALIDPARAM;
1412 return DI_OK;
1415 HRESULT WINAPI IDirectInputDevice2AImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPDIPROPHEADER pdiph)
1417 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1418 return IDirectInputDevice2WImpl_GetProperty(IDirectInputDevice8W_from_impl(This), rguid, pdiph);
1421 /******************************************************************************
1422 * SetProperty
1425 HRESULT WINAPI IDirectInputDevice2WImpl_SetProperty(
1426 LPDIRECTINPUTDEVICE8W iface, REFGUID rguid, LPCDIPROPHEADER pdiph)
1428 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1430 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(rguid), pdiph);
1431 _dump_DIPROPHEADER(pdiph);
1433 if (!IS_DIPROP(rguid)) return DI_OK;
1435 switch (LOWORD(rguid))
1437 case (DWORD_PTR) DIPROP_AXISMODE:
1439 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph;
1441 if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
1442 if (pdiph->dwHow == DIPH_DEVICE && pdiph->dwObj) return DIERR_INVALIDPARAM;
1443 if (This->acquired) return DIERR_ACQUIRED;
1444 if (pdiph->dwHow != DIPH_DEVICE) return DIERR_UNSUPPORTED;
1445 if (!This->data_format.user_df) return DI_OK;
1447 TRACE("Axis mode: %s\n", pd->dwData == DIPROPAXISMODE_ABS ? "absolute" :
1448 "relative");
1450 EnterCriticalSection(&This->crit);
1451 This->data_format.user_df->dwFlags &= ~DIDFT_AXIS;
1452 This->data_format.user_df->dwFlags |= pd->dwData == DIPROPAXISMODE_ABS ?
1453 DIDF_ABSAXIS : DIDF_RELAXIS;
1454 LeaveCriticalSection(&This->crit);
1455 break;
1457 case (DWORD_PTR) DIPROP_BUFFERSIZE:
1459 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph;
1461 if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
1462 if (This->acquired) return DIERR_ACQUIRED;
1464 TRACE("buffersize = %d\n", pd->dwData);
1466 EnterCriticalSection(&This->crit);
1468 This->buffersize = pd->dwData;
1469 This->queue_len = min(This->buffersize, 1024);
1470 HeapFree(GetProcessHeap(), 0, This->data_queue);
1472 This->data_queue = !This->queue_len ? NULL : HeapAlloc(GetProcessHeap(), 0,
1473 This->queue_len * sizeof(DIDEVICEOBJECTDATA));
1474 This->queue_head = This->queue_tail = This->overflow = 0;
1476 LeaveCriticalSection(&This->crit);
1477 break;
1479 case (DWORD_PTR) DIPROP_USERNAME:
1481 LPCDIPROPSTRING ps = (LPCDIPROPSTRING)pdiph;
1482 struct DevicePlayer *device_player;
1483 BOOL found = FALSE;
1485 if (pdiph->dwSize != sizeof(DIPROPSTRING)) return DIERR_INVALIDPARAM;
1487 LIST_FOR_EACH_ENTRY(device_player, &This->dinput->device_players,
1488 struct DevicePlayer, entry)
1490 if (IsEqualGUID(&device_player->instance_guid, &This->guid))
1492 found = TRUE;
1493 break;
1496 if (!found && (device_player =
1497 HeapAlloc(GetProcessHeap(), 0, sizeof(struct DevicePlayer))))
1499 list_add_tail(&This->dinput->device_players, &device_player->entry);
1500 device_player->instance_guid = This->guid;
1502 if (device_player)
1503 lstrcpynW(device_player->username, ps->wsz, ARRAY_SIZE(device_player->username));
1504 break;
1506 case (DWORD_PTR) DIPROP_APPDATA:
1508 int offset = -1;
1509 LPCDIPROPPOINTER pp = (LPCDIPROPPOINTER)pdiph;
1510 if (pdiph->dwSize != sizeof(DIPROPPOINTER)) return DIERR_INVALIDPARAM;
1512 if (pdiph->dwHow == DIPH_BYID)
1513 offset = id_to_offset(&This->data_format, pdiph->dwObj);
1514 else if (pdiph->dwHow == DIPH_BYOFFSET)
1515 offset = verify_offset(&This->data_format, pdiph->dwObj);
1516 else
1517 return DIERR_UNSUPPORTED;
1519 if (offset == -1) return DIERR_OBJECTNOTFOUND;
1520 if (!set_app_data(This, offset, pp->uData)) return DIERR_OUTOFMEMORY;
1521 break;
1523 default:
1524 WARN("Unknown property %s\n", debugstr_guid(rguid));
1525 return DIERR_UNSUPPORTED;
1528 return DI_OK;
1531 HRESULT WINAPI IDirectInputDevice2AImpl_SetProperty(
1532 LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPCDIPROPHEADER pdiph)
1534 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1535 return IDirectInputDevice2WImpl_SetProperty(IDirectInputDevice8W_from_impl(This), rguid, pdiph);
1538 HRESULT WINAPI IDirectInputDevice2AImpl_GetObjectInfo(
1539 LPDIRECTINPUTDEVICE8A iface,
1540 LPDIDEVICEOBJECTINSTANCEA pdidoi,
1541 DWORD dwObj,
1542 DWORD dwHow)
1544 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1545 DIDEVICEOBJECTINSTANCEW didoiW;
1546 HRESULT res;
1548 if (!pdidoi ||
1549 (pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCEA) &&
1550 pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCE_DX3A)))
1551 return DIERR_INVALIDPARAM;
1553 didoiW.dwSize = sizeof(didoiW);
1554 res = IDirectInputDevice2WImpl_GetObjectInfo(IDirectInputDevice8W_from_impl(This), &didoiW, dwObj, dwHow);
1555 if (res == DI_OK)
1557 DWORD dwSize = pdidoi->dwSize;
1559 memset(pdidoi, 0, pdidoi->dwSize);
1560 pdidoi->dwSize = dwSize;
1561 pdidoi->guidType = didoiW.guidType;
1562 pdidoi->dwOfs = didoiW.dwOfs;
1563 pdidoi->dwType = didoiW.dwType;
1564 pdidoi->dwFlags = didoiW.dwFlags;
1567 return res;
1570 HRESULT WINAPI IDirectInputDevice2WImpl_GetObjectInfo(
1571 LPDIRECTINPUTDEVICE8W iface,
1572 LPDIDEVICEOBJECTINSTANCEW pdidoi,
1573 DWORD dwObj,
1574 DWORD dwHow)
1576 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1577 DWORD dwSize;
1578 LPDIOBJECTDATAFORMAT odf;
1579 int idx = -1;
1581 TRACE("(%p) %d(0x%08x) -> %p\n", This, dwHow, dwObj, pdidoi);
1583 if (!pdidoi ||
1584 (pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCEW) &&
1585 pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCE_DX3W)))
1586 return DIERR_INVALIDPARAM;
1588 switch (dwHow)
1590 case DIPH_BYOFFSET:
1591 if (!This->data_format.offsets) break;
1592 for (idx = This->data_format.wine_df->dwNumObjs - 1; idx >= 0; idx--)
1593 if (This->data_format.offsets[idx] == dwObj) break;
1594 break;
1595 case DIPH_BYID:
1596 dwObj &= 0x00ffffff;
1597 for (idx = This->data_format.wine_df->dwNumObjs - 1; idx >= 0; idx--)
1598 if ((dataformat_to_odf(This->data_format.wine_df, idx)->dwType & 0x00ffffff) == dwObj)
1599 break;
1600 break;
1602 case DIPH_BYUSAGE:
1603 FIXME("dwHow = DIPH_BYUSAGE not implemented\n");
1604 break;
1605 default:
1606 WARN("invalid parameter: dwHow = %08x\n", dwHow);
1607 return DIERR_INVALIDPARAM;
1609 if (idx < 0) return DIERR_OBJECTNOTFOUND;
1611 odf = dataformat_to_odf(This->data_format.wine_df, idx);
1612 dwSize = pdidoi->dwSize; /* save due to memset below */
1613 memset(pdidoi, 0, pdidoi->dwSize);
1614 pdidoi->dwSize = dwSize;
1615 if (odf->pguid) pdidoi->guidType = *odf->pguid;
1616 pdidoi->dwOfs = This->data_format.offsets ? This->data_format.offsets[idx] : odf->dwOfs;
1617 pdidoi->dwType = odf->dwType;
1618 pdidoi->dwFlags = odf->dwFlags;
1620 return DI_OK;
1623 HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceData(LPDIRECTINPUTDEVICE8W iface, DWORD dodsize,
1624 LPDIDEVICEOBJECTDATA dod, LPDWORD entries, DWORD flags)
1626 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1627 HRESULT ret = DI_OK;
1628 int len;
1630 TRACE("(%p) %p -> %p(%d) x%d, 0x%08x\n",
1631 This, dod, entries, entries ? *entries : 0, dodsize, flags);
1633 if (This->dinput->dwVersion == 0x0800 || dodsize == sizeof(DIDEVICEOBJECTDATA_DX3))
1635 if (!This->queue_len) return DIERR_NOTBUFFERED;
1636 if (!This->acquired) return DIERR_NOTACQUIRED;
1639 if (!This->queue_len)
1640 return DI_OK;
1641 if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3))
1642 return DIERR_INVALIDPARAM;
1644 IDirectInputDevice2_Poll(iface);
1645 EnterCriticalSection(&This->crit);
1647 len = This->queue_head - This->queue_tail;
1648 if (len < 0) len += This->queue_len;
1650 if ((*entries != INFINITE) && (len > *entries)) len = *entries;
1652 if (dod)
1654 int i;
1655 for (i = 0; i < len; i++)
1657 int n = (This->queue_tail + i) % This->queue_len;
1658 memcpy((char *)dod + dodsize * i, This->data_queue + n, dodsize);
1661 *entries = len;
1663 if (This->overflow && This->dinput->dwVersion == 0x0800)
1664 ret = DI_BUFFEROVERFLOW;
1666 if (!(flags & DIGDD_PEEK))
1668 /* Advance reading position */
1669 This->queue_tail = (This->queue_tail + len) % This->queue_len;
1670 This->overflow = FALSE;
1673 LeaveCriticalSection(&This->crit);
1675 TRACE("Returning %d events queued\n", *entries);
1676 return ret;
1679 HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface, DWORD dodsize,
1680 LPDIDEVICEOBJECTDATA dod, LPDWORD entries, DWORD flags)
1682 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1683 return IDirectInputDevice2WImpl_GetDeviceData(IDirectInputDevice8W_from_impl(This), dodsize, dod, entries, flags);
1686 HRESULT WINAPI IDirectInputDevice2WImpl_RunControlPanel(LPDIRECTINPUTDEVICE8W iface, HWND hwndOwner, DWORD dwFlags)
1688 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1689 FIXME("%p)->(%p,0x%08x): stub!\n", This, hwndOwner, dwFlags);
1691 return DI_OK;
1694 HRESULT WINAPI IDirectInputDevice2AImpl_RunControlPanel(LPDIRECTINPUTDEVICE8A iface, HWND hwndOwner, DWORD dwFlags)
1696 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1697 return IDirectInputDevice2WImpl_RunControlPanel(IDirectInputDevice8W_from_impl(This), hwndOwner, dwFlags);
1700 HRESULT WINAPI IDirectInputDevice2WImpl_Initialize(LPDIRECTINPUTDEVICE8W iface, HINSTANCE hinst, DWORD dwVersion,
1701 REFGUID rguid)
1703 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1704 FIXME("(%p)->(%p,%d,%s): stub!\n", This, hinst, dwVersion, debugstr_guid(rguid));
1705 return DI_OK;
1708 HRESULT WINAPI IDirectInputDevice2AImpl_Initialize(LPDIRECTINPUTDEVICE8A iface, HINSTANCE hinst, DWORD dwVersion,
1709 REFGUID rguid)
1711 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1712 return IDirectInputDevice2WImpl_Initialize(IDirectInputDevice8W_from_impl(This), hinst, dwVersion, rguid);
1715 /******************************************************************************
1716 * IDirectInputDevice2A
1719 HRESULT WINAPI IDirectInputDevice2WImpl_CreateEffect(LPDIRECTINPUTDEVICE8W iface, REFGUID rguid, LPCDIEFFECT lpeff,
1720 LPDIRECTINPUTEFFECT *ppdef, LPUNKNOWN pUnkOuter)
1722 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1723 FIXME("(%p)->(%s,%p,%p,%p): stub!\n", This, debugstr_guid(rguid), lpeff, ppdef, pUnkOuter);
1725 FIXME("not available in the generic implementation\n");
1726 *ppdef = NULL;
1727 return DIERR_UNSUPPORTED;
1730 HRESULT WINAPI IDirectInputDevice2AImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPCDIEFFECT lpeff,
1731 LPDIRECTINPUTEFFECT *ppdef, LPUNKNOWN pUnkOuter)
1733 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1734 return IDirectInputDevice2WImpl_CreateEffect(IDirectInputDevice8W_from_impl(This), rguid, lpeff, ppdef, pUnkOuter);
1737 HRESULT WINAPI IDirectInputDevice2AImpl_EnumEffects(
1738 LPDIRECTINPUTDEVICE8A iface,
1739 LPDIENUMEFFECTSCALLBACKA lpCallback,
1740 LPVOID lpvRef,
1741 DWORD dwFlags)
1743 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1744 FIXME("%p)->(%p,%p,0x%08x): stub!\n", This, lpCallback, lpvRef, dwFlags);
1746 return DI_OK;
1749 HRESULT WINAPI IDirectInputDevice2WImpl_EnumEffects(
1750 LPDIRECTINPUTDEVICE8W iface,
1751 LPDIENUMEFFECTSCALLBACKW lpCallback,
1752 LPVOID lpvRef,
1753 DWORD dwFlags)
1755 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1756 FIXME("(%p)->(%p,%p,0x%08x): stub!\n", This, lpCallback, lpvRef, dwFlags);
1758 return DI_OK;
1761 HRESULT WINAPI IDirectInputDevice2AImpl_GetEffectInfo(
1762 LPDIRECTINPUTDEVICE8A iface,
1763 LPDIEFFECTINFOA lpdei,
1764 REFGUID rguid)
1766 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1767 FIXME("(%p)->(%p,%s): stub!\n", This, lpdei, debugstr_guid(rguid));
1768 return DI_OK;
1771 HRESULT WINAPI IDirectInputDevice2WImpl_GetEffectInfo(
1772 LPDIRECTINPUTDEVICE8W iface,
1773 LPDIEFFECTINFOW lpdei,
1774 REFGUID rguid)
1776 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1777 FIXME("(%p)->(%p,%s): stub!\n", This, lpdei, debugstr_guid(rguid));
1778 return DI_OK;
1781 HRESULT WINAPI IDirectInputDevice2WImpl_GetForceFeedbackState(LPDIRECTINPUTDEVICE8W iface, LPDWORD pdwOut)
1783 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1784 FIXME("(%p)->(%p): stub!\n", This, pdwOut);
1785 return DI_OK;
1788 HRESULT WINAPI IDirectInputDevice2AImpl_GetForceFeedbackState(LPDIRECTINPUTDEVICE8A iface, LPDWORD pdwOut)
1790 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1791 return IDirectInputDevice2WImpl_GetForceFeedbackState(IDirectInputDevice8W_from_impl(This), pdwOut);
1794 HRESULT WINAPI IDirectInputDevice2WImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8W iface, DWORD dwFlags)
1796 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1797 TRACE("(%p)->(0x%08x)\n", This, dwFlags);
1798 return DI_NOEFFECT;
1801 HRESULT WINAPI IDirectInputDevice2AImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8A iface, DWORD dwFlags)
1803 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1804 return IDirectInputDevice2WImpl_SendForceFeedbackCommand(IDirectInputDevice8W_from_impl(This), dwFlags);
1807 HRESULT WINAPI IDirectInputDevice2WImpl_EnumCreatedEffectObjects(LPDIRECTINPUTDEVICE8W iface,
1808 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback, LPVOID lpvRef, DWORD dwFlags)
1810 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1811 FIXME("(%p)0>(%p,%p,0x%08x): stub!\n", This, lpCallback, lpvRef, dwFlags);
1812 return DI_OK;
1815 HRESULT WINAPI IDirectInputDevice2AImpl_EnumCreatedEffectObjects(LPDIRECTINPUTDEVICE8A iface,
1816 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback, LPVOID lpvRef, DWORD dwFlags)
1818 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1819 return IDirectInputDevice2WImpl_EnumCreatedEffectObjects(IDirectInputDevice8W_from_impl(This), lpCallback, lpvRef, dwFlags);
1822 HRESULT WINAPI IDirectInputDevice2WImpl_Escape(LPDIRECTINPUTDEVICE8W iface, LPDIEFFESCAPE lpDIEEsc)
1824 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1825 FIXME("(%p)->(%p): stub!\n", This, lpDIEEsc);
1826 return DI_OK;
1829 HRESULT WINAPI IDirectInputDevice2AImpl_Escape(LPDIRECTINPUTDEVICE8A iface, LPDIEFFESCAPE lpDIEEsc)
1831 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1832 return IDirectInputDevice2WImpl_Escape(IDirectInputDevice8W_from_impl(This), lpDIEEsc);
1835 HRESULT WINAPI IDirectInputDevice2WImpl_Poll(LPDIRECTINPUTDEVICE8W iface)
1837 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1839 if (!This->acquired) return DIERR_NOTACQUIRED;
1841 check_dinput_events();
1842 return DI_OK;
1845 HRESULT WINAPI IDirectInputDevice2AImpl_Poll(LPDIRECTINPUTDEVICE8A iface)
1847 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1848 return IDirectInputDevice2WImpl_Poll(IDirectInputDevice8W_from_impl(This));
1851 HRESULT WINAPI IDirectInputDevice2WImpl_SendDeviceData(LPDIRECTINPUTDEVICE8W iface, DWORD cbObjectData,
1852 LPCDIDEVICEOBJECTDATA rgdod, LPDWORD pdwInOut,
1853 DWORD dwFlags)
1855 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1856 FIXME("(%p)->(0x%08x,%p,%p,0x%08x): stub!\n", This, cbObjectData, rgdod, pdwInOut, dwFlags);
1858 return DI_OK;
1861 HRESULT WINAPI IDirectInputDevice2AImpl_SendDeviceData(LPDIRECTINPUTDEVICE8A iface, DWORD cbObjectData,
1862 LPCDIDEVICEOBJECTDATA rgdod, LPDWORD pdwInOut,
1863 DWORD dwFlags)
1865 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1866 return IDirectInputDevice2WImpl_SendDeviceData(IDirectInputDevice8W_from_impl(This), cbObjectData, rgdod,
1867 pdwInOut, dwFlags);
1870 HRESULT WINAPI IDirectInputDevice7AImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8A iface,
1871 LPCSTR lpszFileName,
1872 LPDIENUMEFFECTSINFILECALLBACK pec,
1873 LPVOID pvRef,
1874 DWORD dwFlags)
1876 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1877 FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", This, lpszFileName, pec, pvRef, dwFlags);
1879 return DI_OK;
1882 HRESULT WINAPI IDirectInputDevice7WImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8W iface,
1883 LPCWSTR lpszFileName,
1884 LPDIENUMEFFECTSINFILECALLBACK pec,
1885 LPVOID pvRef,
1886 DWORD dwFlags)
1888 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1889 FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", This, debugstr_w(lpszFileName), pec, pvRef, dwFlags);
1891 return DI_OK;
1894 HRESULT WINAPI IDirectInputDevice7AImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8A iface,
1895 LPCSTR lpszFileName,
1896 DWORD dwEntries,
1897 LPDIFILEEFFECT rgDiFileEft,
1898 DWORD dwFlags)
1900 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1901 FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", This, lpszFileName, dwEntries, rgDiFileEft, dwFlags);
1903 return DI_OK;
1906 HRESULT WINAPI IDirectInputDevice7WImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8W iface,
1907 LPCWSTR lpszFileName,
1908 DWORD dwEntries,
1909 LPDIFILEEFFECT rgDiFileEft,
1910 DWORD dwFlags)
1912 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1913 FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", This, debugstr_w(lpszFileName), dwEntries, rgDiFileEft, dwFlags);
1915 return DI_OK;
1918 HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface,
1919 LPDIACTIONFORMATW lpdiaf,
1920 LPCWSTR lpszUserName,
1921 DWORD dwFlags)
1923 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1924 FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", This, lpdiaf, debugstr_w(lpszUserName), dwFlags);
1925 #define X(x) if (dwFlags & x) FIXME("\tdwFlags =|"#x"\n");
1926 X(DIDBAM_DEFAULT)
1927 X(DIDBAM_PRESERVE)
1928 X(DIDBAM_INITIALIZE)
1929 X(DIDBAM_HWDEFAULTS)
1930 #undef X
1932 return DI_OK;
1935 HRESULT WINAPI IDirectInputDevice8AImpl_GetImageInfo(LPDIRECTINPUTDEVICE8A iface,
1936 LPDIDEVICEIMAGEINFOHEADERA lpdiDevImageInfoHeader)
1938 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1939 FIXME("(%p)->(%p): stub !\n", This, lpdiDevImageInfoHeader);
1941 return DI_OK;
1944 HRESULT WINAPI IDirectInputDevice8WImpl_GetImageInfo(LPDIRECTINPUTDEVICE8W iface,
1945 LPDIDEVICEIMAGEINFOHEADERW lpdiDevImageInfoHeader)
1947 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1948 FIXME("(%p)->(%p): stub !\n", This, lpdiDevImageInfoHeader);
1950 return DI_OK;