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 DataFormat: %p\n", format);
287 HeapFree(GetProcessHeap(), 0, format->dt);
289 HeapFree(GetProcessHeap(), 0, format->offsets);
290 format->offsets = NULL;
292 HeapFree(GetProcessHeap(), 0, format->user_df->rgodf);
293 HeapFree(GetProcessHeap(), 0, format->user_df);
294 format->user_df = NULL;
297 /* Make all instances sequential */
298 static void calculate_ids(LPDIDATAFORMAT df)
300 int i, axis = 0, pov = 0, button = 0;
301 int axis_base, pov_base, button_base;
304 /* Make two passes over the format. The first counts the number
305 * for each type and the second sets the id */
306 for (i = 0; i < df->dwNumObjs; i++)
308 type = DIDFT_GETTYPE(df->rgodf[i].dwType);
309 if (type & DIDFT_AXIS) axis++;
310 else if (type & DIDFT_POV) pov++;
311 else if (type & DIDFT_BUTTON) button++;
315 pov_base = axis_base + axis;
316 button_base = pov_base + pov;
317 axis = pov = button = 0;
319 for (i = 0; i < df->dwNumObjs; i++)
321 type = DIDFT_GETTYPE(df->rgodf[i].dwType);
322 if (type & DIDFT_AXIS)
324 type |= DIDFT_MAKEINSTANCE(axis_base + axis++);
325 TRACE("axis type = 0x%08x\n", type);
326 } else if (type & DIDFT_POV)
328 type |= DIDFT_MAKEINSTANCE(pov_base + pov++);
329 TRACE("POV type = 0x%08x\n", type);
330 } else if (type & DIDFT_BUTTON)
332 type |= DIDFT_MAKEINSTANCE(button_base + button++);
333 TRACE("button type = 0x%08x\n", type);
335 df->rgodf[i].dwType = type;
339 HRESULT create_DataFormat(LPCDIDATAFORMAT asked_format, DataFormat *format)
348 if (!format->wine_df) return DIERR_INVALIDPARAM;
349 done = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, asked_format->dwNumObjs * sizeof(int));
350 dt = HeapAlloc(GetProcessHeap(), 0, asked_format->dwNumObjs * sizeof(DataTransform));
351 if (!dt || !done) goto failed;
353 if (!(format->offsets = HeapAlloc(GetProcessHeap(), 0, format->wine_df->dwNumObjs * sizeof(int))))
356 if (!(format->user_df = HeapAlloc(GetProcessHeap(), 0, asked_format->dwSize)))
358 memcpy(format->user_df, asked_format, asked_format->dwSize);
360 if (!(format->user_df->rgodf = HeapAlloc(GetProcessHeap(), 0, asked_format->dwNumObjs*asked_format->dwObjSize)))
362 memcpy(format->user_df->rgodf, asked_format->rgodf, asked_format->dwNumObjs*asked_format->dwObjSize);
364 TRACE("Creating DataTransform :\n");
366 for (i = 0; i < format->wine_df->dwNumObjs; i++)
368 format->offsets[i] = -1;
370 for (j = 0; j < asked_format->dwNumObjs; j++) {
374 if (/* Check if the application either requests any GUID and if not, it if matches
375 * the GUID of the Wine object.
377 ((asked_format->rgodf[j].pguid == NULL) ||
378 (format->wine_df->rgodf[i].pguid == NULL) ||
379 (IsEqualGUID(format->wine_df->rgodf[i].pguid, asked_format->rgodf[j].pguid)))
381 (/* Then check if it accepts any instance id, and if not, if it matches Wine's
384 ((asked_format->rgodf[j].dwType & DIDFT_INSTANCEMASK) == DIDFT_ANYINSTANCE) ||
385 (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == 0x00FF) || /* This is mentionned in no DX docs, but it works fine - tested on WinXP */
386 (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == DIDFT_GETINSTANCE(format->wine_df->rgodf[i].dwType)))
388 ( /* Then if the asked type matches the one Wine provides */
389 DIDFT_GETTYPE(asked_format->rgodf[j].dwType) & format->wine_df->rgodf[i].dwType))
393 TRACE("Matching :\n");
394 TRACE(" - Asked (%d) :\n", j);
395 TRACE(" * GUID: %s ('%s')\n",
396 debugstr_guid(asked_format->rgodf[j].pguid),
397 _dump_dinput_GUID(asked_format->rgodf[j].pguid));
398 TRACE(" * Offset: %3d\n", asked_format->rgodf[j].dwOfs);
399 TRACE(" * dwType: %08x\n", asked_format->rgodf[j].dwType);
400 TRACE(" "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
402 TRACE(" - Wine (%d) :\n", i);
403 TRACE(" * GUID: %s ('%s')\n",
404 debugstr_guid(format->wine_df->rgodf[i].pguid),
405 _dump_dinput_GUID(format->wine_df->rgodf[i].pguid));
406 TRACE(" * Offset: %3d\n", format->wine_df->rgodf[i].dwOfs);
407 TRACE(" * dwType: %08x\n", format->wine_df->rgodf[i].dwType);
408 TRACE(" "); _dump_EnumObjects_flags(format->wine_df->rgodf[i].dwType); TRACE("\n");
410 if (format->wine_df->rgodf[i].dwType & DIDFT_BUTTON)
411 dt[index].size = sizeof(BYTE);
413 dt[index].size = sizeof(DWORD);
414 dt[index].offset_in = format->wine_df->rgodf[i].dwOfs;
415 dt[index].offset_out = asked_format->rgodf[j].dwOfs;
416 format->offsets[i] = asked_format->rgodf[j].dwOfs;
418 next = next + dt[index].size;
420 if (format->wine_df->rgodf[i].dwOfs != dt[index].offset_out)
428 if (j == asked_format->dwNumObjs)
432 TRACE("Setting to default value :\n");
433 for (j = 0; j < asked_format->dwNumObjs; j++) {
435 TRACE(" - Asked (%d) :\n", j);
436 TRACE(" * GUID: %s ('%s')\n",
437 debugstr_guid(asked_format->rgodf[j].pguid),
438 _dump_dinput_GUID(asked_format->rgodf[j].pguid));
439 TRACE(" * Offset: %3d\n", asked_format->rgodf[j].dwOfs);
440 TRACE(" * dwType: %08x\n", asked_format->rgodf[j].dwType);
441 TRACE(" "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
443 if (asked_format->rgodf[j].dwType & DIDFT_BUTTON)
444 dt[index].size = sizeof(BYTE);
446 dt[index].size = sizeof(DWORD);
447 dt[index].offset_in = -1;
448 dt[index].offset_out = asked_format->rgodf[j].dwOfs;
456 format->internal_format_size = format->wine_df->dwDataSize;
457 format->size = index;
459 HeapFree(GetProcessHeap(), 0, dt);
464 HeapFree(GetProcessHeap(), 0, done);
466 /* Last step - reset all instances of the new format */
467 calculate_ids(format->user_df);
471 HeapFree(GetProcessHeap(), 0, done);
472 HeapFree(GetProcessHeap(), 0, dt);
474 HeapFree(GetProcessHeap(), 0, format->offsets);
475 format->offsets = NULL;
477 HeapFree(GetProcessHeap(), 0, format->user_df->rgodf);
478 HeapFree(GetProcessHeap(), 0, format->user_df);
479 format->user_df = NULL;
481 return DIERR_OUTOFMEMORY;
484 /* find an object by it's offset in a data format */
485 int offset_to_object(LPCDIDATAFORMAT df, int offset)
489 for (i = 0; i < df->dwNumObjs; i++)
490 if (df->rgodf[i].dwOfs == offset)
496 static int id_to_object(LPCDIDATAFORMAT df, int id)
500 for (i = 0; i < df->dwNumObjs; i++)
501 if ((df->rgodf[i].dwType & 0x00ffffff) == (id & 0x00ffffff))
507 int find_property(LPCDIDATAFORMAT df, LPCDIPROPHEADER ph)
511 case DIPH_BYID: return id_to_object(df, ph->dwObj);
512 case DIPH_BYOFFSET: return offset_to_object(df, ph->dwObj);
514 FIXME("Unhandled ph->dwHow=='%04X'\n", (unsigned int)ph->dwHow);
520 BOOL DIEnumDevicesCallbackAtoW(LPCDIDEVICEOBJECTINSTANCEA lpddi, LPVOID lpvRef) {
521 DIDEVICEOBJECTINSTANCEW ddtmp;
522 device_enumobjects_AtoWcb_data* data;
524 data = (device_enumobjects_AtoWcb_data*) lpvRef;
526 memset(&ddtmp, 0, sizeof(ddtmp));
528 ddtmp.dwSize = sizeof(DIDEVICEINSTANCEW);
529 ddtmp.guidType = lpddi->guidType;
530 ddtmp.dwOfs = lpddi->dwOfs;
531 ddtmp.dwType = lpddi->dwType;
532 ddtmp.dwFlags = lpddi->dwFlags;
533 MultiByteToWideChar(CP_ACP, 0, lpddi->tszName, -1, ddtmp.tszName, MAX_PATH);
535 if (lpddi->dwSize == sizeof(DIDEVICEINSTANCEA)) {
537 * if dwSize < sizeof(DIDEVICEINSTANCEA of DInput version >= 5)
538 * force feedback and other newer datas aren't available
540 ddtmp.dwFFMaxForce = lpddi->dwFFMaxForce;
541 ddtmp.dwFFForceResolution = lpddi->dwFFForceResolution;
542 ddtmp.wCollectionNumber = lpddi->wCollectionNumber;
543 ddtmp.wDesignatorIndex = lpddi->wDesignatorIndex;
544 ddtmp.wUsagePage = lpddi->wUsagePage;
545 ddtmp.wUsage = lpddi->wUsage;
546 ddtmp.dwDimension = lpddi->dwDimension;
547 ddtmp.wExponent = lpddi->wExponent;
548 ddtmp.wReserved = lpddi->wReserved;
550 return data->lpCallBack(&ddtmp, data->lpvRef);
553 /******************************************************************************
554 * queue_event - add new event to the ring queue
557 void queue_event(LPDIRECTINPUTDEVICE8A iface, int ofs, DWORD data, DWORD time, DWORD seq)
559 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
562 if (!This->queue_len || This->overflow || ofs < 0) return;
564 next_pos = (This->queue_head + 1) % This->queue_len;
565 if (next_pos == This->queue_tail)
567 TRACE(" queue overflowed\n");
568 This->overflow = TRUE;
572 TRACE(" queueing %d at offset %d (queue head %d / size %d)\n",
573 data, ofs, This->queue_head, This->queue_len);
575 This->data_queue[This->queue_head].dwOfs = ofs;
576 This->data_queue[This->queue_head].dwData = data;
577 This->data_queue[This->queue_head].dwTimeStamp = time;
578 This->data_queue[This->queue_head].dwSequence = seq;
579 This->queue_head = next_pos;
582 /******************************************************************************
586 HRESULT WINAPI IDirectInputDevice2AImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
588 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
591 if (!This->data_format.user_df) return DIERR_INVALIDPARAM;
593 EnterCriticalSection(&This->crit);
594 res = This->acquired ? S_FALSE : DI_OK;
597 This->queue_head = This->queue_tail = This->overflow = 0;
598 LeaveCriticalSection(&This->crit);
603 /******************************************************************************
607 HRESULT WINAPI IDirectInputDevice2AImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
609 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
612 EnterCriticalSection(&This->crit);
613 res = !This->acquired ? DI_NOEFFECT : DI_OK;
615 LeaveCriticalSection(&This->crit);
620 /******************************************************************************
621 * IDirectInputDeviceA
624 HRESULT WINAPI IDirectInputDevice2AImpl_SetDataFormat(
625 LPDIRECTINPUTDEVICE8A iface, LPCDIDATAFORMAT df)
627 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
630 if (!df) return E_POINTER;
631 TRACE("(%p) %p\n", This, df);
632 _dump_DIDATAFORMAT(df);
634 if (df->dwSize != sizeof(DIDATAFORMAT)) return DIERR_INVALIDPARAM;
635 if (This->acquired) return DIERR_ACQUIRED;
637 EnterCriticalSection(&This->crit);
639 release_DataFormat(&This->data_format);
640 res = create_DataFormat(df, &This->data_format);
642 LeaveCriticalSection(&This->crit);
646 /******************************************************************************
647 * SetCooperativeLevel
649 * Set cooperative level and the source window for the events.
651 HRESULT WINAPI IDirectInputDevice2AImpl_SetCooperativeLevel(
652 LPDIRECTINPUTDEVICE8A iface, HWND hwnd, DWORD dwflags)
654 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
656 TRACE("(%p) %p,0x%08x\n", This, hwnd, dwflags);
657 TRACE(" cooperative level : ");
658 _dump_cooperativelevel_DI(dwflags);
660 if ((dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == 0 ||
661 (dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE) ||
662 (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == 0 ||
663 (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == (DISCL_FOREGROUND | DISCL_BACKGROUND))
664 return DIERR_INVALIDPARAM;
666 if (dwflags == (DISCL_NONEXCLUSIVE | DISCL_BACKGROUND))
667 hwnd = GetDesktopWindow();
669 if (!hwnd) return E_HANDLE;
671 /* For security reasons native does not allow exclusive background level
672 for mouse and keyboard only */
673 if (dwflags & DISCL_EXCLUSIVE && dwflags & DISCL_BACKGROUND &&
674 (IsEqualGUID(&This->guid, &GUID_SysMouse) ||
675 IsEqualGUID(&This->guid, &GUID_SysKeyboard)))
676 return DIERR_UNSUPPORTED;
678 /* Store the window which asks for the mouse */
679 EnterCriticalSection(&This->crit);
681 This->dwCoopLevel = dwflags;
682 LeaveCriticalSection(&This->crit);
687 /******************************************************************************
688 * SetEventNotification : specifies event to be sent on state change
690 HRESULT WINAPI IDirectInputDevice2AImpl_SetEventNotification(
691 LPDIRECTINPUTDEVICE8A iface, HANDLE event)
693 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
695 TRACE("(%p) %p\n", This, event);
697 EnterCriticalSection(&This->crit);
698 This->hEvent = event;
699 LeaveCriticalSection(&This->crit);
703 ULONG WINAPI IDirectInputDevice2AImpl_Release(LPDIRECTINPUTDEVICE8A iface)
705 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
708 ref = InterlockedDecrement(&(This->ref));
711 DeleteCriticalSection(&This->crit);
712 HeapFree(GetProcessHeap(), 0, This->data_queue);
713 HeapFree(GetProcessHeap(), 0, This);
718 HRESULT WINAPI IDirectInputDevice2AImpl_QueryInterface(
719 LPDIRECTINPUTDEVICE8A iface,REFIID riid,LPVOID *ppobj
722 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
724 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
725 if (IsEqualGUID(&IID_IUnknown,riid)) {
726 IDirectInputDevice2_AddRef(iface);
730 if (IsEqualGUID(&IID_IDirectInputDeviceA,riid)) {
731 IDirectInputDevice2_AddRef(iface);
735 if (IsEqualGUID(&IID_IDirectInputDevice2A,riid)) {
736 IDirectInputDevice2_AddRef(iface);
740 if (IsEqualGUID(&IID_IDirectInputDevice7A,riid)) {
741 IDirectInputDevice7_AddRef(iface);
745 if (IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
746 IDirectInputDevice8_AddRef(iface);
750 TRACE("Unsupported interface !\n");
754 HRESULT WINAPI IDirectInputDevice2WImpl_QueryInterface(
755 LPDIRECTINPUTDEVICE8W iface,REFIID riid,LPVOID *ppobj
758 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
760 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
761 if (IsEqualGUID(&IID_IUnknown,riid)) {
762 IDirectInputDevice2_AddRef(iface);
766 if (IsEqualGUID(&IID_IDirectInputDeviceW,riid)) {
767 IDirectInputDevice2_AddRef(iface);
771 if (IsEqualGUID(&IID_IDirectInputDevice2W,riid)) {
772 IDirectInputDevice2_AddRef(iface);
776 if (IsEqualGUID(&IID_IDirectInputDevice7W,riid)) {
777 IDirectInputDevice7_AddRef(iface);
781 if (IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
782 IDirectInputDevice8_AddRef(iface);
786 TRACE("Unsupported interface !\n");
790 ULONG WINAPI IDirectInputDevice2AImpl_AddRef(
791 LPDIRECTINPUTDEVICE8A iface)
793 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
794 return InterlockedIncrement(&(This->ref));
797 HRESULT WINAPI IDirectInputDevice2AImpl_EnumObjects(
798 LPDIRECTINPUTDEVICE8A iface,
799 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback,
803 FIXME("(this=%p,%p,%p,%08x): stub!\n", iface, lpCallback, lpvRef, dwFlags);
804 if (TRACE_ON(dinput)) {
805 DPRINTF(" - flags = ");
806 _dump_EnumObjects_flags(dwFlags);
813 HRESULT WINAPI IDirectInputDevice2WImpl_EnumObjects(
814 LPDIRECTINPUTDEVICE8W iface,
815 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback,
819 FIXME("(this=%p,%p,%p,%08x): stub!\n", iface, lpCallback, lpvRef, dwFlags);
820 if (TRACE_ON(dinput)) {
821 DPRINTF(" - flags = ");
822 _dump_EnumObjects_flags(dwFlags);
829 /******************************************************************************
833 HRESULT WINAPI IDirectInputDevice2AImpl_GetProperty(
834 LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPDIPROPHEADER pdiph)
836 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
838 TRACE("(%p) %s,%p\n", iface, debugstr_guid(rguid), pdiph);
839 _dump_DIPROPHEADER(pdiph);
841 if (HIWORD(rguid)) return DI_OK;
843 switch (LOWORD(rguid))
845 case (DWORD) DIPROP_BUFFERSIZE:
847 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
849 if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
851 pd->dwData = This->queue_len;
852 TRACE("buffersize = %d\n", pd->dwData);
856 WARN("Unknown property %s\n", debugstr_guid(rguid));
863 /******************************************************************************
867 HRESULT WINAPI IDirectInputDevice2AImpl_SetProperty(
868 LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPCDIPROPHEADER pdiph)
870 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
872 TRACE("(%p) %s,%p\n", iface, debugstr_guid(rguid), pdiph);
873 _dump_DIPROPHEADER(pdiph);
875 if (HIWORD(rguid)) return DI_OK;
877 switch (LOWORD(rguid))
879 case (DWORD) DIPROP_AXISMODE:
881 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph;
883 if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
884 if (pdiph->dwHow == DIPH_DEVICE && pdiph->dwObj) return DIERR_INVALIDPARAM;
885 if (This->acquired) return DIERR_ACQUIRED;
886 if (pdiph->dwHow != DIPH_DEVICE) return DIERR_UNSUPPORTED;
888 TRACE("Axis mode: %s\n", pd->dwData == DIPROPAXISMODE_ABS ? "absolute" :
891 EnterCriticalSection(&This->crit);
892 This->data_format.user_df->dwFlags &= ~DIDFT_AXIS;
893 This->data_format.user_df->dwFlags |= pd->dwData == DIPROPAXISMODE_ABS ?
894 DIDF_ABSAXIS : DIDF_RELAXIS;
895 LeaveCriticalSection(&This->crit);
898 case (DWORD) DIPROP_BUFFERSIZE:
900 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph;
902 if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
903 if (This->acquired) return DIERR_ACQUIRED;
905 TRACE("buffersize = %d\n", pd->dwData);
907 EnterCriticalSection(&This->crit);
908 HeapFree(GetProcessHeap(), 0, This->data_queue);
910 This->data_queue = !pd->dwData ? NULL : HeapAlloc(GetProcessHeap(), 0,
911 pd->dwData * sizeof(DIDEVICEOBJECTDATA));
912 This->queue_head = This->queue_tail = This->overflow = 0;
913 This->queue_len = pd->dwData;
915 LeaveCriticalSection(&This->crit);
919 WARN("Unknown property %s\n", debugstr_guid(rguid));
920 return DIERR_UNSUPPORTED;
926 HRESULT WINAPI IDirectInputDevice2AImpl_GetObjectInfo(
927 LPDIRECTINPUTDEVICE8A iface,
928 LPDIDEVICEOBJECTINSTANCEA pdidoi,
932 FIXME("(this=%p,%p,%d,0x%08x): stub!\n",
933 iface, pdidoi, dwObj, dwHow);
938 HRESULT WINAPI IDirectInputDevice2WImpl_GetObjectInfo(
939 LPDIRECTINPUTDEVICE8W iface,
940 LPDIDEVICEOBJECTINSTANCEW pdidoi,
944 FIXME("(this=%p,%p,%d,0x%08x): stub!\n",
945 iface, pdidoi, dwObj, dwHow);
950 HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceData(
951 LPDIRECTINPUTDEVICE8A iface, DWORD dodsize, LPDIDEVICEOBJECTDATA dod,
952 LPDWORD entries, DWORD flags)
954 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
958 TRACE("(%p) %p -> %p(%d) x%d, 0x%08x\n",
959 This, dod, entries, entries ? *entries : 0, dodsize, flags);
962 return DIERR_NOTACQUIRED;
963 if (!This->queue_len)
964 return DIERR_NOTBUFFERED;
965 if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3))
966 return DIERR_INVALIDPARAM;
968 IDirectInputDevice2_Poll(iface);
969 EnterCriticalSection(&This->crit);
971 len = This->queue_head - This->queue_tail;
972 if (len < 0) len += This->queue_len;
974 if ((*entries != INFINITE) && (len > *entries)) len = *entries;
979 for (i = 0; i < len; i++)
981 int n = (This->queue_tail + i) % This->queue_len;
982 memcpy((char *)dod + dodsize * i, This->data_queue + n, dodsize);
988 ret = DI_BUFFEROVERFLOW;
990 if (!(flags & DIGDD_PEEK))
992 /* Advance reading position */
993 This->queue_tail = (This->queue_tail + len) % This->queue_len;
994 This->overflow = FALSE;
997 LeaveCriticalSection(&This->crit);
999 TRACE("Returning %d events queued\n", *entries);
1003 HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceInfo(
1004 LPDIRECTINPUTDEVICE8A iface,
1005 LPDIDEVICEINSTANCEA pdidi)
1007 FIXME("(this=%p,%p): stub!\n",
1013 HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceInfo(
1014 LPDIRECTINPUTDEVICE8W iface,
1015 LPDIDEVICEINSTANCEW pdidi)
1017 FIXME("(this=%p,%p): stub!\n",
1023 HRESULT WINAPI IDirectInputDevice2AImpl_RunControlPanel(
1024 LPDIRECTINPUTDEVICE8A iface,
1028 FIXME("(this=%p,%p,0x%08x): stub!\n",
1029 iface, hwndOwner, dwFlags);
1034 HRESULT WINAPI IDirectInputDevice2AImpl_Initialize(
1035 LPDIRECTINPUTDEVICE8A iface,
1040 FIXME("(this=%p,%p,%d,%s): stub!\n",
1041 iface, hinst, dwVersion, debugstr_guid(rguid));
1045 /******************************************************************************
1046 * IDirectInputDevice2A
1049 HRESULT WINAPI IDirectInputDevice2AImpl_CreateEffect(
1050 LPDIRECTINPUTDEVICE8A iface,
1053 LPDIRECTINPUTEFFECT *ppdef,
1054 LPUNKNOWN pUnkOuter)
1056 FIXME("(this=%p,%s,%p,%p,%p): stub!\n",
1057 iface, debugstr_guid(rguid), lpeff, ppdef, pUnkOuter);
1061 HRESULT WINAPI IDirectInputDevice2AImpl_EnumEffects(
1062 LPDIRECTINPUTDEVICE8A iface,
1063 LPDIENUMEFFECTSCALLBACKA lpCallback,
1067 FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1068 iface, lpCallback, lpvRef, dwFlags);
1073 HRESULT WINAPI IDirectInputDevice2WImpl_EnumEffects(
1074 LPDIRECTINPUTDEVICE8W iface,
1075 LPDIENUMEFFECTSCALLBACKW lpCallback,
1079 FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1080 iface, lpCallback, lpvRef, dwFlags);
1085 HRESULT WINAPI IDirectInputDevice2AImpl_GetEffectInfo(
1086 LPDIRECTINPUTDEVICE8A iface,
1087 LPDIEFFECTINFOA lpdei,
1090 FIXME("(this=%p,%p,%s): stub!\n",
1091 iface, lpdei, debugstr_guid(rguid));
1095 HRESULT WINAPI IDirectInputDevice2WImpl_GetEffectInfo(
1096 LPDIRECTINPUTDEVICE8W iface,
1097 LPDIEFFECTINFOW lpdei,
1100 FIXME("(this=%p,%p,%s): stub!\n",
1101 iface, lpdei, debugstr_guid(rguid));
1105 HRESULT WINAPI IDirectInputDevice2AImpl_GetForceFeedbackState(
1106 LPDIRECTINPUTDEVICE8A iface,
1109 FIXME("(this=%p,%p): stub!\n",
1114 HRESULT WINAPI IDirectInputDevice2AImpl_SendForceFeedbackCommand(
1115 LPDIRECTINPUTDEVICE8A iface,
1118 FIXME("(this=%p,0x%08x): stub!\n",
1123 HRESULT WINAPI IDirectInputDevice2AImpl_EnumCreatedEffectObjects(
1124 LPDIRECTINPUTDEVICE8A iface,
1125 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback,
1129 FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1130 iface, lpCallback, lpvRef, dwFlags);
1134 HRESULT WINAPI IDirectInputDevice2AImpl_Escape(
1135 LPDIRECTINPUTDEVICE8A iface,
1136 LPDIEFFESCAPE lpDIEEsc)
1138 FIXME("(this=%p,%p): stub!\n",
1143 HRESULT WINAPI IDirectInputDevice2AImpl_Poll(
1144 LPDIRECTINPUTDEVICE8A iface)
1146 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
1148 if (!This->acquired) return DIERR_NOTACQUIRED;
1149 /* Because wine devices do not need to be polled, just return DI_NOEFFECT */
1153 HRESULT WINAPI IDirectInputDevice2AImpl_SendDeviceData(
1154 LPDIRECTINPUTDEVICE8A iface,
1156 LPCDIDEVICEOBJECTDATA rgdod,
1160 FIXME("(this=%p,0x%08x,%p,%p,0x%08x): stub!\n",
1161 iface, cbObjectData, rgdod, pdwInOut, dwFlags);
1166 HRESULT WINAPI IDirectInputDevice7AImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8A iface,
1167 LPCSTR lpszFileName,
1168 LPDIENUMEFFECTSINFILECALLBACK pec,
1172 FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", iface, lpszFileName, pec, pvRef, dwFlags);
1177 HRESULT WINAPI IDirectInputDevice7WImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8W iface,
1178 LPCWSTR lpszFileName,
1179 LPDIENUMEFFECTSINFILECALLBACK pec,
1183 FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", iface, debugstr_w(lpszFileName), pec, pvRef, dwFlags);
1188 HRESULT WINAPI IDirectInputDevice7AImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8A iface,
1189 LPCSTR lpszFileName,
1191 LPDIFILEEFFECT rgDiFileEft,
1194 FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", iface, lpszFileName, dwEntries, rgDiFileEft, dwFlags);
1199 HRESULT WINAPI IDirectInputDevice7WImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8W iface,
1200 LPCWSTR lpszFileName,
1202 LPDIFILEEFFECT rgDiFileEft,
1205 FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", iface, debugstr_w(lpszFileName), dwEntries, rgDiFileEft, dwFlags);
1210 HRESULT WINAPI IDirectInputDevice8AImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface,
1211 LPDIACTIONFORMATA lpdiaf,
1212 LPCSTR lpszUserName,
1215 FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, lpszUserName, dwFlags);
1220 HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface,
1221 LPDIACTIONFORMATW lpdiaf,
1222 LPCWSTR lpszUserName,
1225 FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
1230 HRESULT WINAPI IDirectInputDevice8AImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface,
1231 LPDIACTIONFORMATA lpdiaf,
1232 LPCSTR lpszUserName,
1235 FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, lpszUserName, dwFlags);
1240 HRESULT WINAPI IDirectInputDevice8WImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
1241 LPDIACTIONFORMATW lpdiaf,
1242 LPCWSTR lpszUserName,
1245 FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
1250 HRESULT WINAPI IDirectInputDevice8AImpl_GetImageInfo(LPDIRECTINPUTDEVICE8A iface,
1251 LPDIDEVICEIMAGEINFOHEADERA lpdiDevImageInfoHeader)
1253 FIXME("(%p)->(%p): stub !\n", iface, lpdiDevImageInfoHeader);
1258 HRESULT WINAPI IDirectInputDevice8WImpl_GetImageInfo(LPDIRECTINPUTDEVICE8W iface,
1259 LPDIDEVICEIMAGEINFOHEADERW lpdiDevImageInfoHeader)
1261 FIXME("(%p)->(%p): stub !\n", iface, lpdiDevImageInfoHeader);