Correctness for const pointer casts.
[wine/multimedia.git] / dlls / dinput / dinput_main.c
blob464cf64d3fd7e0d6ffafb1b0fa4384e423e1271b
1 /* DirectInput
3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998,1999 Lionel Ulmer
5 * Copyright 2000-2002 TransGaming Technologies Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 /* Status:
24 * - Tomb Raider 2 Demo:
25 * Playable using keyboard only.
26 * - WingCommander Prophecy Demo:
27 * Doesn't get Input Focus.
29 * - Fallout : works great in X and DGA mode
32 #include "config.h"
33 #include <assert.h>
34 #include <stdarg.h>
35 #include <string.h>
37 #define COBJMACROS
39 #include "wine/debug.h"
40 #include "wine/unicode.h"
41 #include "windef.h"
42 #include "winbase.h"
43 #include "winuser.h"
44 #include "winerror.h"
45 #include "dinput_private.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
49 static IDirectInput7AVtbl ddi7avt;
50 static IDirectInput7WVtbl ddi7wvt;
51 static IDirectInput8AVtbl ddi8avt;
52 static IDirectInput8WVtbl ddi8wvt;
54 static const struct dinput_device *dinput_devices[] =
56 &mouse_device,
57 &keyboard_device,
58 &joystick_linuxinput_device,
59 &joystick_linux_device
61 #define NB_DINPUT_DEVICES (sizeof(dinput_devices)/sizeof(dinput_devices[0]))
63 HINSTANCE DINPUT_instance = NULL;
65 BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserv)
67 switch(reason)
69 case DLL_PROCESS_ATTACH:
70 DisableThreadLibraryCalls(inst);
71 DINPUT_instance = inst;
72 break;
73 case DLL_PROCESS_DETACH:
74 break;
76 return TRUE;
80 /******************************************************************************
81 * DirectInputCreateEx (DINPUT.@)
83 HRESULT WINAPI DirectInputCreateEx(
84 HINSTANCE hinst, DWORD dwVersion, REFIID riid, LPVOID *ppDI,
85 LPUNKNOWN punkOuter)
87 IDirectInputImpl* This;
89 TRACE("(0x%08lx,%04lx,%s,%p,%p)\n", (DWORD)hinst,dwVersion,debugstr_guid(riid),ppDI,punkOuter);
91 if (IsEqualGUID(&IID_IDirectInputA,riid) ||
92 IsEqualGUID(&IID_IDirectInput2A,riid) ||
93 IsEqualGUID(&IID_IDirectInput7A,riid)) {
94 This = HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputImpl));
95 This->lpVtbl = &ddi7avt;
96 This->ref = 1;
97 This->version = 1;
98 *ppDI = This;
100 return DI_OK;
103 if (IsEqualGUID(&IID_IDirectInputW,riid) ||
104 IsEqualGUID(&IID_IDirectInput2W,riid) ||
105 IsEqualGUID(&IID_IDirectInput7W,riid)) {
106 This = HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputImpl));
107 This->lpVtbl = &ddi7wvt;
108 This->ref = 1;
109 This->version = 1;
110 *ppDI = This;
112 return DI_OK;
115 if (IsEqualGUID(&IID_IDirectInput8A,riid)) {
116 This = HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputImpl));
117 This->lpVtbl = &ddi8avt;
118 This->ref = 1;
119 This->version = 8;
120 *ppDI = This;
122 return DI_OK;
125 if (IsEqualGUID(&IID_IDirectInput8W,riid)) {
126 This = HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputImpl));
127 This->lpVtbl = &ddi8wvt;
128 This->ref = 1;
129 This->version = 8;
130 *ppDI = This;
132 return DI_OK;
135 return DIERR_OLDDIRECTINPUTVERSION;
138 /******************************************************************************
139 * DirectInputCreateA (DINPUT.@)
141 HRESULT WINAPI DirectInputCreateA(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUTA *ppDI, LPUNKNOWN punkOuter)
143 IDirectInputImpl* This;
144 TRACE("(0x%08lx,%04lx,%p,%p)\n", (DWORD)hinst,dwVersion,ppDI,punkOuter);
145 This = HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputImpl));
146 This->lpVtbl = &ddi7avt;
147 This->ref = 1;
148 if (dwVersion >= 0x0800) {
149 This->version = 8;
150 } else {
151 /* We do not differientiate between version 1, 2 and 7 */
152 This->version = 1;
154 *ppDI = (IDirectInputA*)This;
155 return 0;
159 /******************************************************************************
160 * DirectInputCreateW (DINPUT.@)
162 HRESULT WINAPI DirectInputCreateW(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUTW *ppDI, LPUNKNOWN punkOuter)
164 IDirectInputImpl* This;
165 TRACE("(0x%08lx,%04lx,%p,%p)\n", (DWORD)hinst,dwVersion,ppDI,punkOuter);
166 This = HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputImpl));
167 This->lpVtbl = &ddi7wvt;
168 This->ref = 1;
169 if (dwVersion >= 0x0800) {
170 This->version = 8;
171 } else {
172 /* We do not differientiate between version 1, 2 and 7 */
173 This->version = 1;
175 *ppDI = (IDirectInputW*)This;
176 return 0;
179 static const char *_dump_DIDEVTYPE_value(DWORD dwDevType) {
180 switch (dwDevType) {
181 case 0: return "All devices";
182 case DIDEVTYPE_MOUSE: return "DIDEVTYPE_MOUSE";
183 case DIDEVTYPE_KEYBOARD: return "DIDEVTYPE_KEYBOARD";
184 case DIDEVTYPE_JOYSTICK: return "DIDEVTYPE_JOYSTICK";
185 case DIDEVTYPE_DEVICE: return "DIDEVTYPE_DEVICE";
186 default: return "Unkown";
190 static void _dump_EnumDevices_dwFlags(DWORD dwFlags) {
191 if (TRACE_ON(dinput)) {
192 unsigned int i;
193 static const struct {
194 DWORD mask;
195 const char *name;
196 } flags[] = {
197 #define FE(x) { x, #x}
198 FE(DIEDFL_ALLDEVICES),
199 FE(DIEDFL_ATTACHEDONLY),
200 FE(DIEDFL_FORCEFEEDBACK),
201 FE(DIEDFL_INCLUDEALIASES),
202 FE(DIEDFL_INCLUDEPHANTOMS)
203 #undef FE
205 if (dwFlags == 0) {
206 DPRINTF("DIEDFL_ALLDEVICES");
207 return;
209 for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++)
210 if (flags[i].mask & dwFlags)
211 DPRINTF("%s ",flags[i].name);
215 /******************************************************************************
216 * IDirectInputA_EnumDevices
218 static HRESULT WINAPI IDirectInputAImpl_EnumDevices(
219 LPDIRECTINPUT7A iface, DWORD dwDevType, LPDIENUMDEVICESCALLBACKA lpCallback,
220 LPVOID pvRef, DWORD dwFlags)
222 IDirectInputImpl *This = (IDirectInputImpl *)iface;
223 DIDEVICEINSTANCEA devInstance;
224 int i, j, r;
226 TRACE("(this=%p,0x%04lx '%s',%p,%p,%04lx)\n",
227 This, dwDevType, _dump_DIDEVTYPE_value(dwDevType),
228 lpCallback, pvRef, dwFlags);
229 TRACE(" flags: "); _dump_EnumDevices_dwFlags(dwFlags); TRACE("\n");
231 for (i = 0; i < NB_DINPUT_DEVICES; i++) {
232 if (!dinput_devices[i]->enum_deviceA) continue;
233 for (j = 0, r = -1; r != 0; j++) {
234 devInstance.dwSize = sizeof(devInstance);
235 TRACE(" - checking device %d ('%s')\n", i, dinput_devices[i]->name);
236 if ((r = dinput_devices[i]->enum_deviceA(dwDevType, dwFlags, &devInstance, This->version, j))) {
237 if (lpCallback(&devInstance,pvRef) == DIENUM_STOP)
238 return 0;
243 return 0;
245 /******************************************************************************
246 * IDirectInputW_EnumDevices
248 static HRESULT WINAPI IDirectInputWImpl_EnumDevices(
249 LPDIRECTINPUT7W iface, DWORD dwDevType, LPDIENUMDEVICESCALLBACKW lpCallback,
250 LPVOID pvRef, DWORD dwFlags)
252 IDirectInputImpl *This = (IDirectInputImpl *)iface;
253 DIDEVICEINSTANCEW devInstance;
254 int i, j, r;
256 TRACE("(this=%p,0x%04lx '%s',%p,%p,%04lx)\n",
257 This, dwDevType, _dump_DIDEVTYPE_value(dwDevType),
258 lpCallback, pvRef, dwFlags);
259 TRACE(" flags: "); _dump_EnumDevices_dwFlags(dwFlags); TRACE("\n");
261 for (i = 0; i < NB_DINPUT_DEVICES; i++) {
262 if (!dinput_devices[i]->enum_deviceW) continue;
263 for (j = 0, r = -1; r != 0; j++) {
264 devInstance.dwSize = sizeof(devInstance);
265 TRACE(" - checking device %d ('%s')\n", i, dinput_devices[i]->name);
266 if ((r = dinput_devices[i]->enum_deviceW(dwDevType, dwFlags, &devInstance, This->version, j))) {
267 if (lpCallback(&devInstance,pvRef) == DIENUM_STOP)
268 return 0;
273 return 0;
276 static ULONG WINAPI IDirectInputAImpl_AddRef(LPDIRECTINPUT7A iface)
278 IDirectInputImpl *This = (IDirectInputImpl *)iface;
279 return InterlockedIncrement((&This->ref));
282 static ULONG WINAPI IDirectInputAImpl_Release(LPDIRECTINPUT7A iface)
284 IDirectInputImpl *This = (IDirectInputImpl *)iface;
285 ULONG ref;
286 ref = InterlockedDecrement(&(This->ref));
287 if (ref == 0)
288 HeapFree(GetProcessHeap(),0,This);
289 return ref;
292 static HRESULT WINAPI IDirectInputAImpl_QueryInterface(LPDIRECTINPUT7A iface, REFIID riid, LPVOID *ppobj) {
293 IDirectInputImpl *This = (IDirectInputImpl *)iface;
295 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
296 if (IsEqualGUID(&IID_IUnknown,riid) ||
297 IsEqualGUID(&IID_IDirectInputA,riid) ||
298 IsEqualGUID(&IID_IDirectInput2A,riid) ||
299 IsEqualGUID(&IID_IDirectInput7A,riid)) {
300 IDirectInputAImpl_AddRef(iface);
301 *ppobj = This;
302 return 0;
304 TRACE("Unsupported interface !\n");
305 return E_FAIL;
308 static HRESULT WINAPI IDirectInputWImpl_QueryInterface(LPDIRECTINPUT7W iface, REFIID riid, LPVOID *ppobj) {
309 IDirectInputImpl *This = (IDirectInputImpl *)iface;
311 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
312 if (IsEqualGUID(&IID_IUnknown,riid) ||
313 IsEqualGUID(&IID_IDirectInputW,riid) ||
314 IsEqualGUID(&IID_IDirectInput2W,riid) ||
315 IsEqualGUID(&IID_IDirectInput7W,riid)) {
316 IDirectInputAImpl_AddRef((LPDIRECTINPUT7A) iface);
317 *ppobj = This;
318 return 0;
320 TRACE("Unsupported interface !\n");
321 return E_FAIL;
324 static HRESULT WINAPI IDirectInputAImpl_CreateDevice(
325 LPDIRECTINPUT7A iface,REFGUID rguid,LPDIRECTINPUTDEVICEA* pdev,
326 LPUNKNOWN punk
328 IDirectInputImpl *This = (IDirectInputImpl *)iface;
329 HRESULT ret_value = DIERR_DEVICENOTREG;
330 int i;
332 TRACE("(this=%p,%s,%p,%p)\n",This,debugstr_guid(rguid),pdev,punk);
334 /* Loop on all the devices to see if anyone matches the given GUID */
335 for (i = 0; i < NB_DINPUT_DEVICES; i++) {
336 HRESULT ret;
337 if (!dinput_devices[i]->create_deviceA) continue;
338 if ((ret = dinput_devices[i]->create_deviceA(This, rguid, NULL, pdev)) == DI_OK)
339 return DI_OK;
341 if (ret == DIERR_NOINTERFACE)
342 ret_value = DIERR_NOINTERFACE;
345 return ret_value;
348 static HRESULT WINAPI IDirectInputWImpl_CreateDevice(LPDIRECTINPUT7A iface,
349 REFGUID rguid, LPDIRECTINPUTDEVICEW* pdev, LPUNKNOWN punk) {
350 IDirectInputImpl *This = (IDirectInputImpl *)iface;
351 HRESULT ret_value = DIERR_DEVICENOTREG;
352 int i;
354 TRACE("(this=%p,%s,%p,%p)\n",This,debugstr_guid(rguid),pdev,punk);
356 /* Loop on all the devices to see if anyone matches the given GUID */
357 for (i = 0; i < NB_DINPUT_DEVICES; i++) {
358 HRESULT ret;
359 if (!dinput_devices[i]->create_deviceW) continue;
360 if ((ret = dinput_devices[i]->create_deviceW(This, rguid, NULL, pdev)) == DI_OK)
361 return DI_OK;
363 if (ret == DIERR_NOINTERFACE)
364 ret_value = DIERR_NOINTERFACE;
367 return ret_value;
370 static HRESULT WINAPI IDirectInputAImpl_Initialize(LPDIRECTINPUT7A iface, HINSTANCE hinst, DWORD x) {
371 return DIERR_ALREADYINITIALIZED;
374 static HRESULT WINAPI IDirectInputAImpl_GetDeviceStatus(LPDIRECTINPUT7A iface,
375 REFGUID rguid) {
376 IDirectInputImpl *This = (IDirectInputImpl *)iface;
378 FIXME("(%p)->(%s): stub\n",This,debugstr_guid(rguid));
380 return DI_OK;
383 static HRESULT WINAPI IDirectInputAImpl_RunControlPanel(LPDIRECTINPUT7A iface,
384 HWND hwndOwner,
385 DWORD dwFlags) {
386 IDirectInputImpl *This = (IDirectInputImpl *)iface;
387 FIXME("(%p)->(%08lx,%08lx): stub\n",This, (DWORD) hwndOwner, dwFlags);
389 return DI_OK;
392 static HRESULT WINAPI IDirectInput2AImpl_FindDevice(LPDIRECTINPUT7A iface, REFGUID rguid,
393 LPCSTR pszName, LPGUID pguidInstance) {
394 IDirectInputImpl *This = (IDirectInputImpl *)iface;
395 FIXME("(%p)->(%s, %s, %p): stub\n", This, debugstr_guid(rguid), pszName, pguidInstance);
397 return DI_OK;
400 static HRESULT WINAPI IDirectInput2WImpl_FindDevice(LPDIRECTINPUT7W iface, REFGUID rguid,
401 LPCWSTR pszName, LPGUID pguidInstance) {
402 IDirectInputImpl *This = (IDirectInputImpl *)iface;
403 FIXME("(%p)->(%s, %s, %p): stub\n", This, debugstr_guid(rguid), debugstr_w(pszName), pguidInstance);
405 return DI_OK;
408 static HRESULT WINAPI IDirectInput7AImpl_CreateDeviceEx(LPDIRECTINPUT7A iface, REFGUID rguid,
409 REFIID riid, LPVOID* pvOut, LPUNKNOWN lpUnknownOuter)
411 IDirectInputImpl *This = (IDirectInputImpl *)iface;
412 HRESULT ret_value = DIERR_DEVICENOTREG;
413 int i;
415 TRACE("(%p)->(%s, %s, %p, %p)\n", This, debugstr_guid(rguid), debugstr_guid(riid), pvOut, lpUnknownOuter);
417 /* Loop on all the devices to see if anyone matches the given GUID */
418 for (i = 0; i < NB_DINPUT_DEVICES; i++) {
419 HRESULT ret;
420 if (!dinput_devices[i]->create_deviceA) continue;
421 if ((ret = dinput_devices[i]->create_deviceA(This, rguid, riid, (LPDIRECTINPUTDEVICEA*) pvOut)) == DI_OK)
422 return DI_OK;
424 if (ret == DIERR_NOINTERFACE)
425 ret_value = DIERR_NOINTERFACE;
428 return ret_value;
431 static HRESULT WINAPI IDirectInput7WImpl_CreateDeviceEx(LPDIRECTINPUT7W iface, REFGUID rguid,
432 REFIID riid, LPVOID* pvOut, LPUNKNOWN lpUnknownOuter)
434 IDirectInputImpl *This = (IDirectInputImpl *)iface;
435 HRESULT ret_value = DIERR_DEVICENOTREG;
436 int i;
438 TRACE("(%p)->(%s, %s, %p, %p)\n", This, debugstr_guid(rguid), debugstr_guid(riid), pvOut, lpUnknownOuter);
440 /* Loop on all the devices to see if anyone matches the given GUID */
441 for (i = 0; i < NB_DINPUT_DEVICES; i++) {
442 HRESULT ret;
443 if (!dinput_devices[i]->create_deviceW) continue;
444 if ((ret = dinput_devices[i]->create_deviceW(This, rguid, riid, (LPDIRECTINPUTDEVICEW*) pvOut)) == DI_OK)
445 return DI_OK;
447 if (ret == DIERR_NOINTERFACE)
448 ret_value = DIERR_NOINTERFACE;
451 return ret_value;
454 static HRESULT WINAPI IDirectInput8AImpl_QueryInterface(LPDIRECTINPUT8A iface, REFIID riid, LPVOID *ppobj) {
455 IDirectInputImpl *This = (IDirectInputImpl *)iface;
457 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
458 if (IsEqualGUID(&IID_IUnknown,riid) ||
459 IsEqualGUID(&IID_IDirectInput8A,riid)) {
460 IDirectInputAImpl_AddRef((LPDIRECTINPUT7A) iface);
461 *ppobj = This;
462 return 0;
464 TRACE("Unsupported interface !\n");
465 return E_NOINTERFACE;
468 static HRESULT WINAPI IDirectInput8WImpl_QueryInterface(LPDIRECTINPUT8W iface, REFIID riid, LPVOID *ppobj) {
469 IDirectInputImpl *This = (IDirectInputImpl *)iface;
471 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
472 if (IsEqualGUID(&IID_IUnknown,riid) ||
473 IsEqualGUID(&IID_IDirectInput8W,riid)) {
474 IDirectInputAImpl_AddRef((LPDIRECTINPUT7A) iface);
475 *ppobj = This;
476 return 0;
478 TRACE("Unsupported interface !\n");
479 return E_NOINTERFACE;
482 static HRESULT WINAPI IDirectInput8AImpl_EnumDevicesBySemantics(
483 LPDIRECTINPUT8A iface, LPCSTR ptszUserName, LPDIACTIONFORMATA lpdiActionFormat,
484 LPDIENUMDEVICESBYSEMANTICSCBA lpCallback,
485 LPVOID pvRef, DWORD dwFlags
488 IDirectInputImpl *This = (IDirectInputImpl *)iface;
490 FIXME("(this=%p,%s,%p,%p,%p,%04lx): stub\n", This, ptszUserName, lpdiActionFormat,
491 lpCallback, pvRef, dwFlags);
492 return 0;
495 static HRESULT WINAPI IDirectInput8WImpl_EnumDevicesBySemantics(
496 LPDIRECTINPUT8W iface, LPCWSTR ptszUserName, LPDIACTIONFORMATW lpdiActionFormat,
497 LPDIENUMDEVICESBYSEMANTICSCBW lpCallback,
498 LPVOID pvRef, DWORD dwFlags
501 IDirectInputImpl *This = (IDirectInputImpl *)iface;
503 FIXME("(this=%p,%s,%p,%p,%p,%04lx): stub\n", This, debugstr_w(ptszUserName), lpdiActionFormat,
504 lpCallback, pvRef, dwFlags);
505 return 0;
508 static HRESULT WINAPI IDirectInput8AImpl_ConfigureDevices(
509 LPDIRECTINPUT8A iface, LPDICONFIGUREDEVICESCALLBACK lpdiCallback,
510 LPDICONFIGUREDEVICESPARAMSA lpdiCDParams, DWORD dwFlags, LPVOID pvRefData
513 IDirectInputImpl *This = (IDirectInputImpl *)iface;
515 FIXME("(this=%p,%p,%p,%04lx,%p): stub\n", This, lpdiCallback, lpdiCDParams,
516 dwFlags, pvRefData);
517 return 0;
520 static HRESULT WINAPI IDirectInput8WImpl_ConfigureDevices(
521 LPDIRECTINPUT8W iface, LPDICONFIGUREDEVICESCALLBACK lpdiCallback,
522 LPDICONFIGUREDEVICESPARAMSW lpdiCDParams, DWORD dwFlags, LPVOID pvRefData
525 IDirectInputImpl *This = (IDirectInputImpl *)iface;
527 FIXME("(this=%p,%p,%p,%04lx,%p): stub\n", This, lpdiCallback, lpdiCDParams,
528 dwFlags, pvRefData);
529 return 0;
532 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
533 # define XCAST(fun) (typeof(ddi7avt.fun))
534 #else
535 # define XCAST(fun) (void*)
536 #endif
538 static IDirectInput7AVtbl ddi7avt = {
539 XCAST(QueryInterface)IDirectInputAImpl_QueryInterface,
540 XCAST(AddRef)IDirectInputAImpl_AddRef,
541 XCAST(Release)IDirectInputAImpl_Release,
542 XCAST(CreateDevice)IDirectInputAImpl_CreateDevice,
543 XCAST(EnumDevices)IDirectInputAImpl_EnumDevices,
544 XCAST(GetDeviceStatus)IDirectInputAImpl_GetDeviceStatus,
545 XCAST(RunControlPanel)IDirectInputAImpl_RunControlPanel,
546 XCAST(Initialize)IDirectInputAImpl_Initialize,
547 XCAST(FindDevice)IDirectInput2AImpl_FindDevice,
548 XCAST(CreateDeviceEx)IDirectInput7AImpl_CreateDeviceEx
551 #undef XCAST
552 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
553 # define XCAST(fun) (typeof(ddi7wvt.fun))
554 #else
555 # define XCAST(fun) (void*)
556 #endif
558 static IDirectInput7WVtbl ddi7wvt = {
559 XCAST(QueryInterface)IDirectInputWImpl_QueryInterface,
560 XCAST(AddRef)IDirectInputAImpl_AddRef,
561 XCAST(Release)IDirectInputAImpl_Release,
562 XCAST(CreateDevice)IDirectInputWImpl_CreateDevice,
563 XCAST(EnumDevices)IDirectInputWImpl_EnumDevices,
564 XCAST(GetDeviceStatus)IDirectInputAImpl_GetDeviceStatus,
565 XCAST(RunControlPanel)IDirectInputAImpl_RunControlPanel,
566 XCAST(Initialize)IDirectInputAImpl_Initialize,
567 XCAST(FindDevice)IDirectInput2WImpl_FindDevice,
568 XCAST(CreateDeviceEx)IDirectInput7WImpl_CreateDeviceEx
570 #undef XCAST
572 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
573 # define XCAST(fun) (typeof(ddi8avt.fun))
574 #else
575 # define XCAST(fun) (void*)
576 #endif
578 static IDirectInput8AVtbl ddi8avt = {
579 XCAST(QueryInterface)IDirectInput8AImpl_QueryInterface,
580 XCAST(AddRef)IDirectInputAImpl_AddRef,
581 XCAST(Release)IDirectInputAImpl_Release,
582 XCAST(CreateDevice)IDirectInputAImpl_CreateDevice,
583 XCAST(EnumDevices)IDirectInputAImpl_EnumDevices,
584 XCAST(GetDeviceStatus)IDirectInputAImpl_GetDeviceStatus,
585 XCAST(RunControlPanel)IDirectInputAImpl_RunControlPanel,
586 XCAST(Initialize)IDirectInputAImpl_Initialize,
587 XCAST(FindDevice)IDirectInput2AImpl_FindDevice,
588 XCAST(EnumDevicesBySemantics)IDirectInput8AImpl_EnumDevicesBySemantics,
589 XCAST(ConfigureDevices)IDirectInput8AImpl_ConfigureDevices
591 #undef XCAST
593 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
594 # define XCAST(fun) (typeof(ddi8wvt.fun))
595 #else
596 # define XCAST(fun) (void*)
597 #endif
598 static IDirectInput8WVtbl ddi8wvt = {
599 XCAST(QueryInterface)IDirectInput8WImpl_QueryInterface,
600 XCAST(AddRef)IDirectInputAImpl_AddRef,
601 XCAST(Release)IDirectInputAImpl_Release,
602 XCAST(CreateDevice)IDirectInputWImpl_CreateDevice,
603 XCAST(EnumDevices)IDirectInputWImpl_EnumDevices,
604 XCAST(GetDeviceStatus)IDirectInputAImpl_GetDeviceStatus,
605 XCAST(RunControlPanel)IDirectInputAImpl_RunControlPanel,
606 XCAST(Initialize)IDirectInputAImpl_Initialize,
607 XCAST(FindDevice)IDirectInput2WImpl_FindDevice,
608 XCAST(EnumDevicesBySemantics)IDirectInput8WImpl_EnumDevicesBySemantics,
609 XCAST(ConfigureDevices)IDirectInput8WImpl_ConfigureDevices
611 #undef XCAST
613 /*******************************************************************************
614 * DirectInput ClassFactory
616 typedef struct
618 /* IUnknown fields */
619 IClassFactoryVtbl *lpVtbl;
620 DWORD ref;
621 } IClassFactoryImpl;
623 static HRESULT WINAPI DICF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
624 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
626 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
627 return E_NOINTERFACE;
630 static ULONG WINAPI DICF_AddRef(LPCLASSFACTORY iface) {
631 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
632 return InterlockedIncrement(&(This->ref));
635 static ULONG WINAPI DICF_Release(LPCLASSFACTORY iface) {
636 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
637 /* static class, won't be freed */
638 return InterlockedDecrement(&(This->ref));
641 static HRESULT WINAPI DICF_CreateInstance(
642 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
644 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
646 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
647 if ( IsEqualGUID( &IID_IDirectInputA, riid ) ||
648 IsEqualGUID( &IID_IDirectInputW, riid ) ||
649 IsEqualGUID( &IID_IDirectInput2A, riid ) ||
650 IsEqualGUID( &IID_IDirectInput2W, riid ) ||
651 IsEqualGUID( &IID_IDirectInput7A, riid ) ||
652 IsEqualGUID( &IID_IDirectInput7W, riid ) ||
653 IsEqualGUID( &IID_IDirectInput8A, riid ) ||
654 IsEqualGUID( &IID_IDirectInput8W, riid ) ) {
655 /* FIXME: reuse already created dinput if present? */
656 return DirectInputCreateEx(0,0,riid,ppobj,pOuter);
659 FIXME("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj);
660 return E_NOINTERFACE;
663 static HRESULT WINAPI DICF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
664 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
665 FIXME("(%p)->(%d),stub!\n",This,dolock);
666 return S_OK;
669 static IClassFactoryVtbl DICF_Vtbl = {
670 DICF_QueryInterface,
671 DICF_AddRef,
672 DICF_Release,
673 DICF_CreateInstance,
674 DICF_LockServer
676 static IClassFactoryImpl DINPUT_CF = {&DICF_Vtbl, 1 };
678 /***********************************************************************
679 * DllCanUnloadNow (DINPUT.@)
681 HRESULT WINAPI DINPUT_DllCanUnloadNow(void)
683 FIXME("(void): stub\n");
685 return S_FALSE;
688 /***********************************************************************
689 * DllGetClassObject (DINPUT.@)
691 HRESULT WINAPI DINPUT_DllGetClassObject(REFCLSID rclsid, REFIID riid,
692 LPVOID *ppv)
694 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
695 if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
696 *ppv = (LPVOID)&DINPUT_CF;
697 IClassFactory_AddRef((IClassFactory*)*ppv);
698 return S_OK;
701 FIXME("(%s,%s,%p): no interface found.\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
702 return CLASS_E_CLASSNOTAVAILABLE;