include: Make sure __int64 is correctly defined on PPC64.
[wine.git] / dlls / dinput / device.c
blob198e903fc2eca143f7a200ef8def4f02c9068e1e
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 /* find an object by its offset in a data format */
575 static int offset_to_object(const DataFormat *df, int offset)
577 int i;
579 if (!df->offsets) return -1;
581 for (i = 0; i < df->wine_df->dwNumObjs; i++)
582 if (df->offsets[i] == offset) return i;
584 return -1;
587 int id_to_object(LPCDIDATAFORMAT df, int id)
589 int i;
591 id &= 0x00ffffff;
592 for (i = 0; i < df->dwNumObjs; i++)
593 if ((dataformat_to_odf(df, i)->dwType & 0x00ffffff) == id)
594 return i;
596 return -1;
599 static int id_to_offset(const DataFormat *df, int id)
601 int obj = id_to_object(df->wine_df, id);
603 return obj >= 0 && df->offsets ? df->offsets[obj] : -1;
606 int find_property(const DataFormat *df, LPCDIPROPHEADER ph)
608 switch (ph->dwHow)
610 case DIPH_BYID: return id_to_object(df->wine_df, ph->dwObj);
611 case DIPH_BYOFFSET: return offset_to_object(df, ph->dwObj);
613 FIXME("Unhandled ph->dwHow=='%04X'\n", (unsigned int)ph->dwHow);
615 return -1;
618 static DWORD semantic_to_obj_id(IDirectInputDeviceImpl* This, DWORD dwSemantic)
620 DWORD type = (0x0000ff00 & dwSemantic) >> 8;
621 DWORD offset = 0x000000ff & dwSemantic;
622 DWORD obj_instance = 0;
623 BOOL found = FALSE;
624 int i;
626 for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++)
628 LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(This->data_format.wine_df, i);
630 if (odf->dwOfs == offset)
632 obj_instance = DIDFT_GETINSTANCE(odf->dwType);
633 found = TRUE;
634 break;
638 if (!found) return 0;
640 if (type & DIDFT_AXIS) type = DIDFT_RELAXIS;
641 if (type & DIDFT_BUTTON) type = DIDFT_PSHBUTTON;
643 return type | (0x0000ff00 & (obj_instance << 8));
647 * get_mapping_key
648 * Retrieves an open registry key to save the mapping, parametrized for an username,
649 * specific device and specific action mapping guid.
651 static HKEY get_mapping_key(const WCHAR *device, const WCHAR *username, const WCHAR *guid)
653 static const WCHAR subkey[] = {
654 'S','o','f','t','w','a','r','e','\\',
655 'W','i','n','e','\\',
656 'D','i','r','e','c','t','I','n','p','u','t','\\',
657 'M','a','p','p','i','n','g','s','\\','%','s','\\','%','s','\\','%','s','\0'};
658 HKEY hkey;
659 WCHAR *keyname;
661 keyname = HeapAlloc(GetProcessHeap(), 0,
662 sizeof(WCHAR) * (lstrlenW(subkey) + strlenW(username) + strlenW(device) + strlenW(guid)));
663 sprintfW(keyname, subkey, username, device, guid);
665 /* The key used is HKCU\Software\Wine\DirectInput\Mappings\[username]\[device]\[mapping_guid] */
666 if (RegCreateKeyW(HKEY_CURRENT_USER, keyname, &hkey))
667 hkey = 0;
669 HeapFree(GetProcessHeap(), 0, keyname);
671 return hkey;
674 static HRESULT save_mapping_settings(IDirectInputDevice8W *iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUsername)
676 WCHAR *guid_str = NULL;
677 DIDEVICEINSTANCEW didev;
678 HKEY hkey;
679 int i;
681 didev.dwSize = sizeof(didev);
682 IDirectInputDevice8_GetDeviceInfo(iface, &didev);
684 if (StringFromCLSID(&lpdiaf->guidActionMap, &guid_str) != S_OK)
685 return DI_SETTINGSNOTSAVED;
687 hkey = get_mapping_key(didev.tszInstanceName, lpszUsername, guid_str);
689 if (!hkey)
691 CoTaskMemFree(guid_str);
692 return DI_SETTINGSNOTSAVED;
695 /* Write each of the actions mapped for this device.
696 Format is "dwSemantic"="dwObjID" and key is of type REG_DWORD
698 for (i = 0; i < lpdiaf->dwNumActions; i++)
700 static const WCHAR format[] = {'%','x','\0'};
701 WCHAR label[9];
703 if (IsEqualGUID(&didev.guidInstance, &lpdiaf->rgoAction[i].guidInstance) &&
704 lpdiaf->rgoAction[i].dwHow != DIAH_UNMAPPED)
706 sprintfW(label, format, lpdiaf->rgoAction[i].dwSemantic);
707 RegSetValueExW(hkey, label, 0, REG_DWORD, (const BYTE*) &lpdiaf->rgoAction[i].dwObjID, sizeof(DWORD));
711 RegCloseKey(hkey);
712 CoTaskMemFree(guid_str);
714 return DI_OK;
717 static BOOL load_mapping_settings(IDirectInputDeviceImpl *This, LPDIACTIONFORMATW lpdiaf, const WCHAR *username)
719 HKEY hkey;
720 WCHAR *guid_str;
721 DIDEVICEINSTANCEW didev;
722 int i, mapped = 0;
724 didev.dwSize = sizeof(didev);
725 IDirectInputDevice8_GetDeviceInfo(&This->IDirectInputDevice8W_iface, &didev);
727 if (StringFromCLSID(&lpdiaf->guidActionMap, &guid_str) != S_OK)
728 return FALSE;
730 hkey = get_mapping_key(didev.tszInstanceName, username, guid_str);
732 if (!hkey)
734 CoTaskMemFree(guid_str);
735 return FALSE;
738 /* Try to read each action in the DIACTIONFORMAT from registry */
739 for (i = 0; i < lpdiaf->dwNumActions; i++)
741 static const WCHAR format[] = {'%','x','\0'};
742 DWORD id, size = sizeof(DWORD);
743 WCHAR label[9];
745 sprintfW(label, format, lpdiaf->rgoAction[i].dwSemantic);
747 if (!RegQueryValueExW(hkey, label, 0, NULL, (LPBYTE) &id, &size))
749 lpdiaf->rgoAction[i].dwObjID = id;
750 lpdiaf->rgoAction[i].guidInstance = didev.guidInstance;
751 lpdiaf->rgoAction[i].dwHow = DIAH_DEFAULT;
752 mapped += 1;
756 RegCloseKey(hkey);
757 CoTaskMemFree(guid_str);
759 return mapped > 0;
762 HRESULT _build_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags, DWORD devMask, LPCDIDATAFORMAT df)
764 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
765 WCHAR username[MAX_PATH];
766 DWORD username_size = MAX_PATH;
767 int i;
768 BOOL load_success = FALSE, has_actions = FALSE;
770 /* Unless asked the contrary by these flags, try to load a previous mapping */
771 if (!(dwFlags & DIDBAM_HWDEFAULTS))
773 /* Retrieve logged user name if necessary */
774 if (lpszUserName == NULL)
775 GetUserNameW(username, &username_size);
776 else
777 lstrcpynW(username, lpszUserName, MAX_PATH);
779 load_success = load_mapping_settings(This, lpdiaf, username);
782 if (load_success) return DI_OK;
784 for (i=0; i < lpdiaf->dwNumActions; i++)
786 /* Don't touch a user configured action */
787 if (lpdiaf->rgoAction[i].dwHow == DIAH_USERCONFIG) continue;
789 if ((lpdiaf->rgoAction[i].dwSemantic & devMask) == devMask)
791 DWORD obj_id = semantic_to_obj_id(This, lpdiaf->rgoAction[i].dwSemantic);
792 DWORD type = DIDFT_GETTYPE(obj_id);
793 DWORD inst = DIDFT_GETINSTANCE(obj_id);
795 LPDIOBJECTDATAFORMAT odf;
797 if (type == DIDFT_PSHBUTTON) type = DIDFT_BUTTON;
798 if (type == DIDFT_RELAXIS) type = DIDFT_AXIS;
800 /* Make sure the object exists */
801 odf = dataformat_to_odf_by_type(df, inst, type);
803 if (odf != NULL)
805 lpdiaf->rgoAction[i].dwObjID = obj_id;
806 lpdiaf->rgoAction[i].guidInstance = This->guid;
807 lpdiaf->rgoAction[i].dwHow = DIAH_DEFAULT;
808 has_actions = TRUE;
811 else if (!(dwFlags & DIDBAM_PRESERVE))
813 /* We must clear action data belonging to other devices */
814 memset(&lpdiaf->rgoAction[i].guidInstance, 0, sizeof(GUID));
815 lpdiaf->rgoAction[i].dwHow = DIAH_UNMAPPED;
819 if (!has_actions) return DI_NOEFFECT;
821 return IDirectInputDevice8WImpl_BuildActionMap(iface, lpdiaf, lpszUserName, dwFlags);
824 HRESULT _set_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags, LPCDIDATAFORMAT df)
826 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
827 DIDATAFORMAT data_format;
828 DIOBJECTDATAFORMAT *obj_df = NULL;
829 DIPROPDWORD dp;
830 DIPROPRANGE dpr;
831 DIPROPSTRING dps;
832 WCHAR username[MAX_PATH];
833 DWORD username_size = MAX_PATH;
834 int i, action = 0, num_actions = 0;
835 unsigned int offset = 0;
837 if (This->acquired) return DIERR_ACQUIRED;
839 data_format.dwSize = sizeof(data_format);
840 data_format.dwObjSize = sizeof(DIOBJECTDATAFORMAT);
841 data_format.dwFlags = DIDF_RELAXIS;
842 data_format.dwDataSize = lpdiaf->dwDataSize;
844 /* Count the actions */
845 for (i=0; i < lpdiaf->dwNumActions; i++)
846 if (IsEqualGUID(&This->guid, &lpdiaf->rgoAction[i].guidInstance))
847 num_actions++;
849 if (num_actions == 0) return DI_NOEFFECT;
851 This->num_actions = num_actions;
853 /* Construct the dataformat and actionmap */
854 obj_df = HeapAlloc(GetProcessHeap(), 0, sizeof(DIOBJECTDATAFORMAT)*num_actions);
855 data_format.rgodf = (LPDIOBJECTDATAFORMAT)obj_df;
856 data_format.dwNumObjs = num_actions;
858 HeapFree(GetProcessHeap(), 0, This->action_map);
859 This->action_map = HeapAlloc(GetProcessHeap(), 0, sizeof(ActionMap)*num_actions);
861 for (i = 0; i < lpdiaf->dwNumActions; i++)
863 if (IsEqualGUID(&This->guid, &lpdiaf->rgoAction[i].guidInstance))
865 DWORD inst = DIDFT_GETINSTANCE(lpdiaf->rgoAction[i].dwObjID);
866 DWORD type = DIDFT_GETTYPE(lpdiaf->rgoAction[i].dwObjID);
867 LPDIOBJECTDATAFORMAT obj;
869 if (type == DIDFT_PSHBUTTON) type = DIDFT_BUTTON;
870 if (type == DIDFT_RELAXIS) type = DIDFT_AXIS;
872 obj = dataformat_to_odf_by_type(df, inst, type);
874 memcpy(&obj_df[action], obj, df->dwObjSize);
876 This->action_map[action].uAppData = lpdiaf->rgoAction[i].uAppData;
877 This->action_map[action].offset = offset;
878 obj_df[action].dwOfs = offset;
879 offset += (type & DIDFT_BUTTON) ? 1 : 4;
881 action++;
885 IDirectInputDevice8_SetDataFormat(iface, &data_format);
887 HeapFree(GetProcessHeap(), 0, obj_df);
889 /* Set the device properties according to the action format */
890 dpr.diph.dwSize = sizeof(DIPROPRANGE);
891 dpr.lMin = lpdiaf->lAxisMin;
892 dpr.lMax = lpdiaf->lAxisMax;
893 dpr.diph.dwHeaderSize = sizeof(DIPROPHEADER);
894 dpr.diph.dwHow = DIPH_DEVICE;
895 IDirectInputDevice8_SetProperty(iface, DIPROP_RANGE, &dpr.diph);
897 if (lpdiaf->dwBufferSize > 0)
899 dp.diph.dwSize = sizeof(DIPROPDWORD);
900 dp.dwData = lpdiaf->dwBufferSize;
901 dp.diph.dwHeaderSize = sizeof(DIPROPHEADER);
902 dp.diph.dwHow = DIPH_DEVICE;
903 IDirectInputDevice8_SetProperty(iface, DIPROP_BUFFERSIZE, &dp.diph);
906 /* Retrieve logged user name if necessary */
907 if (lpszUserName == NULL)
908 GetUserNameW(username, &username_size);
909 else
910 lstrcpynW(username, lpszUserName, MAX_PATH);
912 dps.diph.dwSize = sizeof(dps);
913 dps.diph.dwHeaderSize = sizeof(DIPROPHEADER);
914 dps.diph.dwObj = 0;
915 dps.diph.dwHow = DIPH_DEVICE;
916 if (dwFlags & DIDSAM_NOUSER)
917 dps.wsz[0] = '\0';
918 else
919 lstrcpynW(dps.wsz, username, ARRAY_SIZE(dps.wsz));
920 IDirectInputDevice8_SetProperty(iface, DIPROP_USERNAME, &dps.diph);
922 /* Save the settings to disk */
923 save_mapping_settings(iface, lpdiaf, username);
925 return DI_OK;
928 /******************************************************************************
929 * queue_event - add new event to the ring queue
932 void queue_event(LPDIRECTINPUTDEVICE8A iface, int inst_id, DWORD data, DWORD time, DWORD seq)
934 static ULONGLONG notify_ms = 0;
935 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
936 int next_pos, ofs = id_to_offset(&This->data_format, inst_id);
937 ULONGLONG time_ms = GetTickCount64();
939 /* Event is being set regardless of the queue state */
940 if (This->hEvent) SetEvent(This->hEvent);
942 if (time_ms - notify_ms > 1000)
944 PostMessageW(GetDesktopWindow(), WM_WINE_NOTIFY_ACTIVITY, 0, 0);
945 notify_ms = time_ms;
948 if (!This->queue_len || This->overflow || ofs < 0) return;
950 next_pos = (This->queue_head + 1) % This->queue_len;
951 if (next_pos == This->queue_tail)
953 TRACE(" queue overflowed\n");
954 This->overflow = TRUE;
955 return;
958 TRACE(" queueing %d at offset %d (queue head %d / size %d)\n",
959 data, ofs, This->queue_head, This->queue_len);
961 This->data_queue[This->queue_head].dwOfs = ofs;
962 This->data_queue[This->queue_head].dwData = data;
963 This->data_queue[This->queue_head].dwTimeStamp = time;
964 This->data_queue[This->queue_head].dwSequence = seq;
966 /* Set uAppData by means of action mapping */
967 if (This->num_actions > 0)
969 int i;
970 for (i=0; i < This->num_actions; i++)
972 if (This->action_map[i].offset == ofs)
974 TRACE("Offset %d mapped to uAppData %lu\n", ofs, This->action_map[i].uAppData);
975 This->data_queue[This->queue_head].uAppData = This->action_map[i].uAppData;
976 break;
981 This->queue_head = next_pos;
982 /* Send event if asked */
985 /******************************************************************************
986 * Acquire
989 HRESULT WINAPI IDirectInputDevice2WImpl_Acquire(LPDIRECTINPUTDEVICE8W iface)
991 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
992 HRESULT res;
994 TRACE("(%p)\n", This);
996 if (!This->data_format.user_df) return DIERR_INVALIDPARAM;
997 if (This->dwCoopLevel & DISCL_FOREGROUND && This->win != GetForegroundWindow())
998 return DIERR_OTHERAPPHASPRIO;
1000 EnterCriticalSection(&This->crit);
1001 res = This->acquired ? S_FALSE : DI_OK;
1002 This->acquired = 1;
1003 LeaveCriticalSection(&This->crit);
1004 if (res != DI_OK) return res;
1006 dinput_hooks_acquire_device(iface);
1007 check_dinput_hooks(iface, TRUE);
1009 return res;
1012 HRESULT WINAPI IDirectInputDevice2AImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
1014 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1015 return IDirectInputDevice2WImpl_Acquire(IDirectInputDevice8W_from_impl(This));
1019 /******************************************************************************
1020 * Unacquire
1023 HRESULT WINAPI IDirectInputDevice2WImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface)
1025 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1026 HRESULT res;
1028 TRACE("(%p)\n", This);
1030 EnterCriticalSection(&This->crit);
1031 res = !This->acquired ? DI_NOEFFECT : DI_OK;
1032 This->acquired = 0;
1033 LeaveCriticalSection(&This->crit);
1034 if (res != DI_OK) return res;
1036 dinput_hooks_unacquire_device(iface);
1037 check_dinput_hooks(iface, FALSE);
1039 return res;
1042 HRESULT WINAPI IDirectInputDevice2AImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
1044 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1045 return IDirectInputDevice2WImpl_Unacquire(IDirectInputDevice8W_from_impl(This));
1048 /******************************************************************************
1049 * IDirectInputDeviceA
1052 HRESULT WINAPI IDirectInputDevice2WImpl_SetDataFormat(LPDIRECTINPUTDEVICE8W iface, LPCDIDATAFORMAT df)
1054 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1055 HRESULT res = DI_OK;
1057 if (!df) return E_POINTER;
1058 TRACE("(%p) %p\n", This, df);
1059 _dump_DIDATAFORMAT(df);
1061 if (df->dwSize != sizeof(DIDATAFORMAT)) return DIERR_INVALIDPARAM;
1062 if (This->acquired) return DIERR_ACQUIRED;
1064 EnterCriticalSection(&This->crit);
1066 release_DataFormat(&This->data_format);
1067 res = create_DataFormat(df, &This->data_format);
1069 LeaveCriticalSection(&This->crit);
1070 return res;
1073 HRESULT WINAPI IDirectInputDevice2AImpl_SetDataFormat(LPDIRECTINPUTDEVICE8A iface, LPCDIDATAFORMAT df)
1075 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1076 return IDirectInputDevice2WImpl_SetDataFormat(IDirectInputDevice8W_from_impl(This), df);
1079 /******************************************************************************
1080 * SetCooperativeLevel
1082 * Set cooperative level and the source window for the events.
1084 HRESULT WINAPI IDirectInputDevice2WImpl_SetCooperativeLevel(LPDIRECTINPUTDEVICE8W iface, HWND hwnd, DWORD dwflags)
1086 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1088 TRACE("(%p) %p,0x%08x\n", This, hwnd, dwflags);
1089 _dump_cooperativelevel_DI(dwflags);
1091 if ((dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == 0 ||
1092 (dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE) ||
1093 (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == 0 ||
1094 (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == (DISCL_FOREGROUND | DISCL_BACKGROUND))
1095 return DIERR_INVALIDPARAM;
1097 if (hwnd && GetWindowLongW(hwnd, GWL_STYLE) & WS_CHILD) return E_HANDLE;
1099 if (!hwnd && dwflags == (DISCL_NONEXCLUSIVE | DISCL_BACKGROUND))
1100 hwnd = GetDesktopWindow();
1102 if (!IsWindow(hwnd)) return E_HANDLE;
1104 /* For security reasons native does not allow exclusive background level
1105 for mouse and keyboard only */
1106 if (dwflags & DISCL_EXCLUSIVE && dwflags & DISCL_BACKGROUND &&
1107 (IsEqualGUID(&This->guid, &GUID_SysMouse) ||
1108 IsEqualGUID(&This->guid, &GUID_SysKeyboard)))
1109 return DIERR_UNSUPPORTED;
1111 /* Store the window which asks for the mouse */
1112 EnterCriticalSection(&This->crit);
1113 This->win = hwnd;
1114 This->dwCoopLevel = dwflags;
1115 LeaveCriticalSection(&This->crit);
1117 return DI_OK;
1120 HRESULT WINAPI IDirectInputDevice2AImpl_SetCooperativeLevel(LPDIRECTINPUTDEVICE8A iface, HWND hwnd, DWORD dwflags)
1122 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1123 return IDirectInputDevice2WImpl_SetCooperativeLevel(IDirectInputDevice8W_from_impl(This), hwnd, dwflags);
1126 /******************************************************************************
1127 * SetEventNotification : specifies event to be sent on state change
1129 HRESULT WINAPI IDirectInputDevice2WImpl_SetEventNotification(LPDIRECTINPUTDEVICE8W iface, HANDLE event)
1131 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1133 TRACE("(%p) %p\n", This, event);
1135 EnterCriticalSection(&This->crit);
1136 This->hEvent = event;
1137 LeaveCriticalSection(&This->crit);
1138 return DI_OK;
1141 HRESULT WINAPI IDirectInputDevice2AImpl_SetEventNotification(LPDIRECTINPUTDEVICE8A iface, HANDLE event)
1143 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1144 return IDirectInputDevice2WImpl_SetEventNotification(IDirectInputDevice8W_from_impl(This), event);
1148 ULONG WINAPI IDirectInputDevice2WImpl_Release(LPDIRECTINPUTDEVICE8W iface)
1150 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1151 ULONG ref = InterlockedDecrement(&(This->ref));
1153 TRACE("(%p) ref %d\n", This, ref);
1155 if (ref) return ref;
1157 IDirectInputDevice_Unacquire(iface);
1158 /* Reset the FF state, free all effects, etc */
1159 IDirectInputDevice8_SendForceFeedbackCommand(iface, DISFFC_RESET);
1161 HeapFree(GetProcessHeap(), 0, This->data_queue);
1163 /* Free data format */
1164 HeapFree(GetProcessHeap(), 0, This->data_format.wine_df->rgodf);
1165 HeapFree(GetProcessHeap(), 0, This->data_format.wine_df);
1166 release_DataFormat(&This->data_format);
1168 /* Free action mapping */
1169 HeapFree(GetProcessHeap(), 0, This->action_map);
1171 IDirectInput_Release(&This->dinput->IDirectInput7A_iface);
1172 This->crit.DebugInfo->Spare[0] = 0;
1173 DeleteCriticalSection(&This->crit);
1175 HeapFree(GetProcessHeap(), 0, This);
1177 return ref;
1180 ULONG WINAPI IDirectInputDevice2AImpl_Release(LPDIRECTINPUTDEVICE8A iface)
1182 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1183 return IDirectInputDevice2WImpl_Release(IDirectInputDevice8W_from_impl(This));
1186 HRESULT WINAPI IDirectInputDevice2WImpl_QueryInterface(LPDIRECTINPUTDEVICE8W iface, REFIID riid, LPVOID *ppobj)
1188 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1190 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), ppobj);
1191 if (IsEqualGUID(&IID_IUnknown, riid) ||
1192 IsEqualGUID(&IID_IDirectInputDeviceA, riid) ||
1193 IsEqualGUID(&IID_IDirectInputDevice2A, riid) ||
1194 IsEqualGUID(&IID_IDirectInputDevice7A, riid) ||
1195 IsEqualGUID(&IID_IDirectInputDevice8A, riid))
1197 IDirectInputDevice2_AddRef(iface);
1198 *ppobj = IDirectInputDevice8A_from_impl(This);
1199 return DI_OK;
1201 if (IsEqualGUID(&IID_IDirectInputDeviceW, riid) ||
1202 IsEqualGUID(&IID_IDirectInputDevice2W, riid) ||
1203 IsEqualGUID(&IID_IDirectInputDevice7W, riid) ||
1204 IsEqualGUID(&IID_IDirectInputDevice8W, riid))
1206 IDirectInputDevice2_AddRef(iface);
1207 *ppobj = IDirectInputDevice8W_from_impl(This);
1208 return DI_OK;
1211 WARN("Unsupported interface!\n");
1212 return E_NOINTERFACE;
1215 HRESULT WINAPI IDirectInputDevice2AImpl_QueryInterface(LPDIRECTINPUTDEVICE8A iface, REFIID riid, LPVOID *ppobj)
1217 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1218 return IDirectInputDevice2WImpl_QueryInterface(IDirectInputDevice8W_from_impl(This), riid, ppobj);
1221 ULONG WINAPI IDirectInputDevice2WImpl_AddRef(LPDIRECTINPUTDEVICE8W iface)
1223 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1224 ULONG ref = InterlockedIncrement(&This->ref);
1225 TRACE( "(%p) ref %d\n", This, ref );
1226 return ref;
1229 ULONG WINAPI IDirectInputDevice2AImpl_AddRef(LPDIRECTINPUTDEVICE8A iface)
1231 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1232 return IDirectInputDevice2WImpl_AddRef(IDirectInputDevice8W_from_impl(This));
1235 HRESULT WINAPI IDirectInputDevice2AImpl_EnumObjects(LPDIRECTINPUTDEVICE8A iface,
1236 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback, LPVOID lpvRef, DWORD dwFlags)
1238 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1239 DIDEVICEOBJECTINSTANCEA ddoi;
1240 int i;
1242 TRACE("(%p)->(%p,%p flags:%08x)\n", This, lpCallback, lpvRef, dwFlags);
1243 TRACE(" - flags = ");
1244 _dump_EnumObjects_flags(dwFlags);
1245 TRACE("\n");
1247 /* Only the fields till dwFFMaxForce are relevant */
1248 memset(&ddoi, 0, sizeof(ddoi));
1249 ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce);
1251 for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++)
1253 LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(This->data_format.wine_df, i);
1255 if (dwFlags != DIDFT_ALL && !(dwFlags & DIDFT_GETTYPE(odf->dwType))) continue;
1256 if (IDirectInputDevice_GetObjectInfo(iface, &ddoi, odf->dwType, DIPH_BYID) != DI_OK)
1257 continue;
1259 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) break;
1262 return DI_OK;
1265 HRESULT WINAPI IDirectInputDevice2WImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface,
1266 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback, LPVOID lpvRef, DWORD dwFlags)
1268 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1269 DIDEVICEOBJECTINSTANCEW ddoi;
1270 int i;
1272 TRACE("(%p)->(%p,%p flags:%08x)\n", This, lpCallback, lpvRef, dwFlags);
1273 TRACE(" - flags = ");
1274 _dump_EnumObjects_flags(dwFlags);
1275 TRACE("\n");
1277 /* Only the fields till dwFFMaxForce are relevant */
1278 memset(&ddoi, 0, sizeof(ddoi));
1279 ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEW, dwFFMaxForce);
1281 for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++)
1283 LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(This->data_format.wine_df, i);
1285 if (dwFlags != DIDFT_ALL && !(dwFlags & DIDFT_GETTYPE(odf->dwType))) continue;
1286 if (IDirectInputDevice_GetObjectInfo(iface, &ddoi, odf->dwType, DIPH_BYID) != DI_OK)
1287 continue;
1289 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) break;
1292 return DI_OK;
1295 /******************************************************************************
1296 * GetProperty
1299 HRESULT WINAPI IDirectInputDevice2WImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface, REFGUID rguid, LPDIPROPHEADER pdiph)
1301 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1303 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(rguid), pdiph);
1304 _dump_DIPROPHEADER(pdiph);
1306 if (!IS_DIPROP(rguid)) return DI_OK;
1308 switch (LOWORD(rguid))
1310 case (DWORD_PTR) DIPROP_BUFFERSIZE:
1312 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
1314 if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
1316 pd->dwData = This->buffersize;
1317 TRACE("buffersize = %d\n", pd->dwData);
1318 break;
1320 case (DWORD_PTR) DIPROP_USERNAME:
1322 LPDIPROPSTRING ps = (LPDIPROPSTRING)pdiph;
1323 struct DevicePlayer *device_player;
1325 if (pdiph->dwSize != sizeof(DIPROPSTRING)) return DIERR_INVALIDPARAM;
1327 LIST_FOR_EACH_ENTRY(device_player, &This->dinput->device_players,
1328 struct DevicePlayer, entry)
1330 if (IsEqualGUID(&device_player->instance_guid, &This->guid))
1332 if (*device_player->username)
1334 lstrcpynW(ps->wsz, device_player->username, ARRAY_SIZE(ps->wsz));
1335 return DI_OK;
1337 else break;
1340 return S_FALSE;
1342 case (DWORD_PTR) DIPROP_VIDPID:
1343 FIXME("DIPROP_VIDPID not implemented\n");
1344 return DIERR_UNSUPPORTED;
1345 default:
1346 FIXME("Unknown property %s\n", debugstr_guid(rguid));
1347 return DIERR_INVALIDPARAM;
1350 return DI_OK;
1353 HRESULT WINAPI IDirectInputDevice2AImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPDIPROPHEADER pdiph)
1355 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1356 return IDirectInputDevice2WImpl_GetProperty(IDirectInputDevice8W_from_impl(This), rguid, pdiph);
1359 /******************************************************************************
1360 * SetProperty
1363 HRESULT WINAPI IDirectInputDevice2WImpl_SetProperty(
1364 LPDIRECTINPUTDEVICE8W iface, REFGUID rguid, LPCDIPROPHEADER pdiph)
1366 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1368 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(rguid), pdiph);
1369 _dump_DIPROPHEADER(pdiph);
1371 if (!IS_DIPROP(rguid)) return DI_OK;
1373 switch (LOWORD(rguid))
1375 case (DWORD_PTR) DIPROP_AXISMODE:
1377 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph;
1379 if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
1380 if (pdiph->dwHow == DIPH_DEVICE && pdiph->dwObj) return DIERR_INVALIDPARAM;
1381 if (This->acquired) return DIERR_ACQUIRED;
1382 if (pdiph->dwHow != DIPH_DEVICE) return DIERR_UNSUPPORTED;
1383 if (!This->data_format.user_df) return DI_OK;
1385 TRACE("Axis mode: %s\n", pd->dwData == DIPROPAXISMODE_ABS ? "absolute" :
1386 "relative");
1388 EnterCriticalSection(&This->crit);
1389 This->data_format.user_df->dwFlags &= ~DIDFT_AXIS;
1390 This->data_format.user_df->dwFlags |= pd->dwData == DIPROPAXISMODE_ABS ?
1391 DIDF_ABSAXIS : DIDF_RELAXIS;
1392 LeaveCriticalSection(&This->crit);
1393 break;
1395 case (DWORD_PTR) DIPROP_BUFFERSIZE:
1397 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph;
1399 if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
1400 if (This->acquired) return DIERR_ACQUIRED;
1402 TRACE("buffersize = %d\n", pd->dwData);
1404 EnterCriticalSection(&This->crit);
1406 This->buffersize = pd->dwData;
1407 This->queue_len = min(This->buffersize, 1024);
1408 HeapFree(GetProcessHeap(), 0, This->data_queue);
1410 This->data_queue = !This->queue_len ? NULL : HeapAlloc(GetProcessHeap(), 0,
1411 This->queue_len * sizeof(DIDEVICEOBJECTDATA));
1412 This->queue_head = This->queue_tail = This->overflow = 0;
1414 LeaveCriticalSection(&This->crit);
1415 break;
1417 case (DWORD_PTR) DIPROP_USERNAME:
1419 LPCDIPROPSTRING ps = (LPCDIPROPSTRING)pdiph;
1420 struct DevicePlayer *device_player;
1421 BOOL found = FALSE;
1423 if (pdiph->dwSize != sizeof(DIPROPSTRING)) return DIERR_INVALIDPARAM;
1425 LIST_FOR_EACH_ENTRY(device_player, &This->dinput->device_players,
1426 struct DevicePlayer, entry)
1428 if (IsEqualGUID(&device_player->instance_guid, &This->guid))
1430 found = TRUE;
1431 break;
1434 if (!found && (device_player =
1435 HeapAlloc(GetProcessHeap(), 0, sizeof(struct DevicePlayer))))
1437 list_add_tail(&This->dinput->device_players, &device_player->entry);
1438 device_player->instance_guid = This->guid;
1440 if (device_player)
1441 lstrcpynW(device_player->username, ps->wsz, ARRAY_SIZE(device_player->username));
1442 break;
1444 default:
1445 WARN("Unknown property %s\n", debugstr_guid(rguid));
1446 return DIERR_UNSUPPORTED;
1449 return DI_OK;
1452 HRESULT WINAPI IDirectInputDevice2AImpl_SetProperty(
1453 LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPCDIPROPHEADER pdiph)
1455 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1456 return IDirectInputDevice2WImpl_SetProperty(IDirectInputDevice8W_from_impl(This), rguid, pdiph);
1459 HRESULT WINAPI IDirectInputDevice2AImpl_GetObjectInfo(
1460 LPDIRECTINPUTDEVICE8A iface,
1461 LPDIDEVICEOBJECTINSTANCEA pdidoi,
1462 DWORD dwObj,
1463 DWORD dwHow)
1465 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1466 DIDEVICEOBJECTINSTANCEW didoiW;
1467 HRESULT res;
1469 if (!pdidoi ||
1470 (pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCEA) &&
1471 pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCE_DX3A)))
1472 return DIERR_INVALIDPARAM;
1474 didoiW.dwSize = sizeof(didoiW);
1475 res = IDirectInputDevice2WImpl_GetObjectInfo(IDirectInputDevice8W_from_impl(This), &didoiW, dwObj, dwHow);
1476 if (res == DI_OK)
1478 DWORD dwSize = pdidoi->dwSize;
1480 memset(pdidoi, 0, pdidoi->dwSize);
1481 pdidoi->dwSize = dwSize;
1482 pdidoi->guidType = didoiW.guidType;
1483 pdidoi->dwOfs = didoiW.dwOfs;
1484 pdidoi->dwType = didoiW.dwType;
1485 pdidoi->dwFlags = didoiW.dwFlags;
1488 return res;
1491 HRESULT WINAPI IDirectInputDevice2WImpl_GetObjectInfo(
1492 LPDIRECTINPUTDEVICE8W iface,
1493 LPDIDEVICEOBJECTINSTANCEW pdidoi,
1494 DWORD dwObj,
1495 DWORD dwHow)
1497 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1498 DWORD dwSize;
1499 LPDIOBJECTDATAFORMAT odf;
1500 int idx = -1;
1502 TRACE("(%p) %d(0x%08x) -> %p\n", This, dwHow, dwObj, pdidoi);
1504 if (!pdidoi ||
1505 (pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCEW) &&
1506 pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCE_DX3W)))
1507 return DIERR_INVALIDPARAM;
1509 switch (dwHow)
1511 case DIPH_BYOFFSET:
1512 if (!This->data_format.offsets) break;
1513 for (idx = This->data_format.wine_df->dwNumObjs - 1; idx >= 0; idx--)
1514 if (This->data_format.offsets[idx] == dwObj) break;
1515 break;
1516 case DIPH_BYID:
1517 dwObj &= 0x00ffffff;
1518 for (idx = This->data_format.wine_df->dwNumObjs - 1; idx >= 0; idx--)
1519 if ((dataformat_to_odf(This->data_format.wine_df, idx)->dwType & 0x00ffffff) == dwObj)
1520 break;
1521 break;
1523 case DIPH_BYUSAGE:
1524 FIXME("dwHow = DIPH_BYUSAGE not implemented\n");
1525 break;
1526 default:
1527 WARN("invalid parameter: dwHow = %08x\n", dwHow);
1528 return DIERR_INVALIDPARAM;
1530 if (idx < 0) return DIERR_OBJECTNOTFOUND;
1532 odf = dataformat_to_odf(This->data_format.wine_df, idx);
1533 dwSize = pdidoi->dwSize; /* save due to memset below */
1534 memset(pdidoi, 0, pdidoi->dwSize);
1535 pdidoi->dwSize = dwSize;
1536 if (odf->pguid) pdidoi->guidType = *odf->pguid;
1537 pdidoi->dwOfs = This->data_format.offsets ? This->data_format.offsets[idx] : odf->dwOfs;
1538 pdidoi->dwType = odf->dwType;
1539 pdidoi->dwFlags = odf->dwFlags;
1541 return DI_OK;
1544 HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceData(LPDIRECTINPUTDEVICE8W iface, DWORD dodsize,
1545 LPDIDEVICEOBJECTDATA dod, LPDWORD entries, DWORD flags)
1547 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1548 HRESULT ret = DI_OK;
1549 int len;
1551 TRACE("(%p) %p -> %p(%d) x%d, 0x%08x\n",
1552 This, dod, entries, entries ? *entries : 0, dodsize, flags);
1554 if (This->dinput->dwVersion == 0x0800 || dodsize == sizeof(DIDEVICEOBJECTDATA_DX3))
1556 if (!This->queue_len) return DIERR_NOTBUFFERED;
1557 if (!This->acquired) return DIERR_NOTACQUIRED;
1560 if (!This->queue_len)
1561 return DI_OK;
1562 if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3))
1563 return DIERR_INVALIDPARAM;
1565 IDirectInputDevice2_Poll(iface);
1566 EnterCriticalSection(&This->crit);
1568 len = This->queue_head - This->queue_tail;
1569 if (len < 0) len += This->queue_len;
1571 if ((*entries != INFINITE) && (len > *entries)) len = *entries;
1573 if (dod)
1575 int i;
1576 for (i = 0; i < len; i++)
1578 int n = (This->queue_tail + i) % This->queue_len;
1579 memcpy((char *)dod + dodsize * i, This->data_queue + n, dodsize);
1582 *entries = len;
1584 if (This->overflow && This->dinput->dwVersion == 0x0800)
1585 ret = DI_BUFFEROVERFLOW;
1587 if (!(flags & DIGDD_PEEK))
1589 /* Advance reading position */
1590 This->queue_tail = (This->queue_tail + len) % This->queue_len;
1591 This->overflow = FALSE;
1594 LeaveCriticalSection(&This->crit);
1596 TRACE("Returning %d events queued\n", *entries);
1597 return ret;
1600 HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface, DWORD dodsize,
1601 LPDIDEVICEOBJECTDATA dod, LPDWORD entries, DWORD flags)
1603 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1604 return IDirectInputDevice2WImpl_GetDeviceData(IDirectInputDevice8W_from_impl(This), dodsize, dod, entries, flags);
1607 HRESULT WINAPI IDirectInputDevice2WImpl_RunControlPanel(LPDIRECTINPUTDEVICE8W iface, HWND hwndOwner, DWORD dwFlags)
1609 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1610 FIXME("%p)->(%p,0x%08x): stub!\n", This, hwndOwner, dwFlags);
1612 return DI_OK;
1615 HRESULT WINAPI IDirectInputDevice2AImpl_RunControlPanel(LPDIRECTINPUTDEVICE8A iface, HWND hwndOwner, DWORD dwFlags)
1617 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1618 return IDirectInputDevice2WImpl_RunControlPanel(IDirectInputDevice8W_from_impl(This), hwndOwner, dwFlags);
1621 HRESULT WINAPI IDirectInputDevice2WImpl_Initialize(LPDIRECTINPUTDEVICE8W iface, HINSTANCE hinst, DWORD dwVersion,
1622 REFGUID rguid)
1624 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1625 FIXME("(%p)->(%p,%d,%s): stub!\n", This, hinst, dwVersion, debugstr_guid(rguid));
1626 return DI_OK;
1629 HRESULT WINAPI IDirectInputDevice2AImpl_Initialize(LPDIRECTINPUTDEVICE8A iface, HINSTANCE hinst, DWORD dwVersion,
1630 REFGUID rguid)
1632 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1633 return IDirectInputDevice2WImpl_Initialize(IDirectInputDevice8W_from_impl(This), hinst, dwVersion, rguid);
1636 /******************************************************************************
1637 * IDirectInputDevice2A
1640 HRESULT WINAPI IDirectInputDevice2WImpl_CreateEffect(LPDIRECTINPUTDEVICE8W iface, REFGUID rguid, LPCDIEFFECT lpeff,
1641 LPDIRECTINPUTEFFECT *ppdef, LPUNKNOWN pUnkOuter)
1643 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1644 FIXME("(%p)->(%s,%p,%p,%p): stub!\n", This, debugstr_guid(rguid), lpeff, ppdef, pUnkOuter);
1646 FIXME("not available in the generic implementation\n");
1647 *ppdef = NULL;
1648 return DIERR_UNSUPPORTED;
1651 HRESULT WINAPI IDirectInputDevice2AImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPCDIEFFECT lpeff,
1652 LPDIRECTINPUTEFFECT *ppdef, LPUNKNOWN pUnkOuter)
1654 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1655 return IDirectInputDevice2WImpl_CreateEffect(IDirectInputDevice8W_from_impl(This), rguid, lpeff, ppdef, pUnkOuter);
1658 HRESULT WINAPI IDirectInputDevice2AImpl_EnumEffects(
1659 LPDIRECTINPUTDEVICE8A iface,
1660 LPDIENUMEFFECTSCALLBACKA lpCallback,
1661 LPVOID lpvRef,
1662 DWORD dwFlags)
1664 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1665 FIXME("%p)->(%p,%p,0x%08x): stub!\n", This, lpCallback, lpvRef, dwFlags);
1667 return DI_OK;
1670 HRESULT WINAPI IDirectInputDevice2WImpl_EnumEffects(
1671 LPDIRECTINPUTDEVICE8W iface,
1672 LPDIENUMEFFECTSCALLBACKW lpCallback,
1673 LPVOID lpvRef,
1674 DWORD dwFlags)
1676 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1677 FIXME("(%p)->(%p,%p,0x%08x): stub!\n", This, lpCallback, lpvRef, dwFlags);
1679 return DI_OK;
1682 HRESULT WINAPI IDirectInputDevice2AImpl_GetEffectInfo(
1683 LPDIRECTINPUTDEVICE8A iface,
1684 LPDIEFFECTINFOA lpdei,
1685 REFGUID rguid)
1687 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1688 FIXME("(%p)->(%p,%s): stub!\n", This, lpdei, debugstr_guid(rguid));
1689 return DI_OK;
1692 HRESULT WINAPI IDirectInputDevice2WImpl_GetEffectInfo(
1693 LPDIRECTINPUTDEVICE8W iface,
1694 LPDIEFFECTINFOW lpdei,
1695 REFGUID rguid)
1697 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1698 FIXME("(%p)->(%p,%s): stub!\n", This, lpdei, debugstr_guid(rguid));
1699 return DI_OK;
1702 HRESULT WINAPI IDirectInputDevice2WImpl_GetForceFeedbackState(LPDIRECTINPUTDEVICE8W iface, LPDWORD pdwOut)
1704 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1705 FIXME("(%p)->(%p): stub!\n", This, pdwOut);
1706 return DI_OK;
1709 HRESULT WINAPI IDirectInputDevice2AImpl_GetForceFeedbackState(LPDIRECTINPUTDEVICE8A iface, LPDWORD pdwOut)
1711 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1712 return IDirectInputDevice2WImpl_GetForceFeedbackState(IDirectInputDevice8W_from_impl(This), pdwOut);
1715 HRESULT WINAPI IDirectInputDevice2WImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8W iface, DWORD dwFlags)
1717 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1718 TRACE("(%p)->(0x%08x)\n", This, dwFlags);
1719 return DI_NOEFFECT;
1722 HRESULT WINAPI IDirectInputDevice2AImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8A iface, DWORD dwFlags)
1724 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1725 return IDirectInputDevice2WImpl_SendForceFeedbackCommand(IDirectInputDevice8W_from_impl(This), dwFlags);
1728 HRESULT WINAPI IDirectInputDevice2WImpl_EnumCreatedEffectObjects(LPDIRECTINPUTDEVICE8W iface,
1729 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback, LPVOID lpvRef, DWORD dwFlags)
1731 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1732 FIXME("(%p)0>(%p,%p,0x%08x): stub!\n", This, lpCallback, lpvRef, dwFlags);
1733 return DI_OK;
1736 HRESULT WINAPI IDirectInputDevice2AImpl_EnumCreatedEffectObjects(LPDIRECTINPUTDEVICE8A iface,
1737 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback, LPVOID lpvRef, DWORD dwFlags)
1739 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1740 return IDirectInputDevice2WImpl_EnumCreatedEffectObjects(IDirectInputDevice8W_from_impl(This), lpCallback, lpvRef, dwFlags);
1743 HRESULT WINAPI IDirectInputDevice2WImpl_Escape(LPDIRECTINPUTDEVICE8W iface, LPDIEFFESCAPE lpDIEEsc)
1745 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1746 FIXME("(%p)->(%p): stub!\n", This, lpDIEEsc);
1747 return DI_OK;
1750 HRESULT WINAPI IDirectInputDevice2AImpl_Escape(LPDIRECTINPUTDEVICE8A iface, LPDIEFFESCAPE lpDIEEsc)
1752 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1753 return IDirectInputDevice2WImpl_Escape(IDirectInputDevice8W_from_impl(This), lpDIEEsc);
1756 HRESULT WINAPI IDirectInputDevice2WImpl_Poll(LPDIRECTINPUTDEVICE8W iface)
1758 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1760 if (!This->acquired) return DIERR_NOTACQUIRED;
1762 check_dinput_events();
1763 return DI_OK;
1766 HRESULT WINAPI IDirectInputDevice2AImpl_Poll(LPDIRECTINPUTDEVICE8A iface)
1768 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1769 return IDirectInputDevice2WImpl_Poll(IDirectInputDevice8W_from_impl(This));
1772 HRESULT WINAPI IDirectInputDevice2WImpl_SendDeviceData(LPDIRECTINPUTDEVICE8W iface, DWORD cbObjectData,
1773 LPCDIDEVICEOBJECTDATA rgdod, LPDWORD pdwInOut,
1774 DWORD dwFlags)
1776 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1777 FIXME("(%p)->(0x%08x,%p,%p,0x%08x): stub!\n", This, cbObjectData, rgdod, pdwInOut, dwFlags);
1779 return DI_OK;
1782 HRESULT WINAPI IDirectInputDevice2AImpl_SendDeviceData(LPDIRECTINPUTDEVICE8A iface, DWORD cbObjectData,
1783 LPCDIDEVICEOBJECTDATA rgdod, LPDWORD pdwInOut,
1784 DWORD dwFlags)
1786 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1787 return IDirectInputDevice2WImpl_SendDeviceData(IDirectInputDevice8W_from_impl(This), cbObjectData, rgdod,
1788 pdwInOut, dwFlags);
1791 HRESULT WINAPI IDirectInputDevice7AImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8A iface,
1792 LPCSTR lpszFileName,
1793 LPDIENUMEFFECTSINFILECALLBACK pec,
1794 LPVOID pvRef,
1795 DWORD dwFlags)
1797 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1798 FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", This, lpszFileName, pec, pvRef, dwFlags);
1800 return DI_OK;
1803 HRESULT WINAPI IDirectInputDevice7WImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8W iface,
1804 LPCWSTR lpszFileName,
1805 LPDIENUMEFFECTSINFILECALLBACK pec,
1806 LPVOID pvRef,
1807 DWORD dwFlags)
1809 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1810 FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", This, debugstr_w(lpszFileName), pec, pvRef, dwFlags);
1812 return DI_OK;
1815 HRESULT WINAPI IDirectInputDevice7AImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8A iface,
1816 LPCSTR lpszFileName,
1817 DWORD dwEntries,
1818 LPDIFILEEFFECT rgDiFileEft,
1819 DWORD dwFlags)
1821 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1822 FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", This, lpszFileName, dwEntries, rgDiFileEft, dwFlags);
1824 return DI_OK;
1827 HRESULT WINAPI IDirectInputDevice7WImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8W iface,
1828 LPCWSTR lpszFileName,
1829 DWORD dwEntries,
1830 LPDIFILEEFFECT rgDiFileEft,
1831 DWORD dwFlags)
1833 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1834 FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", This, debugstr_w(lpszFileName), dwEntries, rgDiFileEft, dwFlags);
1836 return DI_OK;
1839 HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface,
1840 LPDIACTIONFORMATW lpdiaf,
1841 LPCWSTR lpszUserName,
1842 DWORD dwFlags)
1844 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1845 FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", This, lpdiaf, debugstr_w(lpszUserName), dwFlags);
1846 #define X(x) if (dwFlags & x) FIXME("\tdwFlags =|"#x"\n");
1847 X(DIDBAM_DEFAULT)
1848 X(DIDBAM_PRESERVE)
1849 X(DIDBAM_INITIALIZE)
1850 X(DIDBAM_HWDEFAULTS)
1851 #undef X
1853 return DI_OK;
1856 HRESULT WINAPI IDirectInputDevice8AImpl_GetImageInfo(LPDIRECTINPUTDEVICE8A iface,
1857 LPDIDEVICEIMAGEINFOHEADERA lpdiDevImageInfoHeader)
1859 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1860 FIXME("(%p)->(%p): stub !\n", This, lpdiDevImageInfoHeader);
1862 return DI_OK;
1865 HRESULT WINAPI IDirectInputDevice8WImpl_GetImageInfo(LPDIRECTINPUTDEVICE8W iface,
1866 LPDIDEVICEIMAGEINFOHEADERW lpdiDevImageInfoHeader)
1868 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1869 FIXME("(%p)->(%p): stub !\n", This, lpdiDevImageInfoHeader);
1871 return DI_OK;