d3d: Don't crash when SetRenderTarget() is called with a NULL pSurface.
[wine/hacks.git] / dlls / dinput / dinput_main.c
blobcef61b7c99a875dbadfff25a941387d13d69b08f
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 const IDirectInput7AVtbl ddi7avt;
50 static const IDirectInput7WVtbl ddi7wvt;
51 static const IDirectInput8AVtbl ddi8avt;
52 static const 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;
88 HRESULT res = DIERR_OLDDIRECTINPUTVERSION;
89 LPCVOID vtable = NULL;
91 TRACE("(%p,%04lx,%s,%p,%p)\n", hinst,dwVersion,debugstr_guid(riid),ppDI,punkOuter);
93 if (IsEqualGUID(&IID_IDirectInputA,riid) ||
94 IsEqualGUID(&IID_IDirectInput2A,riid) ||
95 IsEqualGUID(&IID_IDirectInput7A,riid))
97 vtable = &ddi7avt;
98 res = DI_OK;
101 if (IsEqualGUID(&IID_IDirectInputW,riid) ||
102 IsEqualGUID(&IID_IDirectInput2W,riid) ||
103 IsEqualGUID(&IID_IDirectInput7W,riid))
105 vtable = &ddi7wvt;
106 res = DI_OK;
109 if (IsEqualGUID(&IID_IDirectInput8A,riid))
111 vtable = &ddi8avt;
112 res = DI_OK;
115 if (IsEqualGUID(&IID_IDirectInput8W,riid))
117 vtable = &ddi8wvt;
118 res = DI_OK;
121 if (res == DI_OK)
123 This = HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectInputImpl));
124 This->lpVtbl = vtable;
125 This->ref = 1;
126 This->dwVersion = dwVersion;
127 This->evsequence = 1;
128 *ppDI = This;
130 return res;
133 /******************************************************************************
134 * DirectInputCreateA (DINPUT.@)
136 HRESULT WINAPI DirectInputCreateA(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUTA *ppDI, LPUNKNOWN punkOuter)
138 return DirectInputCreateEx(hinst, dwVersion, &IID_IDirectInput7A, (LPVOID *)ppDI, punkOuter);
141 /******************************************************************************
142 * DirectInputCreateW (DINPUT.@)
144 HRESULT WINAPI DirectInputCreateW(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUTW *ppDI, LPUNKNOWN punkOuter)
146 return DirectInputCreateEx(hinst, dwVersion, &IID_IDirectInput7W, (LPVOID *)ppDI, punkOuter);
149 static const char *_dump_DIDEVTYPE_value(DWORD dwDevType) {
150 switch (dwDevType) {
151 case 0: return "All devices";
152 case DIDEVTYPE_MOUSE: return "DIDEVTYPE_MOUSE";
153 case DIDEVTYPE_KEYBOARD: return "DIDEVTYPE_KEYBOARD";
154 case DIDEVTYPE_JOYSTICK: return "DIDEVTYPE_JOYSTICK";
155 case DIDEVTYPE_DEVICE: return "DIDEVTYPE_DEVICE";
156 default: return "Unknown";
160 static void _dump_EnumDevices_dwFlags(DWORD dwFlags) {
161 if (TRACE_ON(dinput)) {
162 unsigned int i;
163 static const struct {
164 DWORD mask;
165 const char *name;
166 } flags[] = {
167 #define FE(x) { x, #x}
168 FE(DIEDFL_ALLDEVICES),
169 FE(DIEDFL_ATTACHEDONLY),
170 FE(DIEDFL_FORCEFEEDBACK),
171 FE(DIEDFL_INCLUDEALIASES),
172 FE(DIEDFL_INCLUDEPHANTOMS)
173 #undef FE
175 if (dwFlags == 0) {
176 DPRINTF("DIEDFL_ALLDEVICES");
177 return;
179 for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++)
180 if (flags[i].mask & dwFlags)
181 DPRINTF("%s ",flags[i].name);
185 /******************************************************************************
186 * IDirectInputA_EnumDevices
188 static HRESULT WINAPI IDirectInputAImpl_EnumDevices(
189 LPDIRECTINPUT7A iface, DWORD dwDevType, LPDIENUMDEVICESCALLBACKA lpCallback,
190 LPVOID pvRef, DWORD dwFlags)
192 IDirectInputImpl *This = (IDirectInputImpl *)iface;
193 DIDEVICEINSTANCEA devInstance;
194 int i, j, r;
196 TRACE("(this=%p,0x%04lx '%s',%p,%p,%04lx)\n",
197 This, dwDevType, _dump_DIDEVTYPE_value(dwDevType),
198 lpCallback, pvRef, dwFlags);
199 TRACE(" flags: "); _dump_EnumDevices_dwFlags(dwFlags); TRACE("\n");
201 for (i = 0; i < NB_DINPUT_DEVICES; i++) {
202 if (!dinput_devices[i]->enum_deviceA) continue;
203 for (j = 0, r = -1; r != 0; j++) {
204 devInstance.dwSize = sizeof(devInstance);
205 TRACE(" - checking device %d ('%s')\n", i, dinput_devices[i]->name);
206 if ((r = dinput_devices[i]->enum_deviceA(dwDevType, dwFlags, &devInstance, This->dwVersion, j))) {
207 if (lpCallback(&devInstance,pvRef) == DIENUM_STOP)
208 return 0;
213 return 0;
215 /******************************************************************************
216 * IDirectInputW_EnumDevices
218 static HRESULT WINAPI IDirectInputWImpl_EnumDevices(
219 LPDIRECTINPUT7W iface, DWORD dwDevType, LPDIENUMDEVICESCALLBACKW lpCallback,
220 LPVOID pvRef, DWORD dwFlags)
222 IDirectInputImpl *This = (IDirectInputImpl *)iface;
223 DIDEVICEINSTANCEW 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_deviceW) 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_deviceW(dwDevType, dwFlags, &devInstance, This->dwVersion, j))) {
237 if (lpCallback(&devInstance,pvRef) == DIENUM_STOP)
238 return 0;
243 return 0;
246 static ULONG WINAPI IDirectInputAImpl_AddRef(LPDIRECTINPUT7A iface)
248 IDirectInputImpl *This = (IDirectInputImpl *)iface;
249 return InterlockedIncrement((&This->ref));
252 static ULONG WINAPI IDirectInputAImpl_Release(LPDIRECTINPUT7A iface)
254 IDirectInputImpl *This = (IDirectInputImpl *)iface;
255 ULONG ref;
256 ref = InterlockedDecrement(&(This->ref));
257 if (ref == 0)
258 HeapFree(GetProcessHeap(),0,This);
259 return ref;
262 static HRESULT WINAPI IDirectInputAImpl_QueryInterface(LPDIRECTINPUT7A iface, REFIID riid, LPVOID *ppobj) {
263 IDirectInputImpl *This = (IDirectInputImpl *)iface;
265 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
266 if (IsEqualGUID(&IID_IUnknown,riid) ||
267 IsEqualGUID(&IID_IDirectInputA,riid) ||
268 IsEqualGUID(&IID_IDirectInput2A,riid) ||
269 IsEqualGUID(&IID_IDirectInput7A,riid)) {
270 IDirectInputAImpl_AddRef(iface);
271 *ppobj = This;
272 return 0;
274 TRACE("Unsupported interface !\n");
275 return E_FAIL;
278 static HRESULT WINAPI IDirectInputWImpl_QueryInterface(LPDIRECTINPUT7W iface, REFIID riid, LPVOID *ppobj) {
279 IDirectInputImpl *This = (IDirectInputImpl *)iface;
281 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
282 if (IsEqualGUID(&IID_IUnknown,riid) ||
283 IsEqualGUID(&IID_IDirectInputW,riid) ||
284 IsEqualGUID(&IID_IDirectInput2W,riid) ||
285 IsEqualGUID(&IID_IDirectInput7W,riid)) {
286 IDirectInputAImpl_AddRef((LPDIRECTINPUT7A) iface);
287 *ppobj = This;
288 return 0;
290 TRACE("Unsupported interface !\n");
291 return E_FAIL;
294 static HRESULT WINAPI IDirectInputAImpl_CreateDevice(
295 LPDIRECTINPUT7A iface,REFGUID rguid,LPDIRECTINPUTDEVICEA* pdev,
296 LPUNKNOWN punk
298 IDirectInputImpl *This = (IDirectInputImpl *)iface;
299 HRESULT ret_value = DIERR_DEVICENOTREG;
300 int i;
302 TRACE("(this=%p,%s,%p,%p)\n",This,debugstr_guid(rguid),pdev,punk);
304 if (pdev == NULL) {
305 WARN("invalid pointer: pdev == NULL\n");
306 return E_POINTER;
309 if (rguid == NULL) {
310 WARN("invalid pointer: rguid == NULL\n");
311 return E_POINTER;
314 /* Loop on all the devices to see if anyone matches the given GUID */
315 for (i = 0; i < NB_DINPUT_DEVICES; i++) {
316 HRESULT ret;
317 if (!dinput_devices[i]->create_deviceA) continue;
318 if ((ret = dinput_devices[i]->create_deviceA(This, rguid, NULL, pdev)) == DI_OK)
319 return DI_OK;
321 if (ret == DIERR_NOINTERFACE)
322 ret_value = DIERR_NOINTERFACE;
325 return ret_value;
328 static HRESULT WINAPI IDirectInputWImpl_CreateDevice(LPDIRECTINPUT7W iface,
329 REFGUID rguid, LPDIRECTINPUTDEVICEW* pdev, LPUNKNOWN punk) {
330 IDirectInputImpl *This = (IDirectInputImpl *)iface;
331 HRESULT ret_value = DIERR_DEVICENOTREG;
332 int i;
334 TRACE("(this=%p,%s,%p,%p)\n",This,debugstr_guid(rguid),pdev,punk);
336 /* Loop on all the devices to see if anyone matches the given GUID */
337 for (i = 0; i < NB_DINPUT_DEVICES; i++) {
338 HRESULT ret;
339 if (!dinput_devices[i]->create_deviceW) continue;
340 if ((ret = dinput_devices[i]->create_deviceW(This, rguid, NULL, pdev)) == DI_OK)
341 return DI_OK;
343 if (ret == DIERR_NOINTERFACE)
344 ret_value = DIERR_NOINTERFACE;
347 return ret_value;
350 static HRESULT WINAPI IDirectInputAImpl_Initialize(LPDIRECTINPUT7A iface, HINSTANCE hinst, DWORD x) {
351 TRACE("(this=%p,%p,%lx)\n",iface, hinst, x);
353 /* Initialize can return: DIERR_BETADIRECTINPUTVERSION, DIERR_OLDDIRECTINPUTVERSION and DI_OK.
354 * Since we already initialized the device, return DI_OK. In the past we returned DIERR_ALREADYINITIALIZED
355 * which broke applications like Tomb Raider Legend because it isn't a legal return value.
357 return DI_OK;
360 static HRESULT WINAPI IDirectInputAImpl_GetDeviceStatus(LPDIRECTINPUT7A iface,
361 REFGUID rguid) {
362 IDirectInputImpl *This = (IDirectInputImpl *)iface;
364 FIXME("(%p)->(%s): stub\n",This,debugstr_guid(rguid));
366 return DI_OK;
369 static HRESULT WINAPI IDirectInputAImpl_RunControlPanel(LPDIRECTINPUT7A iface,
370 HWND hwndOwner,
371 DWORD dwFlags) {
372 IDirectInputImpl *This = (IDirectInputImpl *)iface;
373 FIXME("(%p)->(%p,%08lx): stub\n",This, hwndOwner, dwFlags);
375 return DI_OK;
378 static HRESULT WINAPI IDirectInput2AImpl_FindDevice(LPDIRECTINPUT7A iface, REFGUID rguid,
379 LPCSTR pszName, LPGUID pguidInstance) {
380 IDirectInputImpl *This = (IDirectInputImpl *)iface;
381 FIXME("(%p)->(%s, %s, %p): stub\n", This, debugstr_guid(rguid), pszName, pguidInstance);
383 return DI_OK;
386 static HRESULT WINAPI IDirectInput2WImpl_FindDevice(LPDIRECTINPUT7W iface, REFGUID rguid,
387 LPCWSTR pszName, LPGUID pguidInstance) {
388 IDirectInputImpl *This = (IDirectInputImpl *)iface;
389 FIXME("(%p)->(%s, %s, %p): stub\n", This, debugstr_guid(rguid), debugstr_w(pszName), pguidInstance);
391 return DI_OK;
394 static HRESULT WINAPI IDirectInput7AImpl_CreateDeviceEx(LPDIRECTINPUT7A iface, REFGUID rguid,
395 REFIID riid, LPVOID* pvOut, LPUNKNOWN lpUnknownOuter)
397 IDirectInputImpl *This = (IDirectInputImpl *)iface;
398 HRESULT ret_value = DIERR_DEVICENOTREG;
399 int i;
401 TRACE("(%p)->(%s, %s, %p, %p)\n", This, debugstr_guid(rguid), debugstr_guid(riid), pvOut, lpUnknownOuter);
403 /* Loop on all the devices to see if anyone matches the given GUID */
404 for (i = 0; i < NB_DINPUT_DEVICES; i++) {
405 HRESULT ret;
406 if (!dinput_devices[i]->create_deviceA) continue;
407 if ((ret = dinput_devices[i]->create_deviceA(This, rguid, riid, (LPDIRECTINPUTDEVICEA*) pvOut)) == DI_OK)
408 return DI_OK;
410 if (ret == DIERR_NOINTERFACE)
411 ret_value = DIERR_NOINTERFACE;
414 return ret_value;
417 static HRESULT WINAPI IDirectInput7WImpl_CreateDeviceEx(LPDIRECTINPUT7W iface, REFGUID rguid,
418 REFIID riid, LPVOID* pvOut, LPUNKNOWN lpUnknownOuter)
420 IDirectInputImpl *This = (IDirectInputImpl *)iface;
421 HRESULT ret_value = DIERR_DEVICENOTREG;
422 int i;
424 TRACE("(%p)->(%s, %s, %p, %p)\n", This, debugstr_guid(rguid), debugstr_guid(riid), pvOut, lpUnknownOuter);
426 /* Loop on all the devices to see if anyone matches the given GUID */
427 for (i = 0; i < NB_DINPUT_DEVICES; i++) {
428 HRESULT ret;
429 if (!dinput_devices[i]->create_deviceW) continue;
430 if ((ret = dinput_devices[i]->create_deviceW(This, rguid, riid, (LPDIRECTINPUTDEVICEW*) pvOut)) == DI_OK)
431 return DI_OK;
433 if (ret == DIERR_NOINTERFACE)
434 ret_value = DIERR_NOINTERFACE;
437 return ret_value;
440 static HRESULT WINAPI IDirectInput8AImpl_QueryInterface(LPDIRECTINPUT8A iface, REFIID riid, LPVOID *ppobj) {
441 IDirectInputImpl *This = (IDirectInputImpl *)iface;
443 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
444 if (IsEqualGUID(&IID_IUnknown,riid) ||
445 IsEqualGUID(&IID_IDirectInput8A,riid)) {
446 IDirectInputAImpl_AddRef((LPDIRECTINPUT7A) iface);
447 *ppobj = This;
448 return 0;
450 TRACE("Unsupported interface !\n");
451 return E_NOINTERFACE;
454 static HRESULT WINAPI IDirectInput8WImpl_QueryInterface(LPDIRECTINPUT8W 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_IDirectInput8W,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 IDirectInput8AImpl_EnumDevicesBySemantics(
469 LPDIRECTINPUT8A iface, LPCSTR ptszUserName, LPDIACTIONFORMATA lpdiActionFormat,
470 LPDIENUMDEVICESBYSEMANTICSCBA lpCallback,
471 LPVOID pvRef, DWORD dwFlags
474 IDirectInputImpl *This = (IDirectInputImpl *)iface;
476 FIXME("(this=%p,%s,%p,%p,%p,%04lx): stub\n", This, ptszUserName, lpdiActionFormat,
477 lpCallback, pvRef, dwFlags);
478 return 0;
481 static HRESULT WINAPI IDirectInput8WImpl_EnumDevicesBySemantics(
482 LPDIRECTINPUT8W iface, LPCWSTR ptszUserName, LPDIACTIONFORMATW lpdiActionFormat,
483 LPDIENUMDEVICESBYSEMANTICSCBW lpCallback,
484 LPVOID pvRef, DWORD dwFlags
487 IDirectInputImpl *This = (IDirectInputImpl *)iface;
489 FIXME("(this=%p,%s,%p,%p,%p,%04lx): stub\n", This, debugstr_w(ptszUserName), lpdiActionFormat,
490 lpCallback, pvRef, dwFlags);
491 return 0;
494 static HRESULT WINAPI IDirectInput8AImpl_ConfigureDevices(
495 LPDIRECTINPUT8A iface, LPDICONFIGUREDEVICESCALLBACK lpdiCallback,
496 LPDICONFIGUREDEVICESPARAMSA lpdiCDParams, DWORD dwFlags, LPVOID pvRefData
499 IDirectInputImpl *This = (IDirectInputImpl *)iface;
501 FIXME("(this=%p,%p,%p,%04lx,%p): stub\n", This, lpdiCallback, lpdiCDParams,
502 dwFlags, pvRefData);
503 return 0;
506 static HRESULT WINAPI IDirectInput8WImpl_ConfigureDevices(
507 LPDIRECTINPUT8W iface, LPDICONFIGUREDEVICESCALLBACK lpdiCallback,
508 LPDICONFIGUREDEVICESPARAMSW lpdiCDParams, DWORD dwFlags, LPVOID pvRefData
511 IDirectInputImpl *This = (IDirectInputImpl *)iface;
513 FIXME("(this=%p,%p,%p,%04lx,%p): stub\n", This, lpdiCallback, lpdiCDParams,
514 dwFlags, pvRefData);
515 return 0;
518 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
519 # define XCAST(fun) (typeof(ddi7avt.fun))
520 #else
521 # define XCAST(fun) (void*)
522 #endif
524 static const IDirectInput7AVtbl ddi7avt = {
525 XCAST(QueryInterface)IDirectInputAImpl_QueryInterface,
526 XCAST(AddRef)IDirectInputAImpl_AddRef,
527 XCAST(Release)IDirectInputAImpl_Release,
528 XCAST(CreateDevice)IDirectInputAImpl_CreateDevice,
529 XCAST(EnumDevices)IDirectInputAImpl_EnumDevices,
530 XCAST(GetDeviceStatus)IDirectInputAImpl_GetDeviceStatus,
531 XCAST(RunControlPanel)IDirectInputAImpl_RunControlPanel,
532 XCAST(Initialize)IDirectInputAImpl_Initialize,
533 XCAST(FindDevice)IDirectInput2AImpl_FindDevice,
534 XCAST(CreateDeviceEx)IDirectInput7AImpl_CreateDeviceEx
537 #undef XCAST
538 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
539 # define XCAST(fun) (typeof(ddi7wvt.fun))
540 #else
541 # define XCAST(fun) (void*)
542 #endif
544 static const IDirectInput7WVtbl ddi7wvt = {
545 XCAST(QueryInterface)IDirectInputWImpl_QueryInterface,
546 XCAST(AddRef)IDirectInputAImpl_AddRef,
547 XCAST(Release)IDirectInputAImpl_Release,
548 XCAST(CreateDevice)IDirectInputWImpl_CreateDevice,
549 XCAST(EnumDevices)IDirectInputWImpl_EnumDevices,
550 XCAST(GetDeviceStatus)IDirectInputAImpl_GetDeviceStatus,
551 XCAST(RunControlPanel)IDirectInputAImpl_RunControlPanel,
552 XCAST(Initialize)IDirectInputAImpl_Initialize,
553 XCAST(FindDevice)IDirectInput2WImpl_FindDevice,
554 XCAST(CreateDeviceEx)IDirectInput7WImpl_CreateDeviceEx
556 #undef XCAST
558 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
559 # define XCAST(fun) (typeof(ddi8avt.fun))
560 #else
561 # define XCAST(fun) (void*)
562 #endif
564 static const IDirectInput8AVtbl ddi8avt = {
565 XCAST(QueryInterface)IDirectInput8AImpl_QueryInterface,
566 XCAST(AddRef)IDirectInputAImpl_AddRef,
567 XCAST(Release)IDirectInputAImpl_Release,
568 XCAST(CreateDevice)IDirectInputAImpl_CreateDevice,
569 XCAST(EnumDevices)IDirectInputAImpl_EnumDevices,
570 XCAST(GetDeviceStatus)IDirectInputAImpl_GetDeviceStatus,
571 XCAST(RunControlPanel)IDirectInputAImpl_RunControlPanel,
572 XCAST(Initialize)IDirectInputAImpl_Initialize,
573 XCAST(FindDevice)IDirectInput2AImpl_FindDevice,
574 XCAST(EnumDevicesBySemantics)IDirectInput8AImpl_EnumDevicesBySemantics,
575 XCAST(ConfigureDevices)IDirectInput8AImpl_ConfigureDevices
577 #undef XCAST
579 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
580 # define XCAST(fun) (typeof(ddi8wvt.fun))
581 #else
582 # define XCAST(fun) (void*)
583 #endif
584 static const IDirectInput8WVtbl ddi8wvt = {
585 XCAST(QueryInterface)IDirectInput8WImpl_QueryInterface,
586 XCAST(AddRef)IDirectInputAImpl_AddRef,
587 XCAST(Release)IDirectInputAImpl_Release,
588 XCAST(CreateDevice)IDirectInputWImpl_CreateDevice,
589 XCAST(EnumDevices)IDirectInputWImpl_EnumDevices,
590 XCAST(GetDeviceStatus)IDirectInputAImpl_GetDeviceStatus,
591 XCAST(RunControlPanel)IDirectInputAImpl_RunControlPanel,
592 XCAST(Initialize)IDirectInputAImpl_Initialize,
593 XCAST(FindDevice)IDirectInput2WImpl_FindDevice,
594 XCAST(EnumDevicesBySemantics)IDirectInput8WImpl_EnumDevicesBySemantics,
595 XCAST(ConfigureDevices)IDirectInput8WImpl_ConfigureDevices
597 #undef XCAST
599 /*******************************************************************************
600 * DirectInput ClassFactory
602 typedef struct
604 /* IUnknown fields */
605 const IClassFactoryVtbl *lpVtbl;
606 LONG ref;
607 } IClassFactoryImpl;
609 static HRESULT WINAPI DICF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
610 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
612 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
613 return E_NOINTERFACE;
616 static ULONG WINAPI DICF_AddRef(LPCLASSFACTORY iface) {
617 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
618 return InterlockedIncrement(&(This->ref));
621 static ULONG WINAPI DICF_Release(LPCLASSFACTORY iface) {
622 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
623 /* static class, won't be freed */
624 return InterlockedDecrement(&(This->ref));
627 static HRESULT WINAPI DICF_CreateInstance(
628 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
630 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
632 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
633 if ( IsEqualGUID( &IID_IDirectInputA, riid ) ||
634 IsEqualGUID( &IID_IDirectInputW, riid ) ||
635 IsEqualGUID( &IID_IDirectInput2A, riid ) ||
636 IsEqualGUID( &IID_IDirectInput2W, riid ) ||
637 IsEqualGUID( &IID_IDirectInput7A, riid ) ||
638 IsEqualGUID( &IID_IDirectInput7W, riid ) ||
639 IsEqualGUID( &IID_IDirectInput8A, riid ) ||
640 IsEqualGUID( &IID_IDirectInput8W, riid ) ) {
641 /* FIXME: reuse already created dinput if present? */
642 return DirectInputCreateEx(0,0,riid,ppobj,pOuter);
645 FIXME("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj);
646 return E_NOINTERFACE;
649 static HRESULT WINAPI DICF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
650 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
651 FIXME("(%p)->(%d),stub!\n",This,dolock);
652 return S_OK;
655 static const IClassFactoryVtbl DICF_Vtbl = {
656 DICF_QueryInterface,
657 DICF_AddRef,
658 DICF_Release,
659 DICF_CreateInstance,
660 DICF_LockServer
662 static IClassFactoryImpl DINPUT_CF = {&DICF_Vtbl, 1 };
664 /***********************************************************************
665 * DllCanUnloadNow (DINPUT.@)
667 HRESULT WINAPI DllCanUnloadNow(void)
669 FIXME("(void): stub\n");
671 return S_FALSE;
674 /***********************************************************************
675 * DllGetClassObject (DINPUT.@)
677 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
679 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
680 if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
681 *ppv = (LPVOID)&DINPUT_CF;
682 IClassFactory_AddRef((IClassFactory*)*ppv);
683 return S_OK;
686 FIXME("(%s,%s,%p): no interface found.\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
687 return CLASS_E_CLASSNOTAVAILABLE;