[DINPUT]
[reactos.git] / reactos / dll / directx / wine / dinput / device.c
1 /* DirectInput Device
2 *
3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998,1999 Lionel Ulmer
5 *
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 /* This file contains all the Device specific functions that can be used as stubs
23 by real device implementations.
24
25 It also contains all the helper functions.
26 */
27
28 #include "dinput_private.h"
29
30 static inline IDirectInputDeviceImpl *impl_from_IDirectInputDevice8A(IDirectInputDevice8A *iface)
31 {
32 return CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8A_iface);
33 }
34 static inline IDirectInputDeviceImpl *impl_from_IDirectInputDevice8W(IDirectInputDevice8W *iface)
35 {
36 return CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8W_iface);
37 }
38
39 static inline IDirectInputDevice8A *IDirectInputDevice8A_from_impl(IDirectInputDeviceImpl *This)
40 {
41 return &This->IDirectInputDevice8A_iface;
42 }
43 static inline IDirectInputDevice8W *IDirectInputDevice8W_from_impl(IDirectInputDeviceImpl *This)
44 {
45 return &This->IDirectInputDevice8W_iface;
46 }
47
48 /******************************************************************************
49 * Various debugging tools
50 */
51 static void _dump_cooperativelevel_DI(DWORD dwFlags) {
52 if (TRACE_ON(dinput)) {
53 unsigned int i;
54 static const struct {
55 DWORD mask;
56 const char *name;
57 } flags[] = {
58 #define FE(x) { x, #x}
59 FE(DISCL_BACKGROUND),
60 FE(DISCL_EXCLUSIVE),
61 FE(DISCL_FOREGROUND),
62 FE(DISCL_NONEXCLUSIVE),
63 FE(DISCL_NOWINKEY)
64 #undef FE
65 };
66 TRACE(" cooperative level : ");
67 for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++)
68 if (flags[i].mask & dwFlags)
69 TRACE("%s ",flags[i].name);
70 TRACE("\n");
71 }
72 }
73
74 static void _dump_EnumObjects_flags(DWORD dwFlags) {
75 if (TRACE_ON(dinput)) {
76 unsigned int i;
77 DWORD type, instance;
78 static const struct {
79 DWORD mask;
80 const char *name;
81 } flags[] = {
82 #define FE(x) { x, #x}
83 FE(DIDFT_RELAXIS),
84 FE(DIDFT_ABSAXIS),
85 FE(DIDFT_PSHBUTTON),
86 FE(DIDFT_TGLBUTTON),
87 FE(DIDFT_POV),
88 FE(DIDFT_COLLECTION),
89 FE(DIDFT_NODATA),
90 FE(DIDFT_FFACTUATOR),
91 FE(DIDFT_FFEFFECTTRIGGER),
92 FE(DIDFT_OUTPUT),
93 FE(DIDFT_VENDORDEFINED),
94 FE(DIDFT_ALIAS),
95 FE(DIDFT_OPTIONAL)
96 #undef FE
97 };
98 type = (dwFlags & 0xFF0000FF);
99 instance = ((dwFlags >> 8) & 0xFFFF);
100 TRACE("Type:");
101 if (type == DIDFT_ALL) {
102 TRACE(" DIDFT_ALL");
103 } else {
104 for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++) {
105 if (flags[i].mask & type) {
106 type &= ~flags[i].mask;
107 TRACE(" %s",flags[i].name);
108 }
109 }
110 if (type) {
111 TRACE(" (unhandled: %08x)", type);
112 }
113 }
114 TRACE(" / Instance: ");
115 if (instance == ((DIDFT_ANYINSTANCE >> 8) & 0xFFFF)) {
116 TRACE("DIDFT_ANYINSTANCE");
117 } else {
118 TRACE("%3d", instance);
119 }
120 }
121 }
122
123 void _dump_DIPROPHEADER(LPCDIPROPHEADER diph) {
124 if (TRACE_ON(dinput)) {
125 TRACE(" - dwObj = 0x%08x\n", diph->dwObj);
126 TRACE(" - dwHow = %s\n",
127 ((diph->dwHow == DIPH_DEVICE) ? "DIPH_DEVICE" :
128 ((diph->dwHow == DIPH_BYOFFSET) ? "DIPH_BYOFFSET" :
129 ((diph->dwHow == DIPH_BYID)) ? "DIPH_BYID" : "unknown")));
130 }
131 }
132
133 void _dump_OBJECTINSTANCEA(const DIDEVICEOBJECTINSTANCEA *ddoi) {
134 TRACE(" - enumerating : %s ('%s') - %2d - 0x%08x - %s - 0x%x\n",
135 debugstr_guid(&ddoi->guidType), _dump_dinput_GUID(&ddoi->guidType), ddoi->dwOfs, ddoi->dwType, ddoi->tszName, ddoi->dwFlags);
136 }
137
138 void _dump_OBJECTINSTANCEW(const DIDEVICEOBJECTINSTANCEW *ddoi) {
139 TRACE(" - enumerating : %s ('%s'), - %2d - 0x%08x - %s - 0x%x\n",
140 debugstr_guid(&ddoi->guidType), _dump_dinput_GUID(&ddoi->guidType), ddoi->dwOfs, ddoi->dwType, debugstr_w(ddoi->tszName), ddoi->dwFlags);
141 }
142
143 /* This function is a helper to convert a GUID into any possible DInput GUID out there */
144 const char *_dump_dinput_GUID(const GUID *guid) {
145 unsigned int i;
146 static const struct {
147 const GUID *guid;
148 const char *name;
149 } guids[] = {
150 #define FE(x) { &x, #x}
151 FE(GUID_XAxis),
152 FE(GUID_YAxis),
153 FE(GUID_ZAxis),
154 FE(GUID_RxAxis),
155 FE(GUID_RyAxis),
156 FE(GUID_RzAxis),
157 FE(GUID_Slider),
158 FE(GUID_Button),
159 FE(GUID_Key),
160 FE(GUID_POV),
161 FE(GUID_Unknown),
162 FE(GUID_SysMouse),
163 FE(GUID_SysKeyboard),
164 FE(GUID_Joystick),
165 FE(GUID_ConstantForce),
166 FE(GUID_RampForce),
167 FE(GUID_Square),
168 FE(GUID_Sine),
169 FE(GUID_Triangle),
170 FE(GUID_SawtoothUp),
171 FE(GUID_SawtoothDown),
172 FE(GUID_Spring),
173 FE(GUID_Damper),
174 FE(GUID_Inertia),
175 FE(GUID_Friction),
176 FE(GUID_CustomForce)
177 #undef FE
178 };
179 if (guid == NULL)
180 return "null GUID";
181 for (i = 0; i < (sizeof(guids) / sizeof(guids[0])); i++) {
182 if (IsEqualGUID(guids[i].guid, guid)) {
183 return guids[i].name;
184 }
185 }
186 return debugstr_guid(guid);
187 }
188
189 void _dump_DIDATAFORMAT(const DIDATAFORMAT *df) {
190 unsigned int i;
191
192 TRACE("Dumping DIDATAFORMAT structure:\n");
193 TRACE(" - dwSize: %d\n", df->dwSize);
194 if (df->dwSize != sizeof(DIDATAFORMAT)) {
195 WARN("Non-standard DIDATAFORMAT structure size %d\n", df->dwSize);
196 }
197 TRACE(" - dwObjsize: %d\n", df->dwObjSize);
198 if (df->dwObjSize != sizeof(DIOBJECTDATAFORMAT)) {
199 WARN("Non-standard DIOBJECTDATAFORMAT structure size %d\n", df->dwObjSize);
200 }
201 TRACE(" - dwFlags: 0x%08x (", df->dwFlags);
202 switch (df->dwFlags) {
203 case DIDF_ABSAXIS: TRACE("DIDF_ABSAXIS"); break;
204 case DIDF_RELAXIS: TRACE("DIDF_RELAXIS"); break;
205 default: TRACE("unknown"); break;
206 }
207 TRACE(")\n");
208 TRACE(" - dwDataSize: %d\n", df->dwDataSize);
209 TRACE(" - dwNumObjs: %d\n", df->dwNumObjs);
210
211 for (i = 0; i < df->dwNumObjs; i++) {
212 TRACE(" - Object %d:\n", i);
213 TRACE(" * GUID: %s ('%s')\n", debugstr_guid(df->rgodf[i].pguid), _dump_dinput_GUID(df->rgodf[i].pguid));
214 TRACE(" * dwOfs: %d\n", df->rgodf[i].dwOfs);
215 TRACE(" * dwType: 0x%08x\n", df->rgodf[i].dwType);
216 TRACE(" "); _dump_EnumObjects_flags(df->rgodf[i].dwType); TRACE("\n");
217 TRACE(" * dwFlags: 0x%08x\n", df->rgodf[i].dwFlags);
218 }
219 }
220
221 /******************************************************************************
222 * Get the default and the app-specific config keys.
223 */
224 BOOL get_app_key(HKEY *defkey, HKEY *appkey)
225 {
226 char buffer[MAX_PATH+16];
227 DWORD len;
228
229 *appkey = 0;
230
231 /* @@ Wine registry key: HKCU\Software\Wine\DirectInput */
232 if (RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\DirectInput", defkey))
233 *defkey = 0;
234
235 len = GetModuleFileNameA(0, buffer, MAX_PATH);
236 if (len && len < MAX_PATH)
237 {
238 HKEY tmpkey;
239
240 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DirectInput */
241 if (!RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey))
242 {
243 char *p, *appname = buffer;
244 if ((p = strrchr(appname, '/'))) appname = p + 1;
245 if ((p = strrchr(appname, '\\'))) appname = p + 1;
246 strcat(appname, "\\DirectInput");
247
248 if (RegOpenKeyA(tmpkey, appname, appkey)) *appkey = 0;
249 RegCloseKey(tmpkey);
250 }
251 }
252
253 return *defkey || *appkey;
254 }
255
256 /******************************************************************************
257 * Get a config key from either the app-specific or the default config
258 */
259 DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
260 char *buffer, DWORD size )
261 {
262 if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE)buffer, &size ))
263 return 0;
264
265 if (defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE)buffer, &size ))
266 return 0;
267
268 return ERROR_FILE_NOT_FOUND;
269 }
270
271 /* Conversion between internal data buffer and external data buffer */
272 void fill_DataFormat(void *out, DWORD size, const void *in, const DataFormat *df)
273 {
274 int i;
275 const char *in_c = in;
276 char *out_c = out;
277
278 memset(out, 0, size);
279 if (df->dt == NULL) {
280 /* This means that the app uses Wine's internal data format */
281 memcpy(out, in, min(size, df->internal_format_size));
282 } else {
283 for (i = 0; i < df->size; i++) {
284 if (df->dt[i].offset_in >= 0) {
285 switch (df->dt[i].size) {
286 case 1:
287 TRACE("Copying (c) to %d from %d (value %d)\n",
288 df->dt[i].offset_out, df->dt[i].offset_in, *(in_c + df->dt[i].offset_in));
289 *(out_c + df->dt[i].offset_out) = *(in_c + df->dt[i].offset_in);
290 break;
291
292 case 2:
293 TRACE("Copying (s) to %d from %d (value %d)\n",
294 df->dt[i].offset_out, df->dt[i].offset_in, *((const short *)(in_c + df->dt[i].offset_in)));
295 *((short *)(out_c + df->dt[i].offset_out)) = *((const short *)(in_c + df->dt[i].offset_in));
296 break;
297
298 case 4:
299 TRACE("Copying (i) to %d from %d (value %d)\n",
300 df->dt[i].offset_out, df->dt[i].offset_in, *((const int *)(in_c + df->dt[i].offset_in)));
301 *((int *)(out_c + df->dt[i].offset_out)) = *((const int *)(in_c + df->dt[i].offset_in));
302 break;
303
304 default:
305 memcpy((out_c + df->dt[i].offset_out), (in_c + df->dt[i].offset_in), df->dt[i].size);
306 break;
307 }
308 } else {
309 switch (df->dt[i].size) {
310 case 1:
311 TRACE("Copying (c) to %d default value %d\n",
312 df->dt[i].offset_out, df->dt[i].value);
313 *(out_c + df->dt[i].offset_out) = (char) df->dt[i].value;
314 break;
315
316 case 2:
317 TRACE("Copying (s) to %d default value %d\n",
318 df->dt[i].offset_out, df->dt[i].value);
319 *((short *) (out_c + df->dt[i].offset_out)) = (short) df->dt[i].value;
320 break;
321
322 case 4:
323 TRACE("Copying (i) to %d default value %d\n",
324 df->dt[i].offset_out, df->dt[i].value);
325 *((int *) (out_c + df->dt[i].offset_out)) = df->dt[i].value;
326 break;
327
328 default:
329 memset((out_c + df->dt[i].offset_out), 0, df->dt[i].size);
330 break;
331 }
332 }
333 }
334 }
335 }
336
337 void release_DataFormat(DataFormat * format)
338 {
339 TRACE("Deleting DataFormat: %p\n", format);
340
341 HeapFree(GetProcessHeap(), 0, format->dt);
342 format->dt = NULL;
343 HeapFree(GetProcessHeap(), 0, format->offsets);
344 format->offsets = NULL;
345 HeapFree(GetProcessHeap(), 0, format->user_df);
346 format->user_df = NULL;
347 }
348
349 static inline LPDIOBJECTDATAFORMAT dataformat_to_odf(LPCDIDATAFORMAT df, int idx)
350 {
351 if (idx < 0 || idx >= df->dwNumObjs) return NULL;
352 return (LPDIOBJECTDATAFORMAT)((LPBYTE)df->rgodf + idx * df->dwObjSize);
353 }
354
355 /* dataformat_to_odf_by_type
356 * Find the Nth object of the selected type in the DataFormat
357 */
358 LPDIOBJECTDATAFORMAT dataformat_to_odf_by_type(LPCDIDATAFORMAT df, int n, DWORD type)
359 {
360 int i, nfound = 0;
361
362 for (i=0; i < df->dwNumObjs; i++)
363 {
364 LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(df, i);
365
366 if (odf->dwType & type)
367 {
368 if (n == nfound)
369 return odf;
370
371 nfound++;
372 }
373 }
374
375 return NULL;
376 }
377
378 static HRESULT create_DataFormat(LPCDIDATAFORMAT asked_format, DataFormat *format)
379 {
380 DataTransform *dt;
381 unsigned int i, j;
382 int same = 1;
383 int *done;
384 int index = 0;
385 DWORD next = 0;
386
387 if (!format->wine_df) return DIERR_INVALIDPARAM;
388 done = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, asked_format->dwNumObjs * sizeof(int));
389 dt = HeapAlloc(GetProcessHeap(), 0, asked_format->dwNumObjs * sizeof(DataTransform));
390 if (!dt || !done) goto failed;
391
392 if (!(format->offsets = HeapAlloc(GetProcessHeap(), 0, format->wine_df->dwNumObjs * sizeof(int))))
393 goto failed;
394
395 if (!(format->user_df = HeapAlloc(GetProcessHeap(), 0, asked_format->dwSize)))
396 goto failed;
397 memcpy(format->user_df, asked_format, asked_format->dwSize);
398
399 TRACE("Creating DataTransform :\n");
400
401 for (i = 0; i < format->wine_df->dwNumObjs; i++)
402 {
403 format->offsets[i] = -1;
404
405 for (j = 0; j < asked_format->dwNumObjs; j++) {
406 if (done[j] == 1)
407 continue;
408
409 if (/* Check if the application either requests any GUID and if not, it if matches
410 * the GUID of the Wine object.
411 */
412 ((asked_format->rgodf[j].pguid == NULL) ||
413 (format->wine_df->rgodf[i].pguid == NULL) ||
414 (IsEqualGUID(format->wine_df->rgodf[i].pguid, asked_format->rgodf[j].pguid)))
415 &&
416 (/* Then check if it accepts any instance id, and if not, if it matches Wine's
417 * instance id.
418 */
419 ((asked_format->rgodf[j].dwType & DIDFT_INSTANCEMASK) == DIDFT_ANYINSTANCE) ||
420 (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == 0x00FF) || /* This is mentioned in no DX docs, but it works fine - tested on WinXP */
421 (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == DIDFT_GETINSTANCE(format->wine_df->rgodf[i].dwType)))
422 &&
423 ( /* Then if the asked type matches the one Wine provides */
424 DIDFT_GETTYPE(asked_format->rgodf[j].dwType) & format->wine_df->rgodf[i].dwType))
425 {
426 done[j] = 1;
427
428 TRACE("Matching :\n");
429 TRACE(" - Asked (%d) :\n", j);
430 TRACE(" * GUID: %s ('%s')\n",
431 debugstr_guid(asked_format->rgodf[j].pguid),
432 _dump_dinput_GUID(asked_format->rgodf[j].pguid));
433 TRACE(" * Offset: %3d\n", asked_format->rgodf[j].dwOfs);
434 TRACE(" * dwType: %08x\n", asked_format->rgodf[j].dwType);
435 TRACE(" "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
436
437 TRACE(" - Wine (%d) :\n", i);
438 TRACE(" * GUID: %s ('%s')\n",
439 debugstr_guid(format->wine_df->rgodf[i].pguid),
440 _dump_dinput_GUID(format->wine_df->rgodf[i].pguid));
441 TRACE(" * Offset: %3d\n", format->wine_df->rgodf[i].dwOfs);
442 TRACE(" * dwType: %08x\n", format->wine_df->rgodf[i].dwType);
443 TRACE(" "); _dump_EnumObjects_flags(format->wine_df->rgodf[i].dwType); TRACE("\n");
444
445 if (format->wine_df->rgodf[i].dwType & DIDFT_BUTTON)
446 dt[index].size = sizeof(BYTE);
447 else
448 dt[index].size = sizeof(DWORD);
449 dt[index].offset_in = format->wine_df->rgodf[i].dwOfs;
450 dt[index].offset_out = asked_format->rgodf[j].dwOfs;
451 format->offsets[i] = asked_format->rgodf[j].dwOfs;
452 dt[index].value = 0;
453 next = next + dt[index].size;
454
455 if (format->wine_df->rgodf[i].dwOfs != dt[index].offset_out)
456 same = 0;
457
458 index++;
459 break;
460 }
461 }
462 }
463
464 TRACE("Setting to default value :\n");
465 for (j = 0; j < asked_format->dwNumObjs; j++) {
466 if (done[j] == 0) {
467 TRACE(" - Asked (%d) :\n", j);
468 TRACE(" * GUID: %s ('%s')\n",
469 debugstr_guid(asked_format->rgodf[j].pguid),
470 _dump_dinput_GUID(asked_format->rgodf[j].pguid));
471 TRACE(" * Offset: %3d\n", asked_format->rgodf[j].dwOfs);
472 TRACE(" * dwType: %08x\n", asked_format->rgodf[j].dwType);
473 TRACE(" "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
474
475 if (asked_format->rgodf[j].dwType & DIDFT_BUTTON)
476 dt[index].size = sizeof(BYTE);
477 else
478 dt[index].size = sizeof(DWORD);
479 dt[index].offset_in = -1;
480 dt[index].offset_out = asked_format->rgodf[j].dwOfs;
481 if (asked_format->rgodf[j].dwType & DIDFT_POV)
482 dt[index].value = -1;
483 else
484 dt[index].value = 0;
485 index++;
486
487 same = 0;
488 }
489 }
490
491 format->internal_format_size = format->wine_df->dwDataSize;
492 format->size = index;
493 if (same) {
494 HeapFree(GetProcessHeap(), 0, dt);
495 dt = NULL;
496 }
497 format->dt = dt;
498
499 HeapFree(GetProcessHeap(), 0, done);
500
501 return DI_OK;
502
503 failed:
504 HeapFree(GetProcessHeap(), 0, done);
505 HeapFree(GetProcessHeap(), 0, dt);
506 format->dt = NULL;
507 HeapFree(GetProcessHeap(), 0, format->offsets);
508 format->offsets = NULL;
509 HeapFree(GetProcessHeap(), 0, format->user_df);
510 format->user_df = NULL;
511
512 return DIERR_OUTOFMEMORY;
513 }
514
515 /* find an object by it's offset in a data format */
516 static int offset_to_object(const DataFormat *df, int offset)
517 {
518 int i;
519
520 if (!df->offsets) return -1;
521
522 for (i = 0; i < df->wine_df->dwNumObjs; i++)
523 if (df->offsets[i] == offset) return i;
524
525 return -1;
526 }
527
528 int id_to_object(LPCDIDATAFORMAT df, int id)
529 {
530 int i;
531
532 id &= 0x00ffffff;
533 for (i = 0; i < df->dwNumObjs; i++)
534 if ((dataformat_to_odf(df, i)->dwType & 0x00ffffff) == id)
535 return i;
536
537 return -1;
538 }
539
540 static int id_to_offset(const DataFormat *df, int id)
541 {
542 int obj = id_to_object(df->wine_df, id);
543
544 return obj >= 0 && df->offsets ? df->offsets[obj] : -1;
545 }
546
547 int find_property(const DataFormat *df, LPCDIPROPHEADER ph)
548 {
549 switch (ph->dwHow)
550 {
551 case DIPH_BYID: return id_to_object(df->wine_df, ph->dwObj);
552 case DIPH_BYOFFSET: return offset_to_object(df, ph->dwObj);
553 }
554 FIXME("Unhandled ph->dwHow=='%04X'\n", (unsigned int)ph->dwHow);
555
556 return -1;
557 }
558
559 static DWORD semantic_to_obj_id(IDirectInputDeviceImpl* This, DWORD dwSemantic)
560 {
561 DWORD type = (0x0000ff00 & dwSemantic) >> 8;
562 DWORD offset = 0x000000ff & dwSemantic;
563 DWORD obj_instance = 0;
564 DWORD found = 0;
565 int i;
566
567 for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++)
568 {
569 LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(This->data_format.wine_df, i);
570
571 if (odf->dwOfs == offset)
572 {
573 obj_instance = DIDFT_GETINSTANCE(odf->dwType);
574 found = 1;
575 break;
576 }
577 }
578
579 if (!found) return 0;
580
581 if (type & DIDFT_AXIS) type = DIDFT_RELAXIS;
582 if (type & DIDFT_BUTTON) type = DIDFT_PSHBUTTON;
583
584 return type | (0x0000ff00 & (obj_instance << 8));
585 }
586
587 /*
588 * get_mapping_key
589 * Retrieves an open registry key to save the mapping, parametrized for an username,
590 * specific device and specific action mapping guid.
591 */
592 static HKEY get_mapping_key(const WCHAR *device, const WCHAR *username, const WCHAR *guid)
593 {
594 static const WCHAR subkey[] = {
595 'S','o','f','t','w','a','r','e','\\',
596 'W','i','n','e','\\',
597 'D','i','r','e','c','t','I','n','p','u','t','\\',
598 'M','a','p','p','i','n','g','s','\\','%','s','\\','%','s','\\','%','s','\0'};
599 HKEY hkey;
600 WCHAR *keyname;
601
602 keyname = HeapAlloc(GetProcessHeap(), 0,
603 sizeof(WCHAR) * (lstrlenW(subkey) + strlenW(username) + strlenW(device) + strlenW(guid)));
604 sprintfW(keyname, subkey, username, device, guid);
605
606 /* The key used is HKCU\Software\Wine\DirectInput\Mappings\[username]\[device]\[mapping_guid] */
607 if (RegCreateKeyW(HKEY_CURRENT_USER, keyname, &hkey))
608 hkey = 0;
609
610 HeapFree(GetProcessHeap(), 0, keyname);
611
612 return hkey;
613 }
614
615 static HRESULT save_mapping_settings(IDirectInputDevice8W *iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUsername)
616 {
617 WCHAR *guid_str = NULL;
618 DIDEVICEINSTANCEW didev;
619 HKEY hkey;
620 int i;
621
622 didev.dwSize = sizeof(didev);
623 IDirectInputDevice8_GetDeviceInfo(iface, &didev);
624
625 if (StringFromCLSID(&lpdiaf->guidActionMap, &guid_str) != S_OK)
626 return DI_SETTINGSNOTSAVED;
627
628 hkey = get_mapping_key(didev.tszInstanceName, lpszUsername, guid_str);
629
630 if (!hkey)
631 {
632 CoTaskMemFree(guid_str);
633 return DI_SETTINGSNOTSAVED;
634 }
635
636 /* Write each of the actions mapped for this device.
637 Format is "dwSemantic"="dwObjID" and key is of type REG_DWORD
638 */
639 for (i = 0; i < lpdiaf->dwNumActions; i++)
640 {
641 static const WCHAR format[] = {'%','x','\0'};
642 WCHAR label[9];
643
644 if (IsEqualGUID(&didev.guidInstance, &lpdiaf->rgoAction[i].guidInstance) &&
645 lpdiaf->rgoAction[i].dwHow != DIAH_UNMAPPED)
646 {
647 sprintfW(label, format, lpdiaf->rgoAction[i].dwSemantic);
648 RegSetValueExW(hkey, label, 0, REG_DWORD, (const BYTE*) &lpdiaf->rgoAction[i].dwObjID, sizeof(DWORD));
649 }
650 }
651
652 RegCloseKey(hkey);
653 CoTaskMemFree(guid_str);
654
655 return DI_OK;
656 }
657
658 static BOOL load_mapping_settings(IDirectInputDeviceImpl *This, LPDIACTIONFORMATW lpdiaf, const WCHAR *username)
659 {
660 HKEY hkey;
661 WCHAR *guid_str;
662 DIDEVICEINSTANCEW didev;
663 int i, mapped = 0;
664
665 didev.dwSize = sizeof(didev);
666 IDirectInputDevice8_GetDeviceInfo(&This->IDirectInputDevice8W_iface, &didev);
667
668 if (StringFromCLSID(&lpdiaf->guidActionMap, &guid_str) != S_OK)
669 return FALSE;
670
671 hkey = get_mapping_key(didev.tszInstanceName, username, guid_str);
672
673 if (!hkey)
674 {
675 CoTaskMemFree(guid_str);
676 return FALSE;
677 }
678
679 /* Try to read each action in the DIACTIONFORMAT from registry */
680 for (i = 0; i < lpdiaf->dwNumActions; i++)
681 {
682 static const WCHAR format[] = {'%','x','\0'};
683 DWORD id, size = sizeof(DWORD);
684 WCHAR label[9];
685
686 sprintfW(label, format, lpdiaf->rgoAction[i].dwSemantic);
687
688 if (!RegQueryValueExW(hkey, label, 0, NULL, (LPBYTE) &id, &size))
689 {
690 lpdiaf->rgoAction[i].dwObjID = id;
691 lpdiaf->rgoAction[i].guidInstance = didev.guidInstance;
692 lpdiaf->rgoAction[i].dwHow = DIAH_DEFAULT;
693 mapped += 1;
694 }
695 }
696
697 RegCloseKey(hkey);
698 CoTaskMemFree(guid_str);
699
700 return mapped > 0;
701 }
702
703 HRESULT _build_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags, DWORD devMask, LPCDIDATAFORMAT df)
704 {
705 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
706 WCHAR username[MAX_PATH];
707 DWORD username_size = MAX_PATH;
708 int i, has_actions = 0;
709 BOOL load_success = FALSE;
710
711 /* Unless asked the contrary by these flags, try to load a previous mapping */
712 if (!(dwFlags & DIDBAM_HWDEFAULTS))
713 {
714 /* Retrieve logged user name if necessary */
715 if (lpszUserName == NULL)
716 GetUserNameW(username, &username_size);
717 else
718 lstrcpynW(username, lpszUserName, MAX_PATH);
719
720 load_success = load_mapping_settings(This, lpdiaf, username);
721 }
722
723 if (load_success) return DI_OK;
724
725 for (i=0; i < lpdiaf->dwNumActions; i++)
726 {
727 /* Don't touch a user configured action */
728 if (lpdiaf->rgoAction[i].dwHow == DIAH_USERCONFIG) continue;
729
730 if ((lpdiaf->rgoAction[i].dwSemantic & devMask) == devMask)
731 {
732 DWORD obj_id = semantic_to_obj_id(This, lpdiaf->rgoAction[i].dwSemantic);
733 DWORD type = DIDFT_GETTYPE(obj_id);
734 DWORD inst = DIDFT_GETINSTANCE(obj_id);
735
736 LPDIOBJECTDATAFORMAT odf;
737
738 if (type == DIDFT_PSHBUTTON) type = DIDFT_BUTTON;
739 if (type == DIDFT_RELAXIS) type = DIDFT_AXIS;
740
741 /* Make sure the object exists */
742 odf = dataformat_to_odf_by_type(df, inst, type);
743
744 if (odf != NULL)
745 {
746 lpdiaf->rgoAction[i].dwObjID = obj_id;
747 lpdiaf->rgoAction[i].guidInstance = This->guid;
748 lpdiaf->rgoAction[i].dwHow = DIAH_DEFAULT;
749 has_actions = 1;
750 }
751 }
752 else if (!(dwFlags & DIDBAM_PRESERVE))
753 {
754 /* We must clear action data belonging to other devices */
755 memset(&lpdiaf->rgoAction[i].guidInstance, 0, sizeof(GUID));
756 lpdiaf->rgoAction[i].dwHow = DIAH_UNMAPPED;
757 }
758 }
759
760 if (!has_actions) return DI_NOEFFECT;
761
762 return IDirectInputDevice8WImpl_BuildActionMap(iface, lpdiaf, lpszUserName, dwFlags);
763 }
764
765 HRESULT _set_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags, LPCDIDATAFORMAT df)
766 {
767 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
768 DIDATAFORMAT data_format;
769 DIOBJECTDATAFORMAT *obj_df = NULL;
770 DIPROPDWORD dp;
771 DIPROPRANGE dpr;
772 WCHAR username[MAX_PATH];
773 DWORD username_size = MAX_PATH;
774 int i, action = 0, num_actions = 0;
775 unsigned int offset = 0;
776
777 if (This->acquired) return DIERR_ACQUIRED;
778
779 data_format.dwSize = sizeof(data_format);
780 data_format.dwObjSize = sizeof(DIOBJECTDATAFORMAT);
781 data_format.dwFlags = DIDF_RELAXIS;
782 data_format.dwDataSize = lpdiaf->dwDataSize;
783
784 /* Count the actions */
785 for (i=0; i < lpdiaf->dwNumActions; i++)
786 if (IsEqualGUID(&This->guid, &lpdiaf->rgoAction[i].guidInstance))
787 num_actions++;
788
789 if (num_actions == 0) return DI_NOEFFECT;
790
791 This->num_actions = num_actions;
792
793 /* Construct the dataformat and actionmap */
794 obj_df = HeapAlloc(GetProcessHeap(), 0, sizeof(DIOBJECTDATAFORMAT)*num_actions);
795 data_format.rgodf = (LPDIOBJECTDATAFORMAT)obj_df;
796 data_format.dwNumObjs = num_actions;
797
798 HeapFree(GetProcessHeap(), 0, This->action_map);
799 This->action_map = HeapAlloc(GetProcessHeap(), 0, sizeof(ActionMap)*num_actions);
800
801 for (i = 0; i < lpdiaf->dwNumActions; i++)
802 {
803 if (IsEqualGUID(&This->guid, &lpdiaf->rgoAction[i].guidInstance))
804 {
805 DWORD inst = DIDFT_GETINSTANCE(lpdiaf->rgoAction[i].dwObjID);
806 DWORD type = DIDFT_GETTYPE(lpdiaf->rgoAction[i].dwObjID);
807 LPDIOBJECTDATAFORMAT obj;
808
809 if (type == DIDFT_PSHBUTTON) type = DIDFT_BUTTON;
810 if (type == DIDFT_RELAXIS) type = DIDFT_AXIS;
811
812 obj = dataformat_to_odf_by_type(df, inst, type);
813
814 memcpy(&obj_df[action], obj, df->dwObjSize);
815
816 This->action_map[action].uAppData = lpdiaf->rgoAction[i].uAppData;
817 This->action_map[action].offset = offset;
818 obj_df[action].dwOfs = offset;
819 offset += (type & DIDFT_BUTTON) ? 1 : 4;
820
821 action++;
822 }
823 }
824
825 IDirectInputDevice8_SetDataFormat(iface, &data_format);
826
827 HeapFree(GetProcessHeap(), 0, obj_df);
828
829 /* Set the device properties according to the action format */
830 dpr.diph.dwSize = sizeof(DIPROPRANGE);
831 dpr.lMin = lpdiaf->lAxisMin;
832 dpr.lMax = lpdiaf->lAxisMax;
833 dpr.diph.dwHeaderSize = sizeof(DIPROPHEADER);
834 dpr.diph.dwHow = DIPH_DEVICE;
835 IDirectInputDevice8_SetProperty(iface, DIPROP_RANGE, &dpr.diph);
836
837 if (lpdiaf->dwBufferSize > 0)
838 {
839 dp.diph.dwSize = sizeof(DIPROPDWORD);
840 dp.dwData = lpdiaf->dwBufferSize;
841 dp.diph.dwHeaderSize = sizeof(DIPROPHEADER);
842 dp.diph.dwHow = DIPH_DEVICE;
843 IDirectInputDevice8_SetProperty(iface, DIPROP_BUFFERSIZE, &dp.diph);
844 }
845
846 /* Retrieve logged user name if necessary */
847 if (lpszUserName == NULL)
848 GetUserNameW(username, &username_size);
849 else
850 lstrcpynW(username, lpszUserName, MAX_PATH);
851
852 /* Save the settings to disk */
853 save_mapping_settings(iface, lpdiaf, username);
854
855 return IDirectInputDevice8WImpl_SetActionMap(iface, lpdiaf, lpszUserName, dwFlags);
856 }
857
858 /******************************************************************************
859 * queue_event - add new event to the ring queue
860 */
861
862 void queue_event(LPDIRECTINPUTDEVICE8A iface, int inst_id, DWORD data, DWORD time, DWORD seq)
863 {
864 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
865 int next_pos, ofs = id_to_offset(&This->data_format, inst_id);
866
867 /* Event is being set regardless of the queue state */
868 if (This->hEvent) SetEvent(This->hEvent);
869
870 if (!This->queue_len || This->overflow || ofs < 0) return;
871
872 next_pos = (This->queue_head + 1) % This->queue_len;
873 if (next_pos == This->queue_tail)
874 {
875 TRACE(" queue overflowed\n");
876 This->overflow = TRUE;
877 return;
878 }
879
880 TRACE(" queueing %d at offset %d (queue head %d / size %d)\n",
881 data, ofs, This->queue_head, This->queue_len);
882
883 This->data_queue[This->queue_head].dwOfs = ofs;
884 This->data_queue[This->queue_head].dwData = data;
885 This->data_queue[This->queue_head].dwTimeStamp = time;
886 This->data_queue[This->queue_head].dwSequence = seq;
887
888 /* Set uAppData by means of action mapping */
889 if (This->num_actions > 0)
890 {
891 int i;
892 for (i=0; i < This->num_actions; i++)
893 {
894 if (This->action_map[i].offset == ofs)
895 {
896 TRACE("Offset %d mapped to uAppData %lu\n", ofs, This->action_map[i].uAppData);
897 This->data_queue[This->queue_head].uAppData = This->action_map[i].uAppData;
898 break;
899 }
900 }
901 }
902
903 This->queue_head = next_pos;
904 /* Send event if asked */
905 }
906
907 /******************************************************************************
908 * Acquire
909 */
910
911 HRESULT WINAPI IDirectInputDevice2WImpl_Acquire(LPDIRECTINPUTDEVICE8W iface)
912 {
913 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
914 HRESULT res;
915
916 TRACE("(%p)\n", This);
917
918 if (!This->data_format.user_df) return DIERR_INVALIDPARAM;
919 if (This->dwCoopLevel & DISCL_FOREGROUND && This->win != GetForegroundWindow())
920 return DIERR_OTHERAPPHASPRIO;
921
922 EnterCriticalSection(&This->crit);
923 res = This->acquired ? S_FALSE : DI_OK;
924 This->acquired = 1;
925 if (res == DI_OK)
926 check_dinput_hooks(iface);
927 LeaveCriticalSection(&This->crit);
928
929 return res;
930 }
931
932 HRESULT WINAPI IDirectInputDevice2AImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
933 {
934 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
935 return IDirectInputDevice2WImpl_Acquire(IDirectInputDevice8W_from_impl(This));
936 }
937
938
939 /******************************************************************************
940 * Unacquire
941 */
942
943 HRESULT WINAPI IDirectInputDevice2WImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface)
944 {
945 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
946 HRESULT res;
947
948 TRACE("(%p)\n", This);
949
950 EnterCriticalSection(&This->crit);
951 res = !This->acquired ? DI_NOEFFECT : DI_OK;
952 This->acquired = 0;
953 if (res == DI_OK)
954 check_dinput_hooks(iface);
955 LeaveCriticalSection(&This->crit);
956
957 return res;
958 }
959
960 HRESULT WINAPI IDirectInputDevice2AImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
961 {
962 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
963 return IDirectInputDevice2WImpl_Unacquire(IDirectInputDevice8W_from_impl(This));
964 }
965
966 /******************************************************************************
967 * IDirectInputDeviceA
968 */
969
970 HRESULT WINAPI IDirectInputDevice2WImpl_SetDataFormat(LPDIRECTINPUTDEVICE8W iface, LPCDIDATAFORMAT df)
971 {
972 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
973 HRESULT res = DI_OK;
974
975 if (!df) return E_POINTER;
976 TRACE("(%p) %p\n", This, df);
977 _dump_DIDATAFORMAT(df);
978
979 if (df->dwSize != sizeof(DIDATAFORMAT)) return DIERR_INVALIDPARAM;
980 if (This->acquired) return DIERR_ACQUIRED;
981
982 EnterCriticalSection(&This->crit);
983
984 release_DataFormat(&This->data_format);
985 res = create_DataFormat(df, &This->data_format);
986
987 LeaveCriticalSection(&This->crit);
988 return res;
989 }
990
991 HRESULT WINAPI IDirectInputDevice2AImpl_SetDataFormat(LPDIRECTINPUTDEVICE8A iface, LPCDIDATAFORMAT df)
992 {
993 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
994 return IDirectInputDevice2WImpl_SetDataFormat(IDirectInputDevice8W_from_impl(This), df);
995 }
996
997 /******************************************************************************
998 * SetCooperativeLevel
999 *
1000 * Set cooperative level and the source window for the events.
1001 */
1002 HRESULT WINAPI IDirectInputDevice2WImpl_SetCooperativeLevel(LPDIRECTINPUTDEVICE8W iface, HWND hwnd, DWORD dwflags)
1003 {
1004 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1005
1006 TRACE("(%p) %p,0x%08x\n", This, hwnd, dwflags);
1007 _dump_cooperativelevel_DI(dwflags);
1008
1009 if ((dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == 0 ||
1010 (dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE) ||
1011 (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == 0 ||
1012 (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == (DISCL_FOREGROUND | DISCL_BACKGROUND))
1013 return DIERR_INVALIDPARAM;
1014
1015 if (hwnd && GetWindowLongW(hwnd, GWL_STYLE) & WS_CHILD) return E_HANDLE;
1016
1017 if (dwflags == (DISCL_NONEXCLUSIVE | DISCL_BACKGROUND))
1018 hwnd = GetDesktopWindow();
1019
1020 if (!hwnd) return E_HANDLE;
1021
1022 /* For security reasons native does not allow exclusive background level
1023 for mouse and keyboard only */
1024 if (dwflags & DISCL_EXCLUSIVE && dwflags & DISCL_BACKGROUND &&
1025 (IsEqualGUID(&This->guid, &GUID_SysMouse) ||
1026 IsEqualGUID(&This->guid, &GUID_SysKeyboard)))
1027 return DIERR_UNSUPPORTED;
1028
1029 /* Store the window which asks for the mouse */
1030 EnterCriticalSection(&This->crit);
1031 This->win = hwnd;
1032 This->dwCoopLevel = dwflags;
1033 LeaveCriticalSection(&This->crit);
1034
1035 return DI_OK;
1036 }
1037
1038 HRESULT WINAPI IDirectInputDevice2AImpl_SetCooperativeLevel(LPDIRECTINPUTDEVICE8A iface, HWND hwnd, DWORD dwflags)
1039 {
1040 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1041 return IDirectInputDevice2WImpl_SetCooperativeLevel(IDirectInputDevice8W_from_impl(This), hwnd, dwflags);
1042 }
1043
1044 /******************************************************************************
1045 * SetEventNotification : specifies event to be sent on state change
1046 */
1047 HRESULT WINAPI IDirectInputDevice2WImpl_SetEventNotification(LPDIRECTINPUTDEVICE8W iface, HANDLE event)
1048 {
1049 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1050
1051 TRACE("(%p) %p\n", This, event);
1052
1053 EnterCriticalSection(&This->crit);
1054 This->hEvent = event;
1055 LeaveCriticalSection(&This->crit);
1056 return DI_OK;
1057 }
1058
1059 HRESULT WINAPI IDirectInputDevice2AImpl_SetEventNotification(LPDIRECTINPUTDEVICE8A iface, HANDLE event)
1060 {
1061 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1062 return IDirectInputDevice2WImpl_SetEventNotification(IDirectInputDevice8W_from_impl(This), event);
1063 }
1064
1065
1066 ULONG WINAPI IDirectInputDevice2WImpl_Release(LPDIRECTINPUTDEVICE8W iface)
1067 {
1068 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1069 ULONG ref = InterlockedDecrement(&(This->ref));
1070
1071 TRACE("(%p) releasing from %d\n", This, ref + 1);
1072
1073 if (ref) return ref;
1074
1075 IDirectInputDevice_Unacquire(iface);
1076 /* Reset the FF state, free all effects, etc */
1077 IDirectInputDevice8_SendForceFeedbackCommand(iface, DISFFC_RESET);
1078
1079 HeapFree(GetProcessHeap(), 0, This->data_queue);
1080
1081 /* Free data format */
1082 HeapFree(GetProcessHeap(), 0, This->data_format.wine_df->rgodf);
1083 HeapFree(GetProcessHeap(), 0, This->data_format.wine_df);
1084 release_DataFormat(&This->data_format);
1085
1086 /* Free action mapping */
1087 HeapFree(GetProcessHeap(), 0, This->action_map);
1088
1089 EnterCriticalSection( &This->dinput->crit );
1090 list_remove( &This->entry );
1091 LeaveCriticalSection( &This->dinput->crit );
1092
1093 IDirectInput_Release(&This->dinput->IDirectInput7A_iface);
1094 This->crit.DebugInfo->Spare[0] = 0;
1095 DeleteCriticalSection(&This->crit);
1096
1097 HeapFree(GetProcessHeap(), 0, This);
1098
1099 return DI_OK;
1100 }
1101
1102 ULONG WINAPI IDirectInputDevice2AImpl_Release(LPDIRECTINPUTDEVICE8A iface)
1103 {
1104 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1105 return IDirectInputDevice2WImpl_Release(IDirectInputDevice8W_from_impl(This));
1106 }
1107
1108 HRESULT WINAPI IDirectInputDevice2WImpl_QueryInterface(LPDIRECTINPUTDEVICE8W iface, REFIID riid, LPVOID *ppobj)
1109 {
1110 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1111
1112 TRACE("(%p this=%p,%s,%p)\n", iface, This, debugstr_guid(riid), ppobj);
1113 if (IsEqualGUID(&IID_IUnknown, riid) ||
1114 IsEqualGUID(&IID_IDirectInputDeviceA, riid) ||
1115 IsEqualGUID(&IID_IDirectInputDevice2A, riid) ||
1116 IsEqualGUID(&IID_IDirectInputDevice7A, riid) ||
1117 IsEqualGUID(&IID_IDirectInputDevice8A, riid))
1118 {
1119 IDirectInputDevice2_AddRef(iface);
1120 *ppobj = IDirectInputDevice8A_from_impl(This);
1121 return DI_OK;
1122 }
1123 if (IsEqualGUID(&IID_IDirectInputDeviceW, riid) ||
1124 IsEqualGUID(&IID_IDirectInputDevice2W, riid) ||
1125 IsEqualGUID(&IID_IDirectInputDevice7W, riid) ||
1126 IsEqualGUID(&IID_IDirectInputDevice8W, riid))
1127 {
1128 IDirectInputDevice2_AddRef(iface);
1129 *ppobj = IDirectInputDevice8W_from_impl(This);
1130 return DI_OK;
1131 }
1132
1133 WARN("Unsupported interface!\n");
1134 return E_FAIL;
1135 }
1136
1137 HRESULT WINAPI IDirectInputDevice2AImpl_QueryInterface(LPDIRECTINPUTDEVICE8A iface, REFIID riid, LPVOID *ppobj)
1138 {
1139 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1140 return IDirectInputDevice2WImpl_QueryInterface(IDirectInputDevice8W_from_impl(This), riid, ppobj);
1141 }
1142
1143 ULONG WINAPI IDirectInputDevice2WImpl_AddRef(LPDIRECTINPUTDEVICE8W iface)
1144 {
1145 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1146 return InterlockedIncrement(&This->ref);
1147 }
1148
1149 ULONG WINAPI IDirectInputDevice2AImpl_AddRef(LPDIRECTINPUTDEVICE8A iface)
1150 {
1151 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1152 return IDirectInputDevice2WImpl_AddRef(IDirectInputDevice8W_from_impl(This));
1153 }
1154
1155 HRESULT WINAPI IDirectInputDevice2AImpl_EnumObjects(LPDIRECTINPUTDEVICE8A iface,
1156 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback, LPVOID lpvRef, DWORD dwFlags)
1157 {
1158 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1159 DIDEVICEOBJECTINSTANCEA ddoi;
1160 int i;
1161
1162 TRACE("(%p) %p,%p flags:%08x)\n", iface, lpCallback, lpvRef, dwFlags);
1163 TRACE(" - flags = ");
1164 _dump_EnumObjects_flags(dwFlags);
1165 TRACE("\n");
1166
1167 /* Only the fields till dwFFMaxForce are relevant */
1168 memset(&ddoi, 0, sizeof(ddoi));
1169 ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce);
1170
1171 for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++)
1172 {
1173 LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(This->data_format.wine_df, i);
1174
1175 if (dwFlags != DIDFT_ALL && !(dwFlags & DIDFT_GETTYPE(odf->dwType))) continue;
1176 if (IDirectInputDevice_GetObjectInfo(iface, &ddoi, odf->dwType, DIPH_BYID) != DI_OK)
1177 continue;
1178
1179 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) break;
1180 }
1181
1182 return DI_OK;
1183 }
1184
1185 HRESULT WINAPI IDirectInputDevice2WImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface,
1186 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback, LPVOID lpvRef, DWORD dwFlags)
1187 {
1188 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1189 DIDEVICEOBJECTINSTANCEW ddoi;
1190 int i;
1191
1192 TRACE("(%p) %p,%p flags:%08x)\n", iface, lpCallback, lpvRef, dwFlags);
1193 TRACE(" - flags = ");
1194 _dump_EnumObjects_flags(dwFlags);
1195 TRACE("\n");
1196
1197 /* Only the fields till dwFFMaxForce are relevant */
1198 memset(&ddoi, 0, sizeof(ddoi));
1199 ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEW, dwFFMaxForce);
1200
1201 for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++)
1202 {
1203 LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(This->data_format.wine_df, i);
1204
1205 if (dwFlags != DIDFT_ALL && !(dwFlags & DIDFT_GETTYPE(odf->dwType))) continue;
1206 if (IDirectInputDevice_GetObjectInfo(iface, &ddoi, odf->dwType, DIPH_BYID) != DI_OK)
1207 continue;
1208
1209 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) break;
1210 }
1211
1212 return DI_OK;
1213 }
1214
1215 /******************************************************************************
1216 * GetProperty
1217 */
1218
1219 HRESULT WINAPI IDirectInputDevice2WImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface, REFGUID rguid, LPDIPROPHEADER pdiph)
1220 {
1221 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1222
1223 TRACE("(%p) %s,%p\n", iface, debugstr_guid(rguid), pdiph);
1224 _dump_DIPROPHEADER(pdiph);
1225
1226 if (!IS_DIPROP(rguid)) return DI_OK;
1227
1228 switch (LOWORD(rguid))
1229 {
1230 case (DWORD_PTR) DIPROP_BUFFERSIZE:
1231 {
1232 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
1233
1234 if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
1235
1236 pd->dwData = This->queue_len;
1237 TRACE("buffersize = %d\n", pd->dwData);
1238 break;
1239 }
1240 case (DWORD_PTR) DIPROP_VIDPID:
1241 FIXME("DIPROP_VIDPID not implemented\n");
1242 return DIERR_UNSUPPORTED;
1243 default:
1244 FIXME("Unknown property %s\n", debugstr_guid(rguid));
1245 return DIERR_INVALIDPARAM;
1246 }
1247
1248 return DI_OK;
1249 }
1250
1251 HRESULT WINAPI IDirectInputDevice2AImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPDIPROPHEADER pdiph)
1252 {
1253 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1254 return IDirectInputDevice2WImpl_GetProperty(IDirectInputDevice8W_from_impl(This), rguid, pdiph);
1255 }
1256
1257 /******************************************************************************
1258 * SetProperty
1259 */
1260
1261 HRESULT WINAPI IDirectInputDevice2WImpl_SetProperty(
1262 LPDIRECTINPUTDEVICE8W iface, REFGUID rguid, LPCDIPROPHEADER pdiph)
1263 {
1264 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1265
1266 TRACE("(%p) %s,%p\n", iface, debugstr_guid(rguid), pdiph);
1267 _dump_DIPROPHEADER(pdiph);
1268
1269 if (!IS_DIPROP(rguid)) return DI_OK;
1270
1271 switch (LOWORD(rguid))
1272 {
1273 case (DWORD_PTR) DIPROP_AXISMODE:
1274 {
1275 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph;
1276
1277 if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
1278 if (pdiph->dwHow == DIPH_DEVICE && pdiph->dwObj) return DIERR_INVALIDPARAM;
1279 if (This->acquired) return DIERR_ACQUIRED;
1280 if (pdiph->dwHow != DIPH_DEVICE) return DIERR_UNSUPPORTED;
1281 if (!This->data_format.user_df) return DI_OK;
1282
1283 TRACE("Axis mode: %s\n", pd->dwData == DIPROPAXISMODE_ABS ? "absolute" :
1284 "relative");
1285
1286 EnterCriticalSection(&This->crit);
1287 This->data_format.user_df->dwFlags &= ~DIDFT_AXIS;
1288 This->data_format.user_df->dwFlags |= pd->dwData == DIPROPAXISMODE_ABS ?
1289 DIDF_ABSAXIS : DIDF_RELAXIS;
1290 LeaveCriticalSection(&This->crit);
1291 break;
1292 }
1293 case (DWORD_PTR) DIPROP_BUFFERSIZE:
1294 {
1295 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph;
1296
1297 if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
1298 if (This->acquired) return DIERR_ACQUIRED;
1299
1300 TRACE("buffersize = %d\n", pd->dwData);
1301
1302 EnterCriticalSection(&This->crit);
1303 HeapFree(GetProcessHeap(), 0, This->data_queue);
1304
1305 This->data_queue = !pd->dwData ? NULL : HeapAlloc(GetProcessHeap(), 0,
1306 pd->dwData * sizeof(DIDEVICEOBJECTDATA));
1307 This->queue_head = This->queue_tail = This->overflow = 0;
1308 This->queue_len = pd->dwData;
1309
1310 LeaveCriticalSection(&This->crit);
1311 break;
1312 }
1313 default:
1314 WARN("Unknown property %s\n", debugstr_guid(rguid));
1315 return DIERR_UNSUPPORTED;
1316 }
1317
1318 return DI_OK;
1319 }
1320
1321 HRESULT WINAPI IDirectInputDevice2AImpl_SetProperty(
1322 LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPCDIPROPHEADER pdiph)
1323 {
1324 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1325 return IDirectInputDevice2WImpl_SetProperty(IDirectInputDevice8W_from_impl(This), rguid, pdiph);
1326 }
1327
1328 HRESULT WINAPI IDirectInputDevice2AImpl_GetObjectInfo(
1329 LPDIRECTINPUTDEVICE8A iface,
1330 LPDIDEVICEOBJECTINSTANCEA pdidoi,
1331 DWORD dwObj,
1332 DWORD dwHow)
1333 {
1334 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1335 DIDEVICEOBJECTINSTANCEW didoiW;
1336 HRESULT res;
1337
1338 if (!pdidoi ||
1339 (pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCEA) &&
1340 pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCE_DX3A)))
1341 return DIERR_INVALIDPARAM;
1342
1343 didoiW.dwSize = sizeof(didoiW);
1344 res = IDirectInputDevice2WImpl_GetObjectInfo(IDirectInputDevice8W_from_impl(This), &didoiW, dwObj, dwHow);
1345 if (res == DI_OK)
1346 {
1347 DWORD dwSize = pdidoi->dwSize;
1348
1349 memset(pdidoi, 0, pdidoi->dwSize);
1350 pdidoi->dwSize = dwSize;
1351 pdidoi->guidType = didoiW.guidType;
1352 pdidoi->dwOfs = didoiW.dwOfs;
1353 pdidoi->dwType = didoiW.dwType;
1354 pdidoi->dwFlags = didoiW.dwFlags;
1355 }
1356
1357 return res;
1358 }
1359
1360 HRESULT WINAPI IDirectInputDevice2WImpl_GetObjectInfo(
1361 LPDIRECTINPUTDEVICE8W iface,
1362 LPDIDEVICEOBJECTINSTANCEW pdidoi,
1363 DWORD dwObj,
1364 DWORD dwHow)
1365 {
1366 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1367 DWORD dwSize;
1368 LPDIOBJECTDATAFORMAT odf;
1369 int idx = -1;
1370
1371 TRACE("(%p) %d(0x%08x) -> %p\n", This, dwHow, dwObj, pdidoi);
1372
1373 if (!pdidoi ||
1374 (pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCEW) &&
1375 pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCE_DX3W)))
1376 return DIERR_INVALIDPARAM;
1377
1378 switch (dwHow)
1379 {
1380 case DIPH_BYOFFSET:
1381 if (!This->data_format.offsets) break;
1382 for (idx = This->data_format.wine_df->dwNumObjs - 1; idx >= 0; idx--)
1383 if (This->data_format.offsets[idx] == dwObj) break;
1384 break;
1385 case DIPH_BYID:
1386 dwObj &= 0x00ffffff;
1387 for (idx = This->data_format.wine_df->dwNumObjs - 1; idx >= 0; idx--)
1388 if ((dataformat_to_odf(This->data_format.wine_df, idx)->dwType & 0x00ffffff) == dwObj)
1389 break;
1390 break;
1391
1392 case DIPH_BYUSAGE:
1393 FIXME("dwHow = DIPH_BYUSAGE not implemented\n");
1394 break;
1395 default:
1396 WARN("invalid parameter: dwHow = %08x\n", dwHow);
1397 return DIERR_INVALIDPARAM;
1398 }
1399 if (idx < 0) return DIERR_OBJECTNOTFOUND;
1400
1401 odf = dataformat_to_odf(This->data_format.wine_df, idx);
1402 dwSize = pdidoi->dwSize; /* save due to memset below */
1403 memset(pdidoi, 0, pdidoi->dwSize);
1404 pdidoi->dwSize = dwSize;
1405 if (odf->pguid) pdidoi->guidType = *odf->pguid;
1406 pdidoi->dwOfs = This->data_format.offsets ? This->data_format.offsets[idx] : odf->dwOfs;
1407 pdidoi->dwType = odf->dwType;
1408 pdidoi->dwFlags = odf->dwFlags;
1409
1410 return DI_OK;
1411 }
1412
1413 HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceData(LPDIRECTINPUTDEVICE8W iface, DWORD dodsize,
1414 LPDIDEVICEOBJECTDATA dod, LPDWORD entries, DWORD flags)
1415 {
1416 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1417 HRESULT ret = DI_OK;
1418 int len;
1419
1420 TRACE("(%p) %p -> %p(%d) x%d, 0x%08x\n",
1421 This, dod, entries, entries ? *entries : 0, dodsize, flags);
1422
1423 if (This->dinput->dwVersion == 0x0800 || dodsize == sizeof(DIDEVICEOBJECTDATA_DX3))
1424 {
1425 if (!This->queue_len) return DIERR_NOTBUFFERED;
1426 if (!This->acquired) return DIERR_NOTACQUIRED;
1427 }
1428
1429 if (!This->queue_len)
1430 return DI_OK;
1431 if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3))
1432 return DIERR_INVALIDPARAM;
1433
1434 IDirectInputDevice2_Poll(iface);
1435 EnterCriticalSection(&This->crit);
1436
1437 len = This->queue_head - This->queue_tail;
1438 if (len < 0) len += This->queue_len;
1439
1440 if ((*entries != INFINITE) && (len > *entries)) len = *entries;
1441
1442 if (dod)
1443 {
1444 int i;
1445 for (i = 0; i < len; i++)
1446 {
1447 int n = (This->queue_tail + i) % This->queue_len;
1448 memcpy((char *)dod + dodsize * i, This->data_queue + n, dodsize);
1449 }
1450 }
1451 *entries = len;
1452
1453 if (This->overflow && This->dinput->dwVersion == 0x0800)
1454 ret = DI_BUFFEROVERFLOW;
1455
1456 if (!(flags & DIGDD_PEEK))
1457 {
1458 /* Advance reading position */
1459 This->queue_tail = (This->queue_tail + len) % This->queue_len;
1460 This->overflow = FALSE;
1461 }
1462
1463 LeaveCriticalSection(&This->crit);
1464
1465 TRACE("Returning %d events queued\n", *entries);
1466 return ret;
1467 }
1468
1469 HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface, DWORD dodsize,
1470 LPDIDEVICEOBJECTDATA dod, LPDWORD entries, DWORD flags)
1471 {
1472 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1473 return IDirectInputDevice2WImpl_GetDeviceData(IDirectInputDevice8W_from_impl(This), dodsize, dod, entries, flags);
1474 }
1475
1476 HRESULT WINAPI IDirectInputDevice2WImpl_RunControlPanel(LPDIRECTINPUTDEVICE8W iface, HWND hwndOwner, DWORD dwFlags)
1477 {
1478 FIXME("(this=%p,%p,0x%08x): stub!\n", iface, hwndOwner, dwFlags);
1479
1480 return DI_OK;
1481 }
1482
1483 HRESULT WINAPI IDirectInputDevice2AImpl_RunControlPanel(LPDIRECTINPUTDEVICE8A iface, HWND hwndOwner, DWORD dwFlags)
1484 {
1485 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1486 return IDirectInputDevice2WImpl_RunControlPanel(IDirectInputDevice8W_from_impl(This), hwndOwner, dwFlags);
1487 }
1488
1489 HRESULT WINAPI IDirectInputDevice2WImpl_Initialize(LPDIRECTINPUTDEVICE8W iface, HINSTANCE hinst, DWORD dwVersion,
1490 REFGUID rguid)
1491 {
1492 FIXME("(this=%p,%p,%d,%s): stub!\n", iface, hinst, dwVersion, debugstr_guid(rguid));
1493 return DI_OK;
1494 }
1495
1496 HRESULT WINAPI IDirectInputDevice2AImpl_Initialize(LPDIRECTINPUTDEVICE8A iface, HINSTANCE hinst, DWORD dwVersion,
1497 REFGUID rguid)
1498 {
1499 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1500 return IDirectInputDevice2WImpl_Initialize(IDirectInputDevice8W_from_impl(This), hinst, dwVersion, rguid);
1501 }
1502
1503 /******************************************************************************
1504 * IDirectInputDevice2A
1505 */
1506
1507 HRESULT WINAPI IDirectInputDevice2WImpl_CreateEffect(LPDIRECTINPUTDEVICE8W iface, REFGUID rguid, LPCDIEFFECT lpeff,
1508 LPDIRECTINPUTEFFECT *ppdef, LPUNKNOWN pUnkOuter)
1509 {
1510 FIXME("(this=%p,%s,%p,%p,%p): stub!\n", iface, debugstr_guid(rguid), lpeff, ppdef, pUnkOuter);
1511 return DI_OK;
1512 }
1513
1514 HRESULT WINAPI IDirectInputDevice2AImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPCDIEFFECT lpeff,
1515 LPDIRECTINPUTEFFECT *ppdef, LPUNKNOWN pUnkOuter)
1516 {
1517 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1518 return IDirectInputDevice2WImpl_CreateEffect(IDirectInputDevice8W_from_impl(This), rguid, lpeff, ppdef, pUnkOuter);
1519 }
1520
1521 HRESULT WINAPI IDirectInputDevice2AImpl_EnumEffects(
1522 LPDIRECTINPUTDEVICE8A iface,
1523 LPDIENUMEFFECTSCALLBACKA lpCallback,
1524 LPVOID lpvRef,
1525 DWORD dwFlags)
1526 {
1527 FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1528 iface, lpCallback, lpvRef, dwFlags);
1529
1530 return DI_OK;
1531 }
1532
1533 HRESULT WINAPI IDirectInputDevice2WImpl_EnumEffects(
1534 LPDIRECTINPUTDEVICE8W iface,
1535 LPDIENUMEFFECTSCALLBACKW lpCallback,
1536 LPVOID lpvRef,
1537 DWORD dwFlags)
1538 {
1539 FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1540 iface, lpCallback, lpvRef, dwFlags);
1541
1542 return DI_OK;
1543 }
1544
1545 HRESULT WINAPI IDirectInputDevice2AImpl_GetEffectInfo(
1546 LPDIRECTINPUTDEVICE8A iface,
1547 LPDIEFFECTINFOA lpdei,
1548 REFGUID rguid)
1549 {
1550 FIXME("(this=%p,%p,%s): stub!\n",
1551 iface, lpdei, debugstr_guid(rguid));
1552 return DI_OK;
1553 }
1554
1555 HRESULT WINAPI IDirectInputDevice2WImpl_GetEffectInfo(
1556 LPDIRECTINPUTDEVICE8W iface,
1557 LPDIEFFECTINFOW lpdei,
1558 REFGUID rguid)
1559 {
1560 FIXME("(this=%p,%p,%s): stub!\n",
1561 iface, lpdei, debugstr_guid(rguid));
1562 return DI_OK;
1563 }
1564
1565 HRESULT WINAPI IDirectInputDevice2WImpl_GetForceFeedbackState(LPDIRECTINPUTDEVICE8W iface, LPDWORD pdwOut)
1566 {
1567 FIXME("(this=%p,%p): stub!\n", iface, pdwOut);
1568 return DI_OK;
1569 }
1570
1571 HRESULT WINAPI IDirectInputDevice2AImpl_GetForceFeedbackState(LPDIRECTINPUTDEVICE8A iface, LPDWORD pdwOut)
1572 {
1573 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1574 return IDirectInputDevice2WImpl_GetForceFeedbackState(IDirectInputDevice8W_from_impl(This), pdwOut);
1575 }
1576
1577 HRESULT WINAPI IDirectInputDevice2WImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8W iface, DWORD dwFlags)
1578 {
1579 TRACE("(%p) 0x%08x:\n", iface, dwFlags);
1580 return DI_NOEFFECT;
1581 }
1582
1583 HRESULT WINAPI IDirectInputDevice2AImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8A iface, DWORD dwFlags)
1584 {
1585 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1586 return IDirectInputDevice2WImpl_SendForceFeedbackCommand(IDirectInputDevice8W_from_impl(This), dwFlags);
1587 }
1588
1589 HRESULT WINAPI IDirectInputDevice2WImpl_EnumCreatedEffectObjects(LPDIRECTINPUTDEVICE8W iface,
1590 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback, LPVOID lpvRef, DWORD dwFlags)
1591 {
1592 FIXME("(this=%p,%p,%p,0x%08x): stub!\n", iface, lpCallback, lpvRef, dwFlags);
1593 return DI_OK;
1594 }
1595
1596 HRESULT WINAPI IDirectInputDevice2AImpl_EnumCreatedEffectObjects(LPDIRECTINPUTDEVICE8A iface,
1597 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback, LPVOID lpvRef, DWORD dwFlags)
1598 {
1599 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1600 return IDirectInputDevice2WImpl_EnumCreatedEffectObjects(IDirectInputDevice8W_from_impl(This), lpCallback, lpvRef, dwFlags);
1601 }
1602
1603 HRESULT WINAPI IDirectInputDevice2WImpl_Escape(LPDIRECTINPUTDEVICE8W iface, LPDIEFFESCAPE lpDIEEsc)
1604 {
1605 FIXME("(this=%p,%p): stub!\n", iface, lpDIEEsc);
1606 return DI_OK;
1607 }
1608
1609 HRESULT WINAPI IDirectInputDevice2AImpl_Escape(LPDIRECTINPUTDEVICE8A iface, LPDIEFFESCAPE lpDIEEsc)
1610 {
1611 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1612 return IDirectInputDevice2WImpl_Escape(IDirectInputDevice8W_from_impl(This), lpDIEEsc);
1613 }
1614
1615 HRESULT WINAPI IDirectInputDevice2WImpl_Poll(LPDIRECTINPUTDEVICE8W iface)
1616 {
1617 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
1618
1619 if (!This->acquired) return DIERR_NOTACQUIRED;
1620 /* Because wine devices do not need to be polled, just return DI_NOEFFECT */
1621 return DI_NOEFFECT;
1622 }
1623
1624 HRESULT WINAPI IDirectInputDevice2AImpl_Poll(LPDIRECTINPUTDEVICE8A iface)
1625 {
1626 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1627 return IDirectInputDevice2WImpl_Poll(IDirectInputDevice8W_from_impl(This));
1628 }
1629
1630 HRESULT WINAPI IDirectInputDevice2WImpl_SendDeviceData(LPDIRECTINPUTDEVICE8W iface, DWORD cbObjectData,
1631 LPCDIDEVICEOBJECTDATA rgdod, LPDWORD pdwInOut,
1632 DWORD dwFlags)
1633 {
1634 FIXME("(this=%p,0x%08x,%p,%p,0x%08x): stub!\n", iface, cbObjectData, rgdod, pdwInOut, dwFlags);
1635
1636 return DI_OK;
1637 }
1638
1639 HRESULT WINAPI IDirectInputDevice2AImpl_SendDeviceData(LPDIRECTINPUTDEVICE8A iface, DWORD cbObjectData,
1640 LPCDIDEVICEOBJECTDATA rgdod, LPDWORD pdwInOut,
1641 DWORD dwFlags)
1642 {
1643 IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
1644 return IDirectInputDevice2WImpl_SendDeviceData(IDirectInputDevice8W_from_impl(This), cbObjectData, rgdod,
1645 pdwInOut, dwFlags);
1646 }
1647
1648 HRESULT WINAPI IDirectInputDevice7AImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8A iface,
1649 LPCSTR lpszFileName,
1650 LPDIENUMEFFECTSINFILECALLBACK pec,
1651 LPVOID pvRef,
1652 DWORD dwFlags)
1653 {
1654 FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", iface, lpszFileName, pec, pvRef, dwFlags);
1655
1656 return DI_OK;
1657 }
1658
1659 HRESULT WINAPI IDirectInputDevice7WImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8W iface,
1660 LPCWSTR lpszFileName,
1661 LPDIENUMEFFECTSINFILECALLBACK pec,
1662 LPVOID pvRef,
1663 DWORD dwFlags)
1664 {
1665 FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", iface, debugstr_w(lpszFileName), pec, pvRef, dwFlags);
1666
1667 return DI_OK;
1668 }
1669
1670 HRESULT WINAPI IDirectInputDevice7AImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8A iface,
1671 LPCSTR lpszFileName,
1672 DWORD dwEntries,
1673 LPDIFILEEFFECT rgDiFileEft,
1674 DWORD dwFlags)
1675 {
1676 FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", iface, lpszFileName, dwEntries, rgDiFileEft, dwFlags);
1677
1678 return DI_OK;
1679 }
1680
1681 HRESULT WINAPI IDirectInputDevice7WImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8W iface,
1682 LPCWSTR lpszFileName,
1683 DWORD dwEntries,
1684 LPDIFILEEFFECT rgDiFileEft,
1685 DWORD dwFlags)
1686 {
1687 FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", iface, debugstr_w(lpszFileName), dwEntries, rgDiFileEft, dwFlags);
1688
1689 return DI_OK;
1690 }
1691
1692 HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface,
1693 LPDIACTIONFORMATW lpdiaf,
1694 LPCWSTR lpszUserName,
1695 DWORD dwFlags)
1696 {
1697 FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
1698 #define X(x) if (dwFlags & x) FIXME("\tdwFlags =|"#x"\n");
1699 X(DIDBAM_DEFAULT)
1700 X(DIDBAM_PRESERVE)
1701 X(DIDBAM_INITIALIZE)
1702 X(DIDBAM_HWDEFAULTS)
1703 #undef X
1704
1705 return DI_OK;
1706 }
1707
1708 HRESULT WINAPI IDirectInputDevice8WImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
1709 LPDIACTIONFORMATW lpdiaf,
1710 LPCWSTR lpszUserName,
1711 DWORD dwFlags)
1712 {
1713 FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
1714
1715 return DI_OK;
1716 }
1717
1718 HRESULT WINAPI IDirectInputDevice8AImpl_GetImageInfo(LPDIRECTINPUTDEVICE8A iface,
1719 LPDIDEVICEIMAGEINFOHEADERA lpdiDevImageInfoHeader)
1720 {
1721 FIXME("(%p)->(%p): stub !\n", iface, lpdiDevImageInfoHeader);
1722
1723 return DI_OK;
1724 }
1725
1726 HRESULT WINAPI IDirectInputDevice8WImpl_GetImageInfo(LPDIRECTINPUTDEVICE8W iface,
1727 LPDIDEVICEIMAGEINFOHEADERW lpdiDevImageInfoHeader)
1728 {
1729 FIXME("(%p)->(%p): stub !\n", iface, lpdiDevImageInfoHeader);
1730
1731 return DI_OK;
1732 }