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.
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
39 #include "device_private.h"
40 #include "dinput_private.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
44 /******************************************************************************
45 * Various debugging tools
47 void _dump_cooperativelevel_DI(DWORD dwFlags) {
48 if (TRACE_ON(dinput)) {
54 #define FE(x) { x, #x}
58 FE(DISCL_NONEXCLUSIVE),
62 for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++)
63 if (flags[i].mask & dwFlags)
64 DPRINTF("%s ",flags[i].name);
69 void _dump_EnumObjects_flags(DWORD dwFlags) {
70 if (TRACE_ON(dinput)) {
77 #define FE(x) { x, #x}
86 FE(DIDFT_FFEFFECTTRIGGER),
88 FE(DIDFT_VENDORDEFINED),
93 type = (dwFlags & 0xFF0000FF);
94 instance = ((dwFlags >> 8) & 0xFFFF);
96 if (type == DIDFT_ALL) {
97 DPRINTF(" DIDFT_ALL");
99 for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++) {
100 if (flags[i].mask & type) {
101 type &= ~flags[i].mask;
102 DPRINTF(" %s",flags[i].name);
106 DPRINTF(" (unhandled: %08x)", type);
109 DPRINTF(" / Instance: ");
110 if (instance == ((DIDFT_ANYINSTANCE >> 8) & 0xFFFF)) {
111 DPRINTF("DIDFT_ANYINSTANCE");
113 DPRINTF("%3d", instance);
118 void _dump_DIPROPHEADER(LPCDIPROPHEADER diph) {
119 if (TRACE_ON(dinput)) {
120 DPRINTF(" - dwObj = 0x%08x\n", diph->dwObj);
121 DPRINTF(" - dwHow = %s\n",
122 ((diph->dwHow == DIPH_DEVICE) ? "DIPH_DEVICE" :
123 ((diph->dwHow == DIPH_BYOFFSET) ? "DIPH_BYOFFSET" :
124 ((diph->dwHow == DIPH_BYID)) ? "DIPH_BYID" : "unknown")));
128 void _dump_OBJECTINSTANCEA(const DIDEVICEOBJECTINSTANCEA *ddoi) {
129 if (TRACE_ON(dinput)) {
130 DPRINTF(" - enumerating : %s ('%s') - %2d - 0x%08x - %s\n",
131 debugstr_guid(&ddoi->guidType), _dump_dinput_GUID(&ddoi->guidType), ddoi->dwOfs, ddoi->dwType, ddoi->tszName);
135 void _dump_OBJECTINSTANCEW(const DIDEVICEOBJECTINSTANCEW *ddoi) {
136 if (TRACE_ON(dinput)) {
137 DPRINTF(" - enumerating : %s ('%s'), - %2d - 0x%08x - %s\n",
138 debugstr_guid(&ddoi->guidType), _dump_dinput_GUID(&ddoi->guidType), ddoi->dwOfs, ddoi->dwType, debugstr_w(ddoi->tszName));
142 /* This function is a helper to convert a GUID into any possible DInput GUID out there */
143 const char *_dump_dinput_GUID(const GUID *guid) {
145 static const struct {
149 #define FE(x) { &x, #x}
162 FE(GUID_SysKeyboard),
164 FE(GUID_ConstantForce),
170 FE(GUID_SawtoothDown),
180 for (i = 0; i < (sizeof(guids) / sizeof(guids[0])); i++) {
181 if (IsEqualGUID(guids[i].guid, guid)) {
182 return guids[i].name;
185 return "Unknown GUID";
188 void _dump_DIDATAFORMAT(const DIDATAFORMAT *df) {
191 TRACE("Dumping DIDATAFORMAT structure:\n");
192 TRACE(" - dwSize: %d\n", df->dwSize);
193 if (df->dwSize != sizeof(DIDATAFORMAT)) {
194 WARN("Non-standard DIDATAFORMAT structure size %d\n", df->dwSize);
196 TRACE(" - dwObjsize: %d\n", df->dwObjSize);
197 if (df->dwObjSize != sizeof(DIOBJECTDATAFORMAT)) {
198 WARN("Non-standard DIOBJECTDATAFORMAT structure size %d\n", df->dwObjSize);
200 TRACE(" - dwFlags: 0x%08x (", df->dwFlags);
201 switch (df->dwFlags) {
202 case DIDF_ABSAXIS: TRACE("DIDF_ABSAXIS"); break;
203 case DIDF_RELAXIS: TRACE("DIDF_RELAXIS"); break;
204 default: TRACE("unknown"); break;
207 TRACE(" - dwDataSize: %d\n", df->dwDataSize);
208 TRACE(" - dwNumObjs: %d\n", df->dwNumObjs);
210 for (i = 0; i < df->dwNumObjs; i++) {
211 TRACE(" - Object %d:\n", i);
212 TRACE(" * GUID: %s ('%s')\n", debugstr_guid(df->rgodf[i].pguid), _dump_dinput_GUID(df->rgodf[i].pguid));
213 TRACE(" * dwOfs: %d\n", df->rgodf[i].dwOfs);
214 TRACE(" * dwType: 0x%08x\n", df->rgodf[i].dwType);
215 TRACE(" "); _dump_EnumObjects_flags(df->rgodf[i].dwType); TRACE("\n");
216 TRACE(" * dwFlags: 0x%08x\n", df->rgodf[i].dwFlags);
220 /******************************************************************************
221 * Get the default and the app-specific config keys.
223 BOOL get_app_key(HKEY *defkey, HKEY *appkey)
225 char buffer[MAX_PATH+16];
230 /* @@ Wine registry key: HKCU\Software\Wine\DirectInput */
231 if (RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\DirectInput", defkey))
234 len = GetModuleFileNameA(0, buffer, MAX_PATH);
235 if (len && len < MAX_PATH)
239 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DirectInput */
240 if (!RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey))
242 char *p, *appname = buffer;
243 if ((p = strrchr(appname, '/'))) appname = p + 1;
244 if ((p = strrchr(appname, '\\'))) appname = p + 1;
245 strcat(appname, "\\DirectInput");
247 if (RegOpenKeyA(tmpkey, appname, appkey)) *appkey = 0;
252 return *defkey || *appkey;
255 /******************************************************************************
256 * Get a config key from either the app-specific or the default config
258 DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
259 char *buffer, DWORD size )
261 if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE)buffer, &size ))
264 if (defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE)buffer, &size ))
267 return ERROR_FILE_NOT_FOUND;
270 /* Conversion between internal data buffer and external data buffer */
271 void fill_DataFormat(void *out, const void *in, const DataFormat *df) {
273 const char *in_c = in;
274 char *out_c = (char *) out;
276 if (df->dt == NULL) {
277 /* This means that the app uses Wine's internal data format */
278 memcpy(out, in, df->internal_format_size);
280 for (i = 0; i < df->size; i++) {
281 if (df->dt[i].offset_in >= 0) {
282 switch (df->dt[i].size) {
284 TRACE("Copying (c) to %d from %d (value %d)\n",
285 df->dt[i].offset_out, df->dt[i].offset_in, *(in_c + df->dt[i].offset_in));
286 *(out_c + df->dt[i].offset_out) = *(in_c + df->dt[i].offset_in);
290 TRACE("Copying (s) to %d from %d (value %d)\n",
291 df->dt[i].offset_out, df->dt[i].offset_in, *((const short *)(in_c + df->dt[i].offset_in)));
292 *((short *)(out_c + df->dt[i].offset_out)) = *((const short *)(in_c + df->dt[i].offset_in));
296 TRACE("Copying (i) to %d from %d (value %d)\n",
297 df->dt[i].offset_out, df->dt[i].offset_in, *((const int *)(in_c + df->dt[i].offset_in)));
298 *((int *)(out_c + df->dt[i].offset_out)) = *((const int *)(in_c + df->dt[i].offset_in));
302 memcpy((out_c + df->dt[i].offset_out), (in_c + df->dt[i].offset_in), df->dt[i].size);
306 switch (df->dt[i].size) {
308 TRACE("Copying (c) to %d default value %d\n",
309 df->dt[i].offset_out, df->dt[i].value);
310 *(out_c + df->dt[i].offset_out) = (char) df->dt[i].value;
314 TRACE("Copying (s) to %d default value %d\n",
315 df->dt[i].offset_out, df->dt[i].value);
316 *((short *) (out_c + df->dt[i].offset_out)) = (short) df->dt[i].value;
320 TRACE("Copying (i) to %d default value %d\n",
321 df->dt[i].offset_out, df->dt[i].value);
322 *((int *) (out_c + df->dt[i].offset_out)) = (int) df->dt[i].value;
326 memset((out_c + df->dt[i].offset_out), 0, df->dt[i].size);
334 void release_DataFormat(DataFormat * format)
336 TRACE("Deleting DataFormat: %p\n", format);
338 HeapFree(GetProcessHeap(), 0, format->dt);
340 HeapFree(GetProcessHeap(), 0, format->offsets);
341 format->offsets = NULL;
342 HeapFree(GetProcessHeap(), 0, format->user_df);
343 format->user_df = NULL;
346 inline LPDIOBJECTDATAFORMAT dataformat_to_odf(LPCDIDATAFORMAT df, int idx)
348 if (idx < 0 || idx >= df->dwNumObjs) return NULL;
349 return (LPDIOBJECTDATAFORMAT)((LPBYTE)df->rgodf + idx * df->dwObjSize);
352 HRESULT create_DataFormat(LPCDIDATAFORMAT asked_format, DataFormat *format)
361 if (!format->wine_df) return DIERR_INVALIDPARAM;
362 done = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, asked_format->dwNumObjs * sizeof(int));
363 dt = HeapAlloc(GetProcessHeap(), 0, asked_format->dwNumObjs * sizeof(DataTransform));
364 if (!dt || !done) goto failed;
366 if (!(format->offsets = HeapAlloc(GetProcessHeap(), 0, format->wine_df->dwNumObjs * sizeof(int))))
369 if (!(format->user_df = HeapAlloc(GetProcessHeap(), 0, asked_format->dwSize)))
371 memcpy(format->user_df, asked_format, asked_format->dwSize);
373 TRACE("Creating DataTransform :\n");
375 for (i = 0; i < format->wine_df->dwNumObjs; i++)
377 format->offsets[i] = -1;
379 for (j = 0; j < asked_format->dwNumObjs; j++) {
383 if (/* Check if the application either requests any GUID and if not, it if matches
384 * the GUID of the Wine object.
386 ((asked_format->rgodf[j].pguid == NULL) ||
387 (format->wine_df->rgodf[i].pguid == NULL) ||
388 (IsEqualGUID(format->wine_df->rgodf[i].pguid, asked_format->rgodf[j].pguid)))
390 (/* Then check if it accepts any instance id, and if not, if it matches Wine's
393 ((asked_format->rgodf[j].dwType & DIDFT_INSTANCEMASK) == DIDFT_ANYINSTANCE) ||
394 (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == 0x00FF) || /* This is mentionned in no DX docs, but it works fine - tested on WinXP */
395 (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == DIDFT_GETINSTANCE(format->wine_df->rgodf[i].dwType)))
397 ( /* Then if the asked type matches the one Wine provides */
398 DIDFT_GETTYPE(asked_format->rgodf[j].dwType) & format->wine_df->rgodf[i].dwType))
402 TRACE("Matching :\n");
403 TRACE(" - Asked (%d) :\n", j);
404 TRACE(" * GUID: %s ('%s')\n",
405 debugstr_guid(asked_format->rgodf[j].pguid),
406 _dump_dinput_GUID(asked_format->rgodf[j].pguid));
407 TRACE(" * Offset: %3d\n", asked_format->rgodf[j].dwOfs);
408 TRACE(" * dwType: %08x\n", asked_format->rgodf[j].dwType);
409 TRACE(" "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
411 TRACE(" - Wine (%d) :\n", i);
412 TRACE(" * GUID: %s ('%s')\n",
413 debugstr_guid(format->wine_df->rgodf[i].pguid),
414 _dump_dinput_GUID(format->wine_df->rgodf[i].pguid));
415 TRACE(" * Offset: %3d\n", format->wine_df->rgodf[i].dwOfs);
416 TRACE(" * dwType: %08x\n", format->wine_df->rgodf[i].dwType);
417 TRACE(" "); _dump_EnumObjects_flags(format->wine_df->rgodf[i].dwType); TRACE("\n");
419 if (format->wine_df->rgodf[i].dwType & DIDFT_BUTTON)
420 dt[index].size = sizeof(BYTE);
422 dt[index].size = sizeof(DWORD);
423 dt[index].offset_in = format->wine_df->rgodf[i].dwOfs;
424 dt[index].offset_out = asked_format->rgodf[j].dwOfs;
425 format->offsets[i] = asked_format->rgodf[j].dwOfs;
427 next = next + dt[index].size;
429 if (format->wine_df->rgodf[i].dwOfs != dt[index].offset_out)
437 if (j == asked_format->dwNumObjs)
441 TRACE("Setting to default value :\n");
442 for (j = 0; j < asked_format->dwNumObjs; j++) {
444 TRACE(" - Asked (%d) :\n", j);
445 TRACE(" * GUID: %s ('%s')\n",
446 debugstr_guid(asked_format->rgodf[j].pguid),
447 _dump_dinput_GUID(asked_format->rgodf[j].pguid));
448 TRACE(" * Offset: %3d\n", asked_format->rgodf[j].dwOfs);
449 TRACE(" * dwType: %08x\n", asked_format->rgodf[j].dwType);
450 TRACE(" "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
452 if (asked_format->rgodf[j].dwType & DIDFT_BUTTON)
453 dt[index].size = sizeof(BYTE);
455 dt[index].size = sizeof(DWORD);
456 dt[index].offset_in = -1;
457 dt[index].offset_out = asked_format->rgodf[j].dwOfs;
465 format->internal_format_size = format->wine_df->dwDataSize;
466 format->size = index;
468 HeapFree(GetProcessHeap(), 0, dt);
473 HeapFree(GetProcessHeap(), 0, done);
478 HeapFree(GetProcessHeap(), 0, done);
479 HeapFree(GetProcessHeap(), 0, dt);
481 HeapFree(GetProcessHeap(), 0, format->offsets);
482 format->offsets = NULL;
483 HeapFree(GetProcessHeap(), 0, format->user_df);
484 format->user_df = NULL;
486 return DIERR_OUTOFMEMORY;
489 /* find an object by it's offset in a data format */
490 static int offset_to_object(const DataFormat *df, int offset)
494 if (!df->offsets) return -1;
496 for (i = 0; i < df->wine_df->dwNumObjs; i++)
497 if (df->offsets[i] == offset) return i;
502 int id_to_object(LPCDIDATAFORMAT df, int id)
507 for (i = 0; i < df->dwNumObjs; i++)
508 if ((dataformat_to_odf(df, i)->dwType & 0x00ffffff) == id)
514 int id_to_offset(const DataFormat *df, int id)
516 int obj = id_to_object(df->wine_df, id);
518 return obj >= 0 && df->offsets ? df->offsets[obj] : -1;
521 int find_property(const DataFormat *df, LPCDIPROPHEADER ph)
525 case DIPH_BYID: return id_to_object(df->wine_df, ph->dwObj);
526 case DIPH_BYOFFSET: return offset_to_object(df, ph->dwObj);
528 FIXME("Unhandled ph->dwHow=='%04X'\n", (unsigned int)ph->dwHow);
534 BOOL DIEnumDevicesCallbackAtoW(LPCDIDEVICEOBJECTINSTANCEA lpddi, LPVOID lpvRef) {
535 DIDEVICEOBJECTINSTANCEW ddtmp;
536 device_enumobjects_AtoWcb_data* data;
538 data = (device_enumobjects_AtoWcb_data*) lpvRef;
540 memset(&ddtmp, 0, sizeof(ddtmp));
542 ddtmp.dwSize = sizeof(DIDEVICEINSTANCEW);
543 ddtmp.guidType = lpddi->guidType;
544 ddtmp.dwOfs = lpddi->dwOfs;
545 ddtmp.dwType = lpddi->dwType;
546 ddtmp.dwFlags = lpddi->dwFlags;
547 MultiByteToWideChar(CP_ACP, 0, lpddi->tszName, -1, ddtmp.tszName, MAX_PATH);
549 if (lpddi->dwSize == sizeof(DIDEVICEINSTANCEA)) {
551 * if dwSize < sizeof(DIDEVICEINSTANCEA of DInput version >= 5)
552 * force feedback and other newer datas aren't available
554 ddtmp.dwFFMaxForce = lpddi->dwFFMaxForce;
555 ddtmp.dwFFForceResolution = lpddi->dwFFForceResolution;
556 ddtmp.wCollectionNumber = lpddi->wCollectionNumber;
557 ddtmp.wDesignatorIndex = lpddi->wDesignatorIndex;
558 ddtmp.wUsagePage = lpddi->wUsagePage;
559 ddtmp.wUsage = lpddi->wUsage;
560 ddtmp.dwDimension = lpddi->dwDimension;
561 ddtmp.wExponent = lpddi->wExponent;
562 ddtmp.wReserved = lpddi->wReserved;
564 return data->lpCallBack(&ddtmp, data->lpvRef);
567 /******************************************************************************
568 * queue_event - add new event to the ring queue
571 void queue_event(LPDIRECTINPUTDEVICE8A iface, int ofs, DWORD data, DWORD time, DWORD seq)
573 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
576 /* Event is being set regardless of the queue state */
577 if (This->hEvent) SetEvent(This->hEvent);
579 if (!This->queue_len || This->overflow || ofs < 0) return;
581 next_pos = (This->queue_head + 1) % This->queue_len;
582 if (next_pos == This->queue_tail)
584 TRACE(" queue overflowed\n");
585 This->overflow = TRUE;
589 TRACE(" queueing %d at offset %d (queue head %d / size %d)\n",
590 data, ofs, This->queue_head, This->queue_len);
592 This->data_queue[This->queue_head].dwOfs = ofs;
593 This->data_queue[This->queue_head].dwData = data;
594 This->data_queue[This->queue_head].dwTimeStamp = time;
595 This->data_queue[This->queue_head].dwSequence = seq;
596 This->queue_head = next_pos;
597 /* Send event if asked */
600 /******************************************************************************
604 HRESULT WINAPI IDirectInputDevice2AImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
606 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
609 if (!This->data_format.user_df) return DIERR_INVALIDPARAM;
610 if (This->dwCoopLevel & DISCL_FOREGROUND && This->win != GetForegroundWindow())
611 return DIERR_OTHERAPPHASPRIO;
613 EnterCriticalSection(&This->crit);
614 res = This->acquired ? S_FALSE : DI_OK;
618 This->queue_head = This->queue_tail = This->overflow = 0;
619 check_dinput_hooks(iface);
621 LeaveCriticalSection(&This->crit);
626 /******************************************************************************
630 HRESULT WINAPI IDirectInputDevice2AImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
632 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
635 EnterCriticalSection(&This->crit);
636 res = !This->acquired ? DI_NOEFFECT : DI_OK;
639 check_dinput_hooks(iface);
640 LeaveCriticalSection(&This->crit);
645 /******************************************************************************
646 * IDirectInputDeviceA
649 HRESULT WINAPI IDirectInputDevice2AImpl_SetDataFormat(
650 LPDIRECTINPUTDEVICE8A iface, LPCDIDATAFORMAT df)
652 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
655 if (!df) return E_POINTER;
656 TRACE("(%p) %p\n", This, df);
657 _dump_DIDATAFORMAT(df);
659 if (df->dwSize != sizeof(DIDATAFORMAT)) return DIERR_INVALIDPARAM;
660 if (This->acquired) return DIERR_ACQUIRED;
662 EnterCriticalSection(&This->crit);
664 release_DataFormat(&This->data_format);
665 res = create_DataFormat(df, &This->data_format);
667 LeaveCriticalSection(&This->crit);
671 /******************************************************************************
672 * SetCooperativeLevel
674 * Set cooperative level and the source window for the events.
676 HRESULT WINAPI IDirectInputDevice2AImpl_SetCooperativeLevel(
677 LPDIRECTINPUTDEVICE8A iface, HWND hwnd, DWORD dwflags)
679 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
681 TRACE("(%p) %p,0x%08x\n", This, hwnd, dwflags);
682 TRACE(" cooperative level : ");
683 _dump_cooperativelevel_DI(dwflags);
685 if ((dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == 0 ||
686 (dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE) ||
687 (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == 0 ||
688 (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == (DISCL_FOREGROUND | DISCL_BACKGROUND))
689 return DIERR_INVALIDPARAM;
691 if (dwflags == (DISCL_NONEXCLUSIVE | DISCL_BACKGROUND))
692 hwnd = GetDesktopWindow();
694 if (!hwnd) return E_HANDLE;
696 /* For security reasons native does not allow exclusive background level
697 for mouse and keyboard only */
698 if (dwflags & DISCL_EXCLUSIVE && dwflags & DISCL_BACKGROUND &&
699 (IsEqualGUID(&This->guid, &GUID_SysMouse) ||
700 IsEqualGUID(&This->guid, &GUID_SysKeyboard)))
701 return DIERR_UNSUPPORTED;
703 /* Store the window which asks for the mouse */
704 EnterCriticalSection(&This->crit);
706 This->dwCoopLevel = dwflags;
707 LeaveCriticalSection(&This->crit);
712 /******************************************************************************
713 * SetEventNotification : specifies event to be sent on state change
715 HRESULT WINAPI IDirectInputDevice2AImpl_SetEventNotification(
716 LPDIRECTINPUTDEVICE8A iface, HANDLE event)
718 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
720 TRACE("(%p) %p\n", This, event);
722 EnterCriticalSection(&This->crit);
723 This->hEvent = event;
724 LeaveCriticalSection(&This->crit);
728 ULONG WINAPI IDirectInputDevice2AImpl_Release(LPDIRECTINPUTDEVICE8A iface)
730 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
733 ref = InterlockedDecrement(&(This->ref));
736 IDirectInputDevice_Unacquire(iface);
737 /* Reset the FF state, free all effects, etc */
738 IDirectInputDevice8_SendForceFeedbackCommand(iface, DISFFC_RESET);
740 HeapFree(GetProcessHeap(), 0, This->data_queue);
742 /* Free data format */
743 HeapFree(GetProcessHeap(), 0, This->data_format.wine_df->rgodf);
744 HeapFree(GetProcessHeap(), 0, This->data_format.wine_df);
745 release_DataFormat(&This->data_format);
747 EnterCriticalSection( &This->dinput->crit );
748 list_remove( &This->entry );
749 LeaveCriticalSection( &This->dinput->crit );
751 IDirectInput_Release((LPDIRECTINPUTDEVICE8A)This->dinput);
752 This->crit.DebugInfo->Spare[0] = 0;
753 DeleteCriticalSection(&This->crit);
755 HeapFree(GetProcessHeap(), 0, This);
760 HRESULT WINAPI IDirectInputDevice2AImpl_QueryInterface(
761 LPDIRECTINPUTDEVICE8A iface,REFIID riid,LPVOID *ppobj
764 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
766 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
767 if (IsEqualGUID(&IID_IUnknown,riid)) {
768 IDirectInputDevice2_AddRef(iface);
772 if (IsEqualGUID(&IID_IDirectInputDeviceA,riid)) {
773 IDirectInputDevice2_AddRef(iface);
777 if (IsEqualGUID(&IID_IDirectInputDevice2A,riid)) {
778 IDirectInputDevice2_AddRef(iface);
782 if (IsEqualGUID(&IID_IDirectInputDevice7A,riid)) {
783 IDirectInputDevice7_AddRef(iface);
787 if (IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
788 IDirectInputDevice8_AddRef(iface);
792 TRACE("Unsupported interface !\n");
796 HRESULT WINAPI IDirectInputDevice2WImpl_QueryInterface(
797 LPDIRECTINPUTDEVICE8W iface,REFIID riid,LPVOID *ppobj
800 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
802 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
803 if (IsEqualGUID(&IID_IUnknown,riid)) {
804 IDirectInputDevice2_AddRef(iface);
808 if (IsEqualGUID(&IID_IDirectInputDeviceW,riid)) {
809 IDirectInputDevice2_AddRef(iface);
813 if (IsEqualGUID(&IID_IDirectInputDevice2W,riid)) {
814 IDirectInputDevice2_AddRef(iface);
818 if (IsEqualGUID(&IID_IDirectInputDevice7W,riid)) {
819 IDirectInputDevice7_AddRef(iface);
823 if (IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
824 IDirectInputDevice8_AddRef(iface);
828 TRACE("Unsupported interface !\n");
832 ULONG WINAPI IDirectInputDevice2AImpl_AddRef(
833 LPDIRECTINPUTDEVICE8A iface)
835 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
836 return InterlockedIncrement(&(This->ref));
839 HRESULT WINAPI IDirectInputDevice2AImpl_EnumObjects(LPDIRECTINPUTDEVICE8A iface,
840 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback, LPVOID lpvRef, DWORD dwFlags)
842 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
843 DIDEVICEOBJECTINSTANCEA ddoi;
846 TRACE("(%p) %p,%p flags:%08x)\n", iface, lpCallback, lpvRef, dwFlags);
847 TRACE(" - flags = ");
848 _dump_EnumObjects_flags(dwFlags);
851 /* Only the fields till dwFFMaxForce are relevant */
852 memset(&ddoi, 0, sizeof(ddoi));
853 ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce);
855 for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++)
857 LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(This->data_format.wine_df, i);
859 if (dwFlags != DIDFT_ALL && !(dwFlags & DIEFT_GETTYPE(odf->dwType))) continue;
860 if (IDirectInputDevice_GetObjectInfo(iface, &ddoi, odf->dwType, DIPH_BYID) != DI_OK)
863 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) break;
869 HRESULT WINAPI IDirectInputDevice2WImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface,
870 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback, LPVOID lpvRef, DWORD dwFlags)
872 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
873 DIDEVICEOBJECTINSTANCEW ddoi;
876 TRACE("(%p) %p,%p flags:%08x)\n", iface, lpCallback, lpvRef, dwFlags);
877 TRACE(" - flags = ");
878 _dump_EnumObjects_flags(dwFlags);
881 /* Only the fields till dwFFMaxForce are relevant */
882 memset(&ddoi, 0, sizeof(ddoi));
883 ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEW, dwFFMaxForce);
885 for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++)
887 LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(This->data_format.wine_df, i);
889 if (dwFlags != DIDFT_ALL && !(dwFlags & DIEFT_GETTYPE(odf->dwType))) continue;
890 if (IDirectInputDevice_GetObjectInfo(iface, &ddoi, odf->dwType, DIPH_BYID) != DI_OK)
893 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) break;
899 /******************************************************************************
903 HRESULT WINAPI IDirectInputDevice2AImpl_GetProperty(
904 LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPDIPROPHEADER pdiph)
906 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
908 TRACE("(%p) %s,%p\n", iface, debugstr_guid(rguid), pdiph);
909 _dump_DIPROPHEADER(pdiph);
911 if (HIWORD(rguid)) return DI_OK;
913 switch (LOWORD(rguid))
915 case (DWORD) DIPROP_BUFFERSIZE:
917 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
919 if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
921 pd->dwData = This->queue_len;
922 TRACE("buffersize = %d\n", pd->dwData);
926 WARN("Unknown property %s\n", debugstr_guid(rguid));
933 /******************************************************************************
937 HRESULT WINAPI IDirectInputDevice2AImpl_SetProperty(
938 LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPCDIPROPHEADER pdiph)
940 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
942 TRACE("(%p) %s,%p\n", iface, debugstr_guid(rguid), pdiph);
943 _dump_DIPROPHEADER(pdiph);
945 if (HIWORD(rguid)) return DI_OK;
947 switch (LOWORD(rguid))
949 case (DWORD) DIPROP_AXISMODE:
951 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph;
953 if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
954 if (pdiph->dwHow == DIPH_DEVICE && pdiph->dwObj) return DIERR_INVALIDPARAM;
955 if (This->acquired) return DIERR_ACQUIRED;
956 if (pdiph->dwHow != DIPH_DEVICE) return DIERR_UNSUPPORTED;
957 if (!This->data_format.user_df) return DI_OK;
959 TRACE("Axis mode: %s\n", pd->dwData == DIPROPAXISMODE_ABS ? "absolute" :
962 EnterCriticalSection(&This->crit);
963 This->data_format.user_df->dwFlags &= ~DIDFT_AXIS;
964 This->data_format.user_df->dwFlags |= pd->dwData == DIPROPAXISMODE_ABS ?
965 DIDF_ABSAXIS : DIDF_RELAXIS;
966 LeaveCriticalSection(&This->crit);
969 case (DWORD) DIPROP_BUFFERSIZE:
971 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph;
973 if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
974 if (This->acquired) return DIERR_ACQUIRED;
976 TRACE("buffersize = %d\n", pd->dwData);
978 EnterCriticalSection(&This->crit);
979 HeapFree(GetProcessHeap(), 0, This->data_queue);
981 This->data_queue = !pd->dwData ? NULL : HeapAlloc(GetProcessHeap(), 0,
982 pd->dwData * sizeof(DIDEVICEOBJECTDATA));
983 This->queue_head = This->queue_tail = This->overflow = 0;
984 This->queue_len = pd->dwData;
986 LeaveCriticalSection(&This->crit);
990 WARN("Unknown property %s\n", debugstr_guid(rguid));
991 return DIERR_UNSUPPORTED;
997 HRESULT WINAPI IDirectInputDevice2AImpl_GetObjectInfo(
998 LPDIRECTINPUTDEVICE8A iface,
999 LPDIDEVICEOBJECTINSTANCEA pdidoi,
1003 DIDEVICEOBJECTINSTANCEW didoiW;
1007 (pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCEA) &&
1008 pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCE_DX3A)))
1009 return DIERR_INVALIDPARAM;
1011 didoiW.dwSize = sizeof(didoiW);
1012 res = IDirectInputDevice2WImpl_GetObjectInfo((LPDIRECTINPUTDEVICE8W)iface, &didoiW, dwObj, dwHow);
1015 DWORD dwSize = pdidoi->dwSize;
1017 memset(pdidoi, 0, pdidoi->dwSize);
1018 pdidoi->dwSize = dwSize;
1019 pdidoi->guidType = didoiW.guidType;
1020 pdidoi->dwOfs = didoiW.dwOfs;
1021 pdidoi->dwType = didoiW.dwType;
1022 pdidoi->dwFlags = didoiW.dwFlags;
1028 HRESULT WINAPI IDirectInputDevice2WImpl_GetObjectInfo(
1029 LPDIRECTINPUTDEVICE8W iface,
1030 LPDIDEVICEOBJECTINSTANCEW pdidoi,
1034 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
1036 LPDIOBJECTDATAFORMAT odf;
1039 TRACE("(%p) %d(0x%08x) -> %p\n", This, dwHow, dwObj, pdidoi);
1042 (pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCEW) &&
1043 pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCE_DX3W)))
1044 return DIERR_INVALIDPARAM;
1049 if (!This->data_format.offsets) break;
1050 for (idx = This->data_format.wine_df->dwNumObjs - 1; idx >= 0; idx--)
1051 if (This->data_format.offsets[idx] == dwObj) break;
1054 dwObj &= 0x00ffffff;
1055 for (idx = This->data_format.wine_df->dwNumObjs - 1; idx >= 0; idx--)
1056 if ((dataformat_to_odf(This->data_format.wine_df, idx)->dwType & 0x00ffffff) == dwObj)
1061 FIXME("dwHow = DIPH_BYUSAGE not implemented\n");
1064 WARN("invalid parameter: dwHow = %08x\n", dwHow);
1065 return DIERR_INVALIDPARAM;
1067 if (idx < 0) return DIERR_OBJECTNOTFOUND;
1069 odf = dataformat_to_odf(This->data_format.wine_df, idx);
1070 dwSize = pdidoi->dwSize; /* save due to memset below */
1071 memset(pdidoi, 0, pdidoi->dwSize);
1072 pdidoi->dwSize = dwSize;
1073 if (odf->pguid) pdidoi->guidType = *odf->pguid;
1074 pdidoi->dwOfs = This->data_format.offsets ? This->data_format.offsets[idx] : odf->dwOfs;
1075 pdidoi->dwType = odf->dwType;
1076 pdidoi->dwFlags = odf->dwFlags;
1081 HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceData(
1082 LPDIRECTINPUTDEVICE8A iface, DWORD dodsize, LPDIDEVICEOBJECTDATA dod,
1083 LPDWORD entries, DWORD flags)
1085 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
1086 HRESULT ret = DI_OK;
1089 TRACE("(%p) %p -> %p(%d) x%d, 0x%08x\n",
1090 This, dod, entries, entries ? *entries : 0, dodsize, flags);
1092 if (!This->acquired)
1093 return DIERR_NOTACQUIRED;
1094 if (!This->queue_len)
1095 return DIERR_NOTBUFFERED;
1096 if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3))
1097 return DIERR_INVALIDPARAM;
1099 IDirectInputDevice2_Poll(iface);
1100 EnterCriticalSection(&This->crit);
1102 len = This->queue_head - This->queue_tail;
1103 if (len < 0) len += This->queue_len;
1105 if ((*entries != INFINITE) && (len > *entries)) len = *entries;
1110 for (i = 0; i < len; i++)
1112 int n = (This->queue_tail + i) % This->queue_len;
1113 memcpy((char *)dod + dodsize * i, This->data_queue + n, dodsize);
1119 ret = DI_BUFFEROVERFLOW;
1121 if (!(flags & DIGDD_PEEK))
1123 /* Advance reading position */
1124 This->queue_tail = (This->queue_tail + len) % This->queue_len;
1125 This->overflow = FALSE;
1128 LeaveCriticalSection(&This->crit);
1130 TRACE("Returning %d events queued\n", *entries);
1134 HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceInfo(
1135 LPDIRECTINPUTDEVICE8A iface,
1136 LPDIDEVICEINSTANCEA pdidi)
1138 FIXME("(this=%p,%p): stub!\n",
1144 HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceInfo(
1145 LPDIRECTINPUTDEVICE8W iface,
1146 LPDIDEVICEINSTANCEW pdidi)
1148 FIXME("(this=%p,%p): stub!\n",
1154 HRESULT WINAPI IDirectInputDevice2AImpl_RunControlPanel(
1155 LPDIRECTINPUTDEVICE8A iface,
1159 FIXME("(this=%p,%p,0x%08x): stub!\n",
1160 iface, hwndOwner, dwFlags);
1165 HRESULT WINAPI IDirectInputDevice2AImpl_Initialize(
1166 LPDIRECTINPUTDEVICE8A iface,
1171 FIXME("(this=%p,%p,%d,%s): stub!\n",
1172 iface, hinst, dwVersion, debugstr_guid(rguid));
1176 /******************************************************************************
1177 * IDirectInputDevice2A
1180 HRESULT WINAPI IDirectInputDevice2AImpl_CreateEffect(
1181 LPDIRECTINPUTDEVICE8A iface,
1184 LPDIRECTINPUTEFFECT *ppdef,
1185 LPUNKNOWN pUnkOuter)
1187 FIXME("(this=%p,%s,%p,%p,%p): stub!\n",
1188 iface, debugstr_guid(rguid), lpeff, ppdef, pUnkOuter);
1192 HRESULT WINAPI IDirectInputDevice2AImpl_EnumEffects(
1193 LPDIRECTINPUTDEVICE8A iface,
1194 LPDIENUMEFFECTSCALLBACKA lpCallback,
1198 FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1199 iface, lpCallback, lpvRef, dwFlags);
1204 HRESULT WINAPI IDirectInputDevice2WImpl_EnumEffects(
1205 LPDIRECTINPUTDEVICE8W iface,
1206 LPDIENUMEFFECTSCALLBACKW lpCallback,
1210 FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1211 iface, lpCallback, lpvRef, dwFlags);
1216 HRESULT WINAPI IDirectInputDevice2AImpl_GetEffectInfo(
1217 LPDIRECTINPUTDEVICE8A iface,
1218 LPDIEFFECTINFOA lpdei,
1221 FIXME("(this=%p,%p,%s): stub!\n",
1222 iface, lpdei, debugstr_guid(rguid));
1226 HRESULT WINAPI IDirectInputDevice2WImpl_GetEffectInfo(
1227 LPDIRECTINPUTDEVICE8W iface,
1228 LPDIEFFECTINFOW lpdei,
1231 FIXME("(this=%p,%p,%s): stub!\n",
1232 iface, lpdei, debugstr_guid(rguid));
1236 HRESULT WINAPI IDirectInputDevice2AImpl_GetForceFeedbackState(
1237 LPDIRECTINPUTDEVICE8A iface,
1240 FIXME("(this=%p,%p): stub!\n",
1245 HRESULT WINAPI IDirectInputDevice2AImpl_SendForceFeedbackCommand(
1246 LPDIRECTINPUTDEVICE8A iface,
1249 TRACE("(%p) 0x%08x:\n", iface, dwFlags);
1253 HRESULT WINAPI IDirectInputDevice2AImpl_EnumCreatedEffectObjects(
1254 LPDIRECTINPUTDEVICE8A iface,
1255 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback,
1259 FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1260 iface, lpCallback, lpvRef, dwFlags);
1264 HRESULT WINAPI IDirectInputDevice2AImpl_Escape(
1265 LPDIRECTINPUTDEVICE8A iface,
1266 LPDIEFFESCAPE lpDIEEsc)
1268 FIXME("(this=%p,%p): stub!\n",
1273 HRESULT WINAPI IDirectInputDevice2AImpl_Poll(
1274 LPDIRECTINPUTDEVICE8A iface)
1276 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
1278 if (!This->acquired) return DIERR_NOTACQUIRED;
1279 /* Because wine devices do not need to be polled, just return DI_NOEFFECT */
1283 HRESULT WINAPI IDirectInputDevice2AImpl_SendDeviceData(
1284 LPDIRECTINPUTDEVICE8A iface,
1286 LPCDIDEVICEOBJECTDATA rgdod,
1290 FIXME("(this=%p,0x%08x,%p,%p,0x%08x): stub!\n",
1291 iface, cbObjectData, rgdod, pdwInOut, dwFlags);
1296 HRESULT WINAPI IDirectInputDevice7AImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8A iface,
1297 LPCSTR lpszFileName,
1298 LPDIENUMEFFECTSINFILECALLBACK pec,
1302 FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", iface, lpszFileName, pec, pvRef, dwFlags);
1307 HRESULT WINAPI IDirectInputDevice7WImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8W iface,
1308 LPCWSTR lpszFileName,
1309 LPDIENUMEFFECTSINFILECALLBACK pec,
1313 FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", iface, debugstr_w(lpszFileName), pec, pvRef, dwFlags);
1318 HRESULT WINAPI IDirectInputDevice7AImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8A iface,
1319 LPCSTR lpszFileName,
1321 LPDIFILEEFFECT rgDiFileEft,
1324 FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", iface, lpszFileName, dwEntries, rgDiFileEft, dwFlags);
1329 HRESULT WINAPI IDirectInputDevice7WImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8W iface,
1330 LPCWSTR lpszFileName,
1332 LPDIFILEEFFECT rgDiFileEft,
1335 FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", iface, debugstr_w(lpszFileName), dwEntries, rgDiFileEft, dwFlags);
1340 HRESULT WINAPI IDirectInputDevice8AImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface,
1341 LPDIACTIONFORMATA lpdiaf,
1342 LPCSTR lpszUserName,
1345 FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, lpszUserName, dwFlags);
1350 HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface,
1351 LPDIACTIONFORMATW lpdiaf,
1352 LPCWSTR lpszUserName,
1355 FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
1360 HRESULT WINAPI IDirectInputDevice8AImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface,
1361 LPDIACTIONFORMATA lpdiaf,
1362 LPCSTR lpszUserName,
1365 FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, lpszUserName, dwFlags);
1370 HRESULT WINAPI IDirectInputDevice8WImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
1371 LPDIACTIONFORMATW lpdiaf,
1372 LPCWSTR lpszUserName,
1375 FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
1380 HRESULT WINAPI IDirectInputDevice8AImpl_GetImageInfo(LPDIRECTINPUTDEVICE8A iface,
1381 LPDIDEVICEIMAGEINFOHEADERA lpdiDevImageInfoHeader)
1383 FIXME("(%p)->(%p): stub !\n", iface, lpdiDevImageInfoHeader);
1388 HRESULT WINAPI IDirectInputDevice8WImpl_GetImageInfo(LPDIRECTINPUTDEVICE8W iface,
1389 LPDIDEVICEIMAGEINFOHEADERW lpdiDevImageInfoHeader)
1391 FIXME("(%p)->(%p): stub !\n", iface, lpdiDevImageInfoHeader);