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"
38 #include "device_private.h"
39 #include "dinput_private.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
43 /******************************************************************************
44 * Various debugging tools
46 void _dump_cooperativelevel_DI(DWORD dwFlags) {
47 if (TRACE_ON(dinput)) {
53 #define FE(x) { x, #x}
57 FE(DISCL_NONEXCLUSIVE),
61 for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++)
62 if (flags[i].mask & dwFlags)
63 DPRINTF("%s ",flags[i].name);
68 void _dump_EnumObjects_flags(DWORD dwFlags) {
69 if (TRACE_ON(dinput)) {
76 #define FE(x) { x, #x}
85 FE(DIDFT_FFEFFECTTRIGGER),
87 FE(DIDFT_VENDORDEFINED),
92 type = (dwFlags & 0xFF0000FF);
93 instance = ((dwFlags >> 8) & 0xFFFF);
95 if (type == DIDFT_ALL) {
96 DPRINTF(" DIDFT_ALL");
98 for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++) {
99 if (flags[i].mask & type) {
100 type &= ~flags[i].mask;
101 DPRINTF(" %s",flags[i].name);
105 DPRINTF(" (unhandled: %08x)", type);
108 DPRINTF(" / Instance: ");
109 if (instance == ((DIDFT_ANYINSTANCE >> 8) & 0xFFFF)) {
110 DPRINTF("DIDFT_ANYINSTANCE");
112 DPRINTF("%3d", instance);
117 void _dump_DIPROPHEADER(LPCDIPROPHEADER diph) {
118 if (TRACE_ON(dinput)) {
119 DPRINTF(" - dwObj = 0x%08x\n", diph->dwObj);
120 DPRINTF(" - dwHow = %s\n",
121 ((diph->dwHow == DIPH_DEVICE) ? "DIPH_DEVICE" :
122 ((diph->dwHow == DIPH_BYOFFSET) ? "DIPH_BYOFFSET" :
123 ((diph->dwHow == DIPH_BYID)) ? "DIPH_BYID" : "unknown")));
127 void _dump_OBJECTINSTANCEA(DIDEVICEOBJECTINSTANCEA *ddoi) {
128 if (TRACE_ON(dinput)) {
129 DPRINTF(" - enumerating : %s ('%s') - %2d - 0x%08x - %s\n",
130 debugstr_guid(&ddoi->guidType), _dump_dinput_GUID(&ddoi->guidType), ddoi->dwOfs, ddoi->dwType, ddoi->tszName);
134 void _dump_OBJECTINSTANCEW(DIDEVICEOBJECTINSTANCEW *ddoi) {
135 if (TRACE_ON(dinput)) {
136 DPRINTF(" - enumerating : %s ('%s'), - %2d - 0x%08x - %s\n",
137 debugstr_guid(&ddoi->guidType), _dump_dinput_GUID(&ddoi->guidType), ddoi->dwOfs, ddoi->dwType, debugstr_w(ddoi->tszName));
141 /* This function is a helper to convert a GUID into any possible DInput GUID out there */
142 const char *_dump_dinput_GUID(const GUID *guid) {
144 static const struct {
148 #define FE(x) { &x, #x}
161 FE(GUID_SysKeyboard),
163 FE(GUID_ConstantForce),
169 FE(GUID_SawtoothDown),
179 for (i = 0; i < (sizeof(guids) / sizeof(guids[0])); i++) {
180 if (IsEqualGUID(guids[i].guid, guid)) {
181 return guids[i].name;
184 return "Unknown GUID";
187 void _dump_DIDATAFORMAT(const DIDATAFORMAT *df) {
190 TRACE("Dumping DIDATAFORMAT structure:\n");
191 TRACE(" - dwSize: %d\n", df->dwSize);
192 if (df->dwSize != sizeof(DIDATAFORMAT)) {
193 WARN("Non-standard DIDATAFORMAT structure size %d\n", df->dwSize);
195 TRACE(" - dwObjsize: %d\n", df->dwObjSize);
196 if (df->dwObjSize != sizeof(DIOBJECTDATAFORMAT)) {
197 WARN("Non-standard DIOBJECTDATAFORMAT structure size %d\n", df->dwObjSize);
199 TRACE(" - dwFlags: 0x%08x (", df->dwFlags);
200 switch (df->dwFlags) {
201 case DIDF_ABSAXIS: TRACE("DIDF_ABSAXIS"); break;
202 case DIDF_RELAXIS: TRACE("DIDF_RELAXIS"); break;
203 default: TRACE("unknown"); break;
206 TRACE(" - dwDataSize: %d\n", df->dwDataSize);
207 TRACE(" - dwNumObjs: %d\n", df->dwNumObjs);
209 for (i = 0; i < df->dwNumObjs; i++) {
210 TRACE(" - Object %d:\n", i);
211 TRACE(" * GUID: %s ('%s')\n", debugstr_guid(df->rgodf[i].pguid), _dump_dinput_GUID(df->rgodf[i].pguid));
212 TRACE(" * dwOfs: %d\n", df->rgodf[i].dwOfs);
213 TRACE(" * dwType: 0x%08x\n", df->rgodf[i].dwType);
214 TRACE(" "); _dump_EnumObjects_flags(df->rgodf[i].dwType); TRACE("\n");
215 TRACE(" * dwFlags: 0x%08x\n", df->rgodf[i].dwFlags);
219 /* Conversion between internal data buffer and external data buffer */
220 void fill_DataFormat(void *out, const void *in, DataFormat *df) {
222 const char *in_c = in;
223 char *out_c = (char *) out;
225 if (df->dt == NULL) {
226 /* This means that the app uses Wine's internal data format */
227 memcpy(out, in, df->internal_format_size);
229 for (i = 0; i < df->size; i++) {
230 if (df->dt[i].offset_in >= 0) {
231 switch (df->dt[i].size) {
233 TRACE("Copying (c) to %d from %d (value %d)\n",
234 df->dt[i].offset_out, df->dt[i].offset_in, *(in_c + df->dt[i].offset_in));
235 *(out_c + df->dt[i].offset_out) = *(in_c + df->dt[i].offset_in);
239 TRACE("Copying (s) to %d from %d (value %d)\n",
240 df->dt[i].offset_out, df->dt[i].offset_in, *((const short *)(in_c + df->dt[i].offset_in)));
241 *((short *)(out_c + df->dt[i].offset_out)) = *((const short *)(in_c + df->dt[i].offset_in));
245 TRACE("Copying (i) to %d from %d (value %d)\n",
246 df->dt[i].offset_out, df->dt[i].offset_in, *((const int *)(in_c + df->dt[i].offset_in)));
247 *((int *)(out_c + df->dt[i].offset_out)) = *((const int *)(in_c + df->dt[i].offset_in));
251 memcpy((out_c + df->dt[i].offset_out), (in_c + df->dt[i].offset_in), df->dt[i].size);
255 switch (df->dt[i].size) {
257 TRACE("Copying (c) to %d default value %d\n",
258 df->dt[i].offset_out, df->dt[i].value);
259 *(out_c + df->dt[i].offset_out) = (char) df->dt[i].value;
263 TRACE("Copying (s) to %d default value %d\n",
264 df->dt[i].offset_out, df->dt[i].value);
265 *((short *) (out_c + df->dt[i].offset_out)) = (short) df->dt[i].value;
269 TRACE("Copying (i) to %d default value %d\n",
270 df->dt[i].offset_out, df->dt[i].value);
271 *((int *) (out_c + df->dt[i].offset_out)) = (int) df->dt[i].value;
275 memset((out_c + df->dt[i].offset_out), 0, df->dt[i].size);
283 void release_DataFormat(DataFormat * format)
285 TRACE("Deleting DataTransform :\n");
287 HeapFree(GetProcessHeap(), 0, format->dt);
290 /* Make all instances sequential */
291 static void calculate_ids(LPDIDATAFORMAT df)
293 int i, axis = 0, pov = 0, button = 0;
294 int axis_base, pov_base, button_base;
297 /* Make two passes over the format. The first counts the number
298 * for each type and the second sets the id */
299 for (i = 0; i < df->dwNumObjs; i++)
301 type = DIDFT_GETTYPE(df->rgodf[i].dwType);
302 if (type & DIDFT_AXIS) axis++;
303 else if (type & DIDFT_POV) pov++;
304 else if (type & DIDFT_BUTTON) button++;
308 pov_base = axis_base + axis;
309 button_base = pov_base + pov;
310 axis = pov = button = 0;
312 for (i = 0; i < df->dwNumObjs; i++)
314 type = DIDFT_GETTYPE(df->rgodf[i].dwType);
315 if (type & DIDFT_AXIS)
317 type |= DIDFT_MAKEINSTANCE(axis_base + axis++);
318 TRACE("axis type = 0x%08x\n", type);
319 } else if (type & DIDFT_POV)
321 type |= DIDFT_MAKEINSTANCE(pov_base + pov++);
322 TRACE("POV type = 0x%08x\n", type);
323 } else if (type & DIDFT_BUTTON)
325 type |= DIDFT_MAKEINSTANCE(button_base + button++);
326 TRACE("button type = 0x%08x\n", type);
328 df->rgodf[i].dwType = type;
332 DataFormat *create_DataFormat(LPCDIDATAFORMAT wine_format, LPDIDATAFORMAT asked_format, int *offset)
342 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(DataFormat));
344 done = HeapAlloc(GetProcessHeap(), 0, sizeof(int) * asked_format->dwNumObjs);
345 memset(done, 0, sizeof(int) * asked_format->dwNumObjs);
347 dt = HeapAlloc(GetProcessHeap(), 0, asked_format->dwNumObjs * sizeof(DataTransform));
349 TRACE("Creating DataTransform :\n");
351 for (i = 0; i < wine_format->dwNumObjs; i++) {
354 for (j = 0; j < asked_format->dwNumObjs; j++) {
358 if (/* Check if the application either requests any GUID and if not, it if matches
359 * the GUID of the Wine object.
361 ((asked_format->rgodf[j].pguid == NULL) ||
362 (wine_format->rgodf[i].pguid == NULL) ||
363 (IsEqualGUID(wine_format->rgodf[i].pguid, asked_format->rgodf[j].pguid)))
365 (/* Then check if it accepts any instance id, and if not, if it matches Wine's
368 (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == 0xFFFF) ||
369 (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == 0x00FF) || /* This is mentionned in no DX docs, but it works fine - tested on WinXP */
370 (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == DIDFT_GETINSTANCE(wine_format->rgodf[i].dwType)))
372 ( /* Then if the asked type matches the one Wine provides */
373 DIDFT_GETTYPE(asked_format->rgodf[j].dwType) & wine_format->rgodf[i].dwType))
377 TRACE("Matching :\n");
378 TRACE(" - Asked (%d) :\n", j);
379 TRACE(" * GUID: %s ('%s')\n",
380 debugstr_guid(asked_format->rgodf[j].pguid),
381 _dump_dinput_GUID(asked_format->rgodf[j].pguid));
382 TRACE(" * Offset: %3d\n", asked_format->rgodf[j].dwOfs);
383 TRACE(" * dwType: %08x\n", asked_format->rgodf[j].dwType);
384 TRACE(" "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
386 TRACE(" - Wine (%d) :\n", i);
387 TRACE(" * GUID: %s ('%s')\n",
388 debugstr_guid(wine_format->rgodf[i].pguid),
389 _dump_dinput_GUID(wine_format->rgodf[i].pguid));
390 TRACE(" * Offset: %3d\n", wine_format->rgodf[i].dwOfs);
391 TRACE(" * dwType: %08x\n", wine_format->rgodf[i].dwType);
392 TRACE(" "); _dump_EnumObjects_flags(wine_format->rgodf[i].dwType); TRACE("\n");
394 if (wine_format->rgodf[i].dwType & DIDFT_BUTTON)
395 dt[index].size = sizeof(BYTE);
397 dt[index].size = sizeof(DWORD);
398 dt[index].offset_in = wine_format->rgodf[i].dwOfs;
399 dt[index].offset_out = asked_format->rgodf[j].dwOfs;
400 offset[i] = asked_format->rgodf[j].dwOfs;
402 next = next + dt[index].size;
404 if (wine_format->rgodf[i].dwOfs != dt[index].offset_out)
412 if (j == asked_format->dwNumObjs)
416 TRACE("Setting to default value :\n");
417 for (j = 0; j < asked_format->dwNumObjs; j++) {
419 TRACE(" - Asked (%d) :\n", j);
420 TRACE(" * GUID: %s ('%s')\n",
421 debugstr_guid(asked_format->rgodf[j].pguid),
422 _dump_dinput_GUID(asked_format->rgodf[j].pguid));
423 TRACE(" * Offset: %3d\n", asked_format->rgodf[j].dwOfs);
424 TRACE(" * dwType: %08x\n", asked_format->rgodf[j].dwType);
425 TRACE(" "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
427 if (asked_format->rgodf[j].dwType & DIDFT_BUTTON)
428 dt[index].size = sizeof(BYTE);
430 dt[index].size = sizeof(DWORD);
431 dt[index].offset_in = -1;
432 dt[index].offset_out = asked_format->rgodf[j].dwOfs;
440 ret->internal_format_size = wine_format->dwDataSize;
444 HeapFree(GetProcessHeap(), 0, dt);
449 HeapFree(GetProcessHeap(), 0, done);
451 /* Last step - reset all instances of the new format */
452 calculate_ids(asked_format);
456 /* find an object by it's offset in a data format */
457 int offset_to_object(LPCDIDATAFORMAT df, int offset)
461 for (i = 0; i < df->dwNumObjs; i++)
462 if (df->rgodf[i].dwOfs == offset)
468 static int id_to_object(LPCDIDATAFORMAT df, int id)
472 for (i = 0; i < df->dwNumObjs; i++)
473 if ((df->rgodf[i].dwType & 0x00ffffff) == (id & 0x00ffffff))
479 int find_property(LPCDIDATAFORMAT df, LPCDIPROPHEADER ph)
483 case DIPH_BYID: return id_to_object(df, ph->dwObj);
484 case DIPH_BYOFFSET: return offset_to_object(df, ph->dwObj);
486 FIXME("Unhandled ph->dwHow=='%04X'\n", (unsigned int)ph->dwHow);
492 BOOL DIEnumDevicesCallbackAtoW(LPCDIDEVICEOBJECTINSTANCEA lpddi, LPVOID lpvRef) {
493 DIDEVICEOBJECTINSTANCEW ddtmp;
494 device_enumobjects_AtoWcb_data* data;
496 data = (device_enumobjects_AtoWcb_data*) lpvRef;
498 memset(&ddtmp, 0, sizeof(ddtmp));
500 ddtmp.dwSize = sizeof(DIDEVICEINSTANCEW);
501 ddtmp.guidType = lpddi->guidType;
502 ddtmp.dwOfs = lpddi->dwOfs;
503 ddtmp.dwType = lpddi->dwType;
504 ddtmp.dwFlags = lpddi->dwFlags;
505 MultiByteToWideChar(CP_ACP, 0, lpddi->tszName, -1, ddtmp.tszName, MAX_PATH);
507 if (lpddi->dwSize == sizeof(DIDEVICEINSTANCEA)) {
509 * if dwSize < sizeof(DIDEVICEINSTANCEA of DInput version >= 5)
510 * force feedback and other newer datas aren't available
512 ddtmp.dwFFMaxForce = lpddi->dwFFMaxForce;
513 ddtmp.dwFFForceResolution = lpddi->dwFFForceResolution;
514 ddtmp.wCollectionNumber = lpddi->wCollectionNumber;
515 ddtmp.wDesignatorIndex = lpddi->wDesignatorIndex;
516 ddtmp.wUsagePage = lpddi->wUsagePage;
517 ddtmp.wUsage = lpddi->wUsage;
518 ddtmp.dwDimension = lpddi->dwDimension;
519 ddtmp.wExponent = lpddi->wExponent;
520 ddtmp.wReserved = lpddi->wReserved;
522 return data->lpCallBack(&ddtmp, data->lpvRef);
525 /******************************************************************************
526 * queue_event - add new event to the ring queue
529 void queue_event(LPDIRECTINPUTDEVICE8A iface, int ofs, DWORD data, DWORD time, DWORD seq)
531 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
534 if (!This->queue_len || This->overflow || ofs < 0) return;
536 next_pos = (This->queue_head + 1) % This->queue_len;
537 if (next_pos == This->queue_tail)
539 TRACE(" queue overflowed\n");
540 This->overflow = TRUE;
544 TRACE(" queueing %d at offset %d (queue head %d / size %d)\n",
545 data, ofs, This->queue_head, This->queue_len);
547 This->data_queue[This->queue_head].dwOfs = ofs;
548 This->data_queue[This->queue_head].dwData = data;
549 This->data_queue[This->queue_head].dwTimeStamp = time;
550 This->data_queue[This->queue_head].dwSequence = seq;
551 This->queue_head = next_pos;
554 /******************************************************************************
558 HRESULT WINAPI IDirectInputDevice2AImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
560 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
563 EnterCriticalSection(&This->crit);
564 res = This->acquired ? S_FALSE : DI_OK;
567 This->queue_head = This->queue_tail = This->overflow = 0;
568 LeaveCriticalSection(&This->crit);
573 /******************************************************************************
577 HRESULT WINAPI IDirectInputDevice2AImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
579 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
582 EnterCriticalSection(&This->crit);
583 res = !This->acquired ? DI_NOEFFECT : DI_OK;
585 LeaveCriticalSection(&This->crit);
590 /******************************************************************************
591 * IDirectInputDeviceA
594 HRESULT WINAPI IDirectInputDevice2AImpl_SetDataFormat(
595 LPDIRECTINPUTDEVICE8A iface,LPCDIDATAFORMAT df
597 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
599 TRACE("(this=%p,%p)\n",This,df);
601 _dump_DIDATAFORMAT(df);
606 /******************************************************************************
607 * SetCooperativeLevel
609 * Set cooperative level and the source window for the events.
611 HRESULT WINAPI IDirectInputDevice2AImpl_SetCooperativeLevel(
612 LPDIRECTINPUTDEVICE8A iface, HWND hwnd, DWORD dwflags)
614 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
616 TRACE("(%p) %p,0x%08x\n", This, hwnd, dwflags);
617 TRACE(" cooperative level : ");
618 _dump_cooperativelevel_DI(dwflags);
620 if ((dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == 0 ||
621 (dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE) ||
622 (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == 0 ||
623 (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == (DISCL_FOREGROUND | DISCL_BACKGROUND))
624 return DIERR_INVALIDPARAM;
626 if (dwflags == (DISCL_NONEXCLUSIVE | DISCL_BACKGROUND))
627 hwnd = GetDesktopWindow();
629 if (!hwnd) return E_HANDLE;
631 /* For security reasons native does not allow exclusive background level
632 for mouse and keyboard only */
633 if (dwflags & DISCL_EXCLUSIVE && dwflags & DISCL_BACKGROUND &&
634 (IsEqualGUID(&This->guid, &GUID_SysMouse) ||
635 IsEqualGUID(&This->guid, &GUID_SysKeyboard)))
636 return DIERR_UNSUPPORTED;
638 /* Store the window which asks for the mouse */
639 EnterCriticalSection(&This->crit);
641 This->dwCoopLevel = dwflags;
642 LeaveCriticalSection(&This->crit);
647 /******************************************************************************
648 * SetEventNotification : specifies event to be sent on state change
650 HRESULT WINAPI IDirectInputDevice2AImpl_SetEventNotification(
651 LPDIRECTINPUTDEVICE8A iface, HANDLE event)
653 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
655 TRACE("(%p) %p\n", This, event);
657 EnterCriticalSection(&This->crit);
658 This->hEvent = event;
659 LeaveCriticalSection(&This->crit);
663 ULONG WINAPI IDirectInputDevice2AImpl_Release(LPDIRECTINPUTDEVICE8A iface)
665 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
668 ref = InterlockedDecrement(&(This->ref));
671 DeleteCriticalSection(&This->crit);
672 HeapFree(GetProcessHeap(), 0, This->data_queue);
673 HeapFree(GetProcessHeap(), 0, This);
678 HRESULT WINAPI IDirectInputDevice2AImpl_QueryInterface(
679 LPDIRECTINPUTDEVICE8A iface,REFIID riid,LPVOID *ppobj
682 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
684 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
685 if (IsEqualGUID(&IID_IUnknown,riid)) {
686 IDirectInputDevice2_AddRef(iface);
690 if (IsEqualGUID(&IID_IDirectInputDeviceA,riid)) {
691 IDirectInputDevice2_AddRef(iface);
695 if (IsEqualGUID(&IID_IDirectInputDevice2A,riid)) {
696 IDirectInputDevice2_AddRef(iface);
700 if (IsEqualGUID(&IID_IDirectInputDevice7A,riid)) {
701 IDirectInputDevice7_AddRef(iface);
705 if (IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
706 IDirectInputDevice8_AddRef(iface);
710 TRACE("Unsupported interface !\n");
714 HRESULT WINAPI IDirectInputDevice2WImpl_QueryInterface(
715 LPDIRECTINPUTDEVICE8W iface,REFIID riid,LPVOID *ppobj
718 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
720 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
721 if (IsEqualGUID(&IID_IUnknown,riid)) {
722 IDirectInputDevice2_AddRef(iface);
726 if (IsEqualGUID(&IID_IDirectInputDeviceW,riid)) {
727 IDirectInputDevice2_AddRef(iface);
731 if (IsEqualGUID(&IID_IDirectInputDevice2W,riid)) {
732 IDirectInputDevice2_AddRef(iface);
736 if (IsEqualGUID(&IID_IDirectInputDevice7W,riid)) {
737 IDirectInputDevice7_AddRef(iface);
741 if (IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
742 IDirectInputDevice8_AddRef(iface);
746 TRACE("Unsupported interface !\n");
750 ULONG WINAPI IDirectInputDevice2AImpl_AddRef(
751 LPDIRECTINPUTDEVICE8A iface)
753 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
754 return InterlockedIncrement(&(This->ref));
757 HRESULT WINAPI IDirectInputDevice2AImpl_EnumObjects(
758 LPDIRECTINPUTDEVICE8A iface,
759 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback,
763 FIXME("(this=%p,%p,%p,%08x): stub!\n", iface, lpCallback, lpvRef, dwFlags);
764 if (TRACE_ON(dinput)) {
765 DPRINTF(" - flags = ");
766 _dump_EnumObjects_flags(dwFlags);
773 HRESULT WINAPI IDirectInputDevice2WImpl_EnumObjects(
774 LPDIRECTINPUTDEVICE8W iface,
775 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback,
779 FIXME("(this=%p,%p,%p,%08x): stub!\n", iface, lpCallback, lpvRef, dwFlags);
780 if (TRACE_ON(dinput)) {
781 DPRINTF(" - flags = ");
782 _dump_EnumObjects_flags(dwFlags);
789 /******************************************************************************
793 HRESULT WINAPI IDirectInputDevice2AImpl_GetProperty(
794 LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPDIPROPHEADER pdiph)
796 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
798 TRACE("(%p) %s,%p\n", iface, debugstr_guid(rguid), pdiph);
799 _dump_DIPROPHEADER(pdiph);
801 if (HIWORD(rguid)) return DI_OK;
803 switch (LOWORD(rguid))
805 case (DWORD) DIPROP_BUFFERSIZE:
807 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
809 if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
811 pd->dwData = This->queue_len;
812 TRACE("buffersize = %d\n", pd->dwData);
816 WARN("Unknown property %s\n", debugstr_guid(rguid));
823 /******************************************************************************
827 HRESULT WINAPI IDirectInputDevice2AImpl_SetProperty(
828 LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPCDIPROPHEADER pdiph)
830 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
832 TRACE("(%p) %s,%p\n", iface, debugstr_guid(rguid), pdiph);
833 _dump_DIPROPHEADER(pdiph);
835 if (HIWORD(rguid)) return DI_OK;
837 switch (LOWORD(rguid))
839 case (DWORD) DIPROP_BUFFERSIZE:
841 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph;
843 if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
844 if (This->acquired) return DIERR_ACQUIRED;
846 TRACE("buffersize = %d\n", pd->dwData);
848 EnterCriticalSection(&This->crit);
849 HeapFree(GetProcessHeap(), 0, This->data_queue);
851 This->data_queue = !pd->dwData ? NULL : HeapAlloc(GetProcessHeap(), 0,
852 pd->dwData * sizeof(DIDEVICEOBJECTDATA));
853 This->queue_head = This->queue_tail = This->overflow = 0;
854 This->queue_len = pd->dwData;
856 LeaveCriticalSection(&This->crit);
860 WARN("Unknown property %s\n", debugstr_guid(rguid));
861 return DIERR_UNSUPPORTED;
867 HRESULT WINAPI IDirectInputDevice2AImpl_GetObjectInfo(
868 LPDIRECTINPUTDEVICE8A iface,
869 LPDIDEVICEOBJECTINSTANCEA pdidoi,
873 FIXME("(this=%p,%p,%d,0x%08x): stub!\n",
874 iface, pdidoi, dwObj, dwHow);
879 HRESULT WINAPI IDirectInputDevice2WImpl_GetObjectInfo(
880 LPDIRECTINPUTDEVICE8W iface,
881 LPDIDEVICEOBJECTINSTANCEW pdidoi,
885 FIXME("(this=%p,%p,%d,0x%08x): stub!\n",
886 iface, pdidoi, dwObj, dwHow);
891 HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceData(
892 LPDIRECTINPUTDEVICE8A iface, DWORD dodsize, LPDIDEVICEOBJECTDATA dod,
893 LPDWORD entries, DWORD flags)
895 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
899 TRACE("(%p) %p -> %p(%d) x%d, 0x%08x\n",
900 This, dod, entries, entries ? *entries : 0, dodsize, flags);
903 return DIERR_NOTACQUIRED;
904 if (!This->queue_len)
905 return DIERR_NOTBUFFERED;
906 if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3))
907 return DIERR_INVALIDPARAM;
909 IDirectInputDevice2_Poll(iface);
910 EnterCriticalSection(&This->crit);
912 len = This->queue_head - This->queue_tail;
913 if (len < 0) len += This->queue_len;
915 if ((*entries != INFINITE) && (len > *entries)) len = *entries;
920 for (i = 0; i < len; i++)
922 int n = (This->queue_tail + i) % This->queue_len;
923 memcpy((char *)dod + dodsize * i, This->data_queue + n, dodsize);
929 ret = DI_BUFFEROVERFLOW;
931 if (!(flags & DIGDD_PEEK))
933 /* Advance reading position */
934 This->queue_tail = (This->queue_tail + len) % This->queue_len;
935 This->overflow = FALSE;
938 LeaveCriticalSection(&This->crit);
940 TRACE("Returning %d events queued\n", *entries);
944 HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceInfo(
945 LPDIRECTINPUTDEVICE8A iface,
946 LPDIDEVICEINSTANCEA pdidi)
948 FIXME("(this=%p,%p): stub!\n",
954 HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceInfo(
955 LPDIRECTINPUTDEVICE8W iface,
956 LPDIDEVICEINSTANCEW pdidi)
958 FIXME("(this=%p,%p): stub!\n",
964 HRESULT WINAPI IDirectInputDevice2AImpl_RunControlPanel(
965 LPDIRECTINPUTDEVICE8A iface,
969 FIXME("(this=%p,%p,0x%08x): stub!\n",
970 iface, hwndOwner, dwFlags);
975 HRESULT WINAPI IDirectInputDevice2AImpl_Initialize(
976 LPDIRECTINPUTDEVICE8A iface,
981 FIXME("(this=%p,%p,%d,%s): stub!\n",
982 iface, hinst, dwVersion, debugstr_guid(rguid));
986 /******************************************************************************
987 * IDirectInputDevice2A
990 HRESULT WINAPI IDirectInputDevice2AImpl_CreateEffect(
991 LPDIRECTINPUTDEVICE8A iface,
994 LPDIRECTINPUTEFFECT *ppdef,
997 FIXME("(this=%p,%s,%p,%p,%p): stub!\n",
998 iface, debugstr_guid(rguid), lpeff, ppdef, pUnkOuter);
1002 HRESULT WINAPI IDirectInputDevice2AImpl_EnumEffects(
1003 LPDIRECTINPUTDEVICE8A iface,
1004 LPDIENUMEFFECTSCALLBACKA lpCallback,
1008 FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1009 iface, lpCallback, lpvRef, dwFlags);
1014 HRESULT WINAPI IDirectInputDevice2WImpl_EnumEffects(
1015 LPDIRECTINPUTDEVICE8W iface,
1016 LPDIENUMEFFECTSCALLBACKW lpCallback,
1020 FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1021 iface, lpCallback, lpvRef, dwFlags);
1026 HRESULT WINAPI IDirectInputDevice2AImpl_GetEffectInfo(
1027 LPDIRECTINPUTDEVICE8A iface,
1028 LPDIEFFECTINFOA lpdei,
1031 FIXME("(this=%p,%p,%s): stub!\n",
1032 iface, lpdei, debugstr_guid(rguid));
1036 HRESULT WINAPI IDirectInputDevice2WImpl_GetEffectInfo(
1037 LPDIRECTINPUTDEVICE8W iface,
1038 LPDIEFFECTINFOW lpdei,
1041 FIXME("(this=%p,%p,%s): stub!\n",
1042 iface, lpdei, debugstr_guid(rguid));
1046 HRESULT WINAPI IDirectInputDevice2AImpl_GetForceFeedbackState(
1047 LPDIRECTINPUTDEVICE8A iface,
1050 FIXME("(this=%p,%p): stub!\n",
1055 HRESULT WINAPI IDirectInputDevice2AImpl_SendForceFeedbackCommand(
1056 LPDIRECTINPUTDEVICE8A iface,
1059 FIXME("(this=%p,0x%08x): stub!\n",
1064 HRESULT WINAPI IDirectInputDevice2AImpl_EnumCreatedEffectObjects(
1065 LPDIRECTINPUTDEVICE8A iface,
1066 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback,
1070 FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1071 iface, lpCallback, lpvRef, dwFlags);
1075 HRESULT WINAPI IDirectInputDevice2AImpl_Escape(
1076 LPDIRECTINPUTDEVICE8A iface,
1077 LPDIEFFESCAPE lpDIEEsc)
1079 FIXME("(this=%p,%p): stub!\n",
1084 HRESULT WINAPI IDirectInputDevice2AImpl_Poll(
1085 LPDIRECTINPUTDEVICE8A iface)
1087 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
1089 if (!This->acquired) return DIERR_NOTACQUIRED;
1090 /* Because wine devices do not need to be polled, just return DI_NOEFFECT */
1094 HRESULT WINAPI IDirectInputDevice2AImpl_SendDeviceData(
1095 LPDIRECTINPUTDEVICE8A iface,
1097 LPCDIDEVICEOBJECTDATA rgdod,
1101 FIXME("(this=%p,0x%08x,%p,%p,0x%08x): stub!\n",
1102 iface, cbObjectData, rgdod, pdwInOut, dwFlags);
1107 HRESULT WINAPI IDirectInputDevice7AImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8A iface,
1108 LPCSTR lpszFileName,
1109 LPDIENUMEFFECTSINFILECALLBACK pec,
1113 FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", iface, lpszFileName, pec, pvRef, dwFlags);
1118 HRESULT WINAPI IDirectInputDevice7WImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8W iface,
1119 LPCWSTR lpszFileName,
1120 LPDIENUMEFFECTSINFILECALLBACK pec,
1124 FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", iface, debugstr_w(lpszFileName), pec, pvRef, dwFlags);
1129 HRESULT WINAPI IDirectInputDevice7AImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8A iface,
1130 LPCSTR lpszFileName,
1132 LPDIFILEEFFECT rgDiFileEft,
1135 FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", iface, lpszFileName, dwEntries, rgDiFileEft, dwFlags);
1140 HRESULT WINAPI IDirectInputDevice7WImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8W iface,
1141 LPCWSTR lpszFileName,
1143 LPDIFILEEFFECT rgDiFileEft,
1146 FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", iface, debugstr_w(lpszFileName), dwEntries, rgDiFileEft, dwFlags);
1151 HRESULT WINAPI IDirectInputDevice8AImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface,
1152 LPDIACTIONFORMATA lpdiaf,
1153 LPCSTR lpszUserName,
1156 FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, lpszUserName, dwFlags);
1161 HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface,
1162 LPDIACTIONFORMATW lpdiaf,
1163 LPCWSTR lpszUserName,
1166 FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
1171 HRESULT WINAPI IDirectInputDevice8AImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface,
1172 LPDIACTIONFORMATA lpdiaf,
1173 LPCSTR lpszUserName,
1176 FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, lpszUserName, dwFlags);
1181 HRESULT WINAPI IDirectInputDevice8WImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
1182 LPDIACTIONFORMATW lpdiaf,
1183 LPCWSTR lpszUserName,
1186 FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
1191 HRESULT WINAPI IDirectInputDevice8AImpl_GetImageInfo(LPDIRECTINPUTDEVICE8A iface,
1192 LPDIDEVICEIMAGEINFOHEADERA lpdiDevImageInfoHeader)
1194 FIXME("(%p)->(%p): stub !\n", iface, lpdiDevImageInfoHeader);
1199 HRESULT WINAPI IDirectInputDevice8WImpl_GetImageInfo(LPDIRECTINPUTDEVICE8W iface,
1200 LPDIDEVICEIMAGEINFOHEADERW lpdiDevImageInfoHeader)
1202 FIXME("(%p)->(%p): stub !\n", iface, lpdiDevImageInfoHeader);