Handle CBR_BLOCK in EXECUTE and ADVISE DDE transactions.
[wine/hacks.git] / dlls / dinput / dinput_main.c
blob4b2df7f2ece1c6717e283873e80fa09388cc69a2
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 /* This array will be filled a dinput.so loading */
55 #define MAX_WINE_DINPUT_DEVICES 4
56 static dinput_device * dinput_devices[MAX_WINE_DINPUT_DEVICES];
57 static int nrof_dinput_devices = 0;
59 HINSTANCE DINPUT_instance = NULL;
61 BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserv)
63 switch(reason)
65 case DLL_PROCESS_ATTACH:
66 DisableThreadLibraryCalls(inst);
67 DINPUT_instance = inst;
68 break;
69 case DLL_PROCESS_DETACH:
70 break;
72 return TRUE;
76 /* register a direct draw driver. We better not use malloc for we are in
77 * the ELF startup initialisation at this point.
79 void dinput_register_device(dinput_device *device) {
80 int i;
82 /* insert according to priority */
83 for (i=0;i<nrof_dinput_devices;i++) {
84 if (dinput_devices[i]->pref <= device->pref) {
85 memcpy(dinput_devices+i+1,dinput_devices+i,sizeof(dinput_devices[0])*(nrof_dinput_devices-i));
86 dinput_devices[i] = device;
87 break;
90 if (i==nrof_dinput_devices) /* not found, or too low priority */
91 dinput_devices[nrof_dinput_devices] = device;
93 nrof_dinput_devices++;
95 /* increase MAX_DDRAW_DRIVERS if the line below triggers */
96 assert(nrof_dinput_devices <= MAX_WINE_DINPUT_DEVICES);
99 /******************************************************************************
100 * DirectInputCreateEx (DINPUT.@)
102 HRESULT WINAPI DirectInputCreateEx(
103 HINSTANCE hinst, DWORD dwVersion, REFIID riid, LPVOID *ppDI,
104 LPUNKNOWN punkOuter)
106 IDirectInputImpl* This;
108 TRACE("(0x%08lx,%04lx,%s,%p,%p)\n", (DWORD)hinst,dwVersion,debugstr_guid(riid),ppDI,punkOuter);
110 if (IsEqualGUID(&IID_IDirectInputA,riid) ||
111 IsEqualGUID(&IID_IDirectInput2A,riid) ||
112 IsEqualGUID(&IID_IDirectInput7A,riid)) {
113 This = (IDirectInputImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputImpl));
114 This->lpVtbl = &ddi7avt;
115 This->ref = 1;
116 This->version = 1;
117 *ppDI = This;
119 return DI_OK;
122 if (IsEqualGUID(&IID_IDirectInputW,riid) ||
123 IsEqualGUID(&IID_IDirectInput2W,riid) ||
124 IsEqualGUID(&IID_IDirectInput7W,riid)) {
125 This = (IDirectInputImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputImpl));
126 This->lpVtbl = &ddi7wvt;
127 This->ref = 1;
128 This->version = 1;
129 *ppDI = This;
131 return DI_OK;
134 if (IsEqualGUID(&IID_IDirectInput8A,riid)) {
135 This = (IDirectInputImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputImpl));
136 This->lpVtbl = &ddi8avt;
137 This->ref = 1;
138 This->version = 8;
139 *ppDI = This;
141 return DI_OK;
144 if (IsEqualGUID(&IID_IDirectInput8W,riid)) {
145 This = (IDirectInputImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputImpl));
146 This->lpVtbl = &ddi8wvt;
147 This->ref = 1;
148 This->version = 8;
149 *ppDI = This;
151 return DI_OK;
154 return DIERR_OLDDIRECTINPUTVERSION;
157 /******************************************************************************
158 * DirectInputCreateA (DINPUT.@)
160 HRESULT WINAPI DirectInputCreateA(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUTA *ppDI, LPUNKNOWN punkOuter)
162 IDirectInputImpl* This;
163 TRACE("(0x%08lx,%04lx,%p,%p)\n", (DWORD)hinst,dwVersion,ppDI,punkOuter);
164 This = (IDirectInputImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputImpl));
165 This->lpVtbl = &ddi7avt;
166 This->ref = 1;
167 if (dwVersion >= 0x0800) {
168 This->version = 8;
169 } else {
170 /* We do not differientiate between version 1, 2 and 7 */
171 This->version = 1;
173 *ppDI = (IDirectInputA*)This;
174 return 0;
178 /******************************************************************************
179 * DirectInputCreateW (DINPUT.@)
181 HRESULT WINAPI DirectInputCreateW(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUTW *ppDI, LPUNKNOWN punkOuter)
183 IDirectInputImpl* This;
184 TRACE("(0x%08lx,%04lx,%p,%p)\n", (DWORD)hinst,dwVersion,ppDI,punkOuter);
185 This = (IDirectInputImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputImpl));
186 This->lpVtbl = &ddi7wvt;
187 This->ref = 1;
188 if (dwVersion >= 0x0800) {
189 This->version = 8;
190 } else {
191 /* We do not differientiate between version 1, 2 and 7 */
192 This->version = 1;
194 *ppDI = (IDirectInputW*)This;
195 return 0;
198 static const char *_dump_DIDEVTYPE_value(DWORD dwDevType) {
199 switch (dwDevType) {
200 case 0: return "All devices";
201 case DIDEVTYPE_MOUSE: return "DIDEVTYPE_MOUSE";
202 case DIDEVTYPE_KEYBOARD: return "DIDEVTYPE_KEYBOARD";
203 case DIDEVTYPE_JOYSTICK: return "DIDEVTYPE_JOYSTICK";
204 case DIDEVTYPE_DEVICE: return "DIDEVTYPE_DEVICE";
205 default: return "Unkown";
209 static void _dump_EnumDevices_dwFlags(DWORD dwFlags) {
210 if (TRACE_ON(dinput)) {
211 unsigned int i;
212 static const struct {
213 DWORD mask;
214 const char *name;
215 } flags[] = {
216 #define FE(x) { x, #x}
217 FE(DIEDFL_ALLDEVICES),
218 FE(DIEDFL_ATTACHEDONLY),
219 FE(DIEDFL_FORCEFEEDBACK),
220 FE(DIEDFL_INCLUDEALIASES),
221 FE(DIEDFL_INCLUDEPHANTOMS)
222 #undef FE
224 if (dwFlags == 0) {
225 DPRINTF("DIEDFL_ALLDEVICES");
226 return;
228 for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++)
229 if (flags[i].mask & dwFlags)
230 DPRINTF("%s ",flags[i].name);
234 /******************************************************************************
235 * IDirectInputA_EnumDevices
237 static HRESULT WINAPI IDirectInputAImpl_EnumDevices(
238 LPDIRECTINPUT7A iface, DWORD dwDevType, LPDIENUMDEVICESCALLBACKA lpCallback,
239 LPVOID pvRef, DWORD dwFlags)
241 IDirectInputImpl *This = (IDirectInputImpl *)iface;
242 DIDEVICEINSTANCEA devInstance;
243 int i, j, r;
245 TRACE("(this=%p,0x%04lx '%s',%p,%p,%04lx)\n",
246 This, dwDevType, _dump_DIDEVTYPE_value(dwDevType),
247 lpCallback, pvRef, dwFlags);
248 TRACE(" flags: "); _dump_EnumDevices_dwFlags(dwFlags); TRACE("\n");
250 for (i = 0; i < nrof_dinput_devices; i++) {
251 for (j = 0, r = -1; r != 0; j++) {
252 devInstance.dwSize = sizeof(devInstance);
253 TRACE(" - checking device %d ('%s')\n", i, dinput_devices[i]->name);
254 if ((r = dinput_devices[i]->enum_deviceA(dwDevType, dwFlags, &devInstance, This->version, j))) {
255 if (lpCallback(&devInstance,pvRef) == DIENUM_STOP)
256 return 0;
261 return 0;
263 /******************************************************************************
264 * IDirectInputW_EnumDevices
266 static HRESULT WINAPI IDirectInputWImpl_EnumDevices(
267 LPDIRECTINPUT7W iface, DWORD dwDevType, LPDIENUMDEVICESCALLBACKW lpCallback,
268 LPVOID pvRef, DWORD dwFlags)
270 IDirectInputImpl *This = (IDirectInputImpl *)iface;
271 DIDEVICEINSTANCEW devInstance;
272 int i, j, r;
274 TRACE("(this=%p,0x%04lx '%s',%p,%p,%04lx)\n",
275 This, dwDevType, _dump_DIDEVTYPE_value(dwDevType),
276 lpCallback, pvRef, dwFlags);
277 TRACE(" flags: "); _dump_EnumDevices_dwFlags(dwFlags); TRACE("\n");
279 for (i = 0; i < nrof_dinput_devices; i++) {
280 for (j = 0, r = -1; r != 0; j++) {
281 devInstance.dwSize = sizeof(devInstance);
282 TRACE(" - checking device %d ('%s')\n", i, dinput_devices[i]->name);
283 if ((r = dinput_devices[i]->enum_deviceW(dwDevType, dwFlags, &devInstance, This->version, j))) {
284 if (lpCallback(&devInstance,pvRef) == DIENUM_STOP)
285 return 0;
290 return 0;
293 static ULONG WINAPI IDirectInputAImpl_AddRef(LPDIRECTINPUT7A iface)
295 IDirectInputImpl *This = (IDirectInputImpl *)iface;
296 return InterlockedIncrement((&This->ref));
299 static ULONG WINAPI IDirectInputAImpl_Release(LPDIRECTINPUT7A iface)
301 IDirectInputImpl *This = (IDirectInputImpl *)iface;
302 ULONG ref;
303 ref = InterlockedDecrement(&(This->ref));
304 if (ref == 0)
305 HeapFree(GetProcessHeap(),0,This);
306 return ref;
309 static HRESULT WINAPI IDirectInputAImpl_QueryInterface(LPDIRECTINPUT7A iface, REFIID riid, LPVOID *ppobj) {
310 IDirectInputImpl *This = (IDirectInputImpl *)iface;
312 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
313 if (IsEqualGUID(&IID_IUnknown,riid) ||
314 IsEqualGUID(&IID_IDirectInputA,riid) ||
315 IsEqualGUID(&IID_IDirectInput2A,riid) ||
316 IsEqualGUID(&IID_IDirectInput7A,riid)) {
317 IDirectInputAImpl_AddRef(iface);
318 *ppobj = This;
319 return 0;
321 TRACE("Unsupported interface !\n");
322 return E_FAIL;
325 static HRESULT WINAPI IDirectInputWImpl_QueryInterface(LPDIRECTINPUT7W iface, REFIID riid, LPVOID *ppobj) {
326 IDirectInputImpl *This = (IDirectInputImpl *)iface;
328 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
329 if (IsEqualGUID(&IID_IUnknown,riid) ||
330 IsEqualGUID(&IID_IDirectInputW,riid) ||
331 IsEqualGUID(&IID_IDirectInput2W,riid) ||
332 IsEqualGUID(&IID_IDirectInput7W,riid)) {
333 IDirectInputAImpl_AddRef((LPDIRECTINPUT7A) iface);
334 *ppobj = This;
335 return 0;
337 TRACE("Unsupported interface !\n");
338 return E_FAIL;
341 static HRESULT WINAPI IDirectInputAImpl_CreateDevice(
342 LPDIRECTINPUT7A iface,REFGUID rguid,LPDIRECTINPUTDEVICEA* pdev,
343 LPUNKNOWN punk
345 IDirectInputImpl *This = (IDirectInputImpl *)iface;
346 HRESULT ret_value = DIERR_DEVICENOTREG;
347 int i;
349 TRACE("(this=%p,%s,%p,%p)\n",This,debugstr_guid(rguid),pdev,punk);
351 /* Loop on all the devices to see if anyone matches the given GUID */
352 for (i = 0; i < nrof_dinput_devices; i++) {
353 HRESULT ret;
354 if ((ret = dinput_devices[i]->create_deviceA(This, rguid, NULL, pdev)) == DI_OK)
355 return DI_OK;
357 if (ret == DIERR_NOINTERFACE)
358 ret_value = DIERR_NOINTERFACE;
361 return ret_value;
364 static HRESULT WINAPI IDirectInputWImpl_CreateDevice(LPDIRECTINPUT7A iface,
365 REFGUID rguid, LPDIRECTINPUTDEVICEW* pdev, LPUNKNOWN punk) {
366 IDirectInputImpl *This = (IDirectInputImpl *)iface;
367 HRESULT ret_value = DIERR_DEVICENOTREG;
368 int i;
370 TRACE("(this=%p,%s,%p,%p)\n",This,debugstr_guid(rguid),pdev,punk);
372 /* Loop on all the devices to see if anyone matches the given GUID */
373 for (i = 0; i < nrof_dinput_devices; i++) {
374 HRESULT ret;
375 if ((ret = dinput_devices[i]->create_deviceW(This, rguid, NULL, pdev)) == DI_OK)
376 return DI_OK;
378 if (ret == DIERR_NOINTERFACE)
379 ret_value = DIERR_NOINTERFACE;
382 return ret_value;
385 static HRESULT WINAPI IDirectInputAImpl_Initialize(LPDIRECTINPUT7A iface, HINSTANCE hinst, DWORD x) {
386 return DIERR_ALREADYINITIALIZED;
389 static HRESULT WINAPI IDirectInputAImpl_GetDeviceStatus(LPDIRECTINPUT7A iface,
390 REFGUID rguid) {
391 IDirectInputImpl *This = (IDirectInputImpl *)iface;
393 FIXME("(%p)->(%s): stub\n",This,debugstr_guid(rguid));
395 return DI_OK;
398 static HRESULT WINAPI IDirectInputAImpl_RunControlPanel(LPDIRECTINPUT7A iface,
399 HWND hwndOwner,
400 DWORD dwFlags) {
401 IDirectInputImpl *This = (IDirectInputImpl *)iface;
402 FIXME("(%p)->(%08lx,%08lx): stub\n",This, (DWORD) hwndOwner, dwFlags);
404 return DI_OK;
407 static HRESULT WINAPI IDirectInput2AImpl_FindDevice(LPDIRECTINPUT7A iface, REFGUID rguid,
408 LPCSTR pszName, LPGUID pguidInstance) {
409 IDirectInputImpl *This = (IDirectInputImpl *)iface;
410 FIXME("(%p)->(%s, %s, %p): stub\n", This, debugstr_guid(rguid), pszName, pguidInstance);
412 return DI_OK;
415 static HRESULT WINAPI IDirectInput2WImpl_FindDevice(LPDIRECTINPUT7W iface, REFGUID rguid,
416 LPCWSTR pszName, LPGUID pguidInstance) {
417 IDirectInputImpl *This = (IDirectInputImpl *)iface;
418 FIXME("(%p)->(%s, %s, %p): stub\n", This, debugstr_guid(rguid), debugstr_w(pszName), pguidInstance);
420 return DI_OK;
423 static HRESULT WINAPI IDirectInput7AImpl_CreateDeviceEx(LPDIRECTINPUT7A iface, REFGUID rguid,
424 REFIID riid, LPVOID* pvOut, LPUNKNOWN lpUnknownOuter)
426 IDirectInputImpl *This = (IDirectInputImpl *)iface;
427 HRESULT ret_value = DIERR_DEVICENOTREG;
428 int i;
430 TRACE("(%p)->(%s, %s, %p, %p)\n", This, debugstr_guid(rguid), debugstr_guid(riid), pvOut, lpUnknownOuter);
432 /* Loop on all the devices to see if anyone matches the given GUID */
433 for (i = 0; i < nrof_dinput_devices; i++) {
434 HRESULT ret;
435 if ((ret = dinput_devices[i]->create_deviceA(This, rguid, riid, (LPDIRECTINPUTDEVICEA*) pvOut)) == DI_OK)
436 return DI_OK;
438 if (ret == DIERR_NOINTERFACE)
439 ret_value = DIERR_NOINTERFACE;
442 return ret_value;
445 static HRESULT WINAPI IDirectInput7WImpl_CreateDeviceEx(LPDIRECTINPUT7W iface, REFGUID rguid,
446 REFIID riid, LPVOID* pvOut, LPUNKNOWN lpUnknownOuter)
448 IDirectInputImpl *This = (IDirectInputImpl *)iface;
449 HRESULT ret_value = DIERR_DEVICENOTREG;
450 int i;
452 TRACE("(%p)->(%s, %s, %p, %p)\n", This, debugstr_guid(rguid), debugstr_guid(riid), pvOut, lpUnknownOuter);
454 /* Loop on all the devices to see if anyone matches the given GUID */
455 for (i = 0; i < nrof_dinput_devices; i++) {
456 HRESULT ret;
457 if ((ret = dinput_devices[i]->create_deviceW(This, rguid, riid, (LPDIRECTINPUTDEVICEW*) pvOut)) == DI_OK)
458 return DI_OK;
460 if (ret == DIERR_NOINTERFACE)
461 ret_value = DIERR_NOINTERFACE;
464 return ret_value;
467 static HRESULT WINAPI IDirectInput8AImpl_QueryInterface(LPDIRECTINPUT8A iface, REFIID riid, LPVOID *ppobj) {
468 IDirectInputImpl *This = (IDirectInputImpl *)iface;
470 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
471 if (IsEqualGUID(&IID_IUnknown,riid) ||
472 IsEqualGUID(&IID_IDirectInput8A,riid)) {
473 IDirectInputAImpl_AddRef((LPDIRECTINPUT7A) iface);
474 *ppobj = This;
475 return 0;
477 TRACE("Unsupported interface !\n");
478 return E_NOINTERFACE;
481 static HRESULT WINAPI IDirectInput8WImpl_QueryInterface(LPDIRECTINPUT8W iface, REFIID riid, LPVOID *ppobj) {
482 IDirectInputImpl *This = (IDirectInputImpl *)iface;
484 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
485 if (IsEqualGUID(&IID_IUnknown,riid) ||
486 IsEqualGUID(&IID_IDirectInput8W,riid)) {
487 IDirectInputAImpl_AddRef((LPDIRECTINPUT7A) iface);
488 *ppobj = This;
489 return 0;
491 TRACE("Unsupported interface !\n");
492 return E_NOINTERFACE;
495 static HRESULT WINAPI IDirectInput8AImpl_EnumDevicesBySemantics(
496 LPDIRECTINPUT8A iface, LPCSTR ptszUserName, LPDIACTIONFORMATA lpdiActionFormat,
497 LPDIENUMDEVICESBYSEMANTICSCBA lpCallback,
498 LPVOID pvRef, DWORD dwFlags
501 IDirectInputImpl *This = (IDirectInputImpl *)iface;
503 FIXME("(this=%p,%s,%p,%p,%p,%04lx): stub\n", This, ptszUserName, lpdiActionFormat,
504 lpCallback, pvRef, dwFlags);
505 return 0;
508 static HRESULT WINAPI IDirectInput8WImpl_EnumDevicesBySemantics(
509 LPDIRECTINPUT8W iface, LPCWSTR ptszUserName, LPDIACTIONFORMATW lpdiActionFormat,
510 LPDIENUMDEVICESBYSEMANTICSCBW lpCallback,
511 LPVOID pvRef, DWORD dwFlags
514 IDirectInputImpl *This = (IDirectInputImpl *)iface;
516 FIXME("(this=%p,%s,%p,%p,%p,%04lx): stub\n", This, debugstr_w(ptszUserName), lpdiActionFormat,
517 lpCallback, pvRef, dwFlags);
518 return 0;
521 static HRESULT WINAPI IDirectInput8AImpl_ConfigureDevices(
522 LPDIRECTINPUT8A iface, LPDICONFIGUREDEVICESCALLBACK lpdiCallback,
523 LPDICONFIGUREDEVICESPARAMSA lpdiCDParams, DWORD dwFlags, LPVOID pvRefData
526 IDirectInputImpl *This = (IDirectInputImpl *)iface;
528 FIXME("(this=%p,%p,%p,%04lx,%p): stub\n", This, lpdiCallback, lpdiCDParams,
529 dwFlags, pvRefData);
530 return 0;
533 static HRESULT WINAPI IDirectInput8WImpl_ConfigureDevices(
534 LPDIRECTINPUT8W iface, LPDICONFIGUREDEVICESCALLBACK lpdiCallback,
535 LPDICONFIGUREDEVICESPARAMSW lpdiCDParams, DWORD dwFlags, LPVOID pvRefData
538 IDirectInputImpl *This = (IDirectInputImpl *)iface;
540 FIXME("(this=%p,%p,%p,%04lx,%p): stub\n", This, lpdiCallback, lpdiCDParams,
541 dwFlags, pvRefData);
542 return 0;
545 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
546 # define XCAST(fun) (typeof(ddi7avt.fun))
547 #else
548 # define XCAST(fun) (void*)
549 #endif
551 static IDirectInput7AVtbl ddi7avt = {
552 XCAST(QueryInterface)IDirectInputAImpl_QueryInterface,
553 XCAST(AddRef)IDirectInputAImpl_AddRef,
554 XCAST(Release)IDirectInputAImpl_Release,
555 XCAST(CreateDevice)IDirectInputAImpl_CreateDevice,
556 XCAST(EnumDevices)IDirectInputAImpl_EnumDevices,
557 XCAST(GetDeviceStatus)IDirectInputAImpl_GetDeviceStatus,
558 XCAST(RunControlPanel)IDirectInputAImpl_RunControlPanel,
559 XCAST(Initialize)IDirectInputAImpl_Initialize,
560 XCAST(FindDevice)IDirectInput2AImpl_FindDevice,
561 XCAST(CreateDeviceEx)IDirectInput7AImpl_CreateDeviceEx
564 #undef XCAST
565 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
566 # define XCAST(fun) (typeof(ddi7wvt.fun))
567 #else
568 # define XCAST(fun) (void*)
569 #endif
571 static IDirectInput7WVtbl ddi7wvt = {
572 XCAST(QueryInterface)IDirectInputWImpl_QueryInterface,
573 XCAST(AddRef)IDirectInputAImpl_AddRef,
574 XCAST(Release)IDirectInputAImpl_Release,
575 XCAST(CreateDevice)IDirectInputWImpl_CreateDevice,
576 XCAST(EnumDevices)IDirectInputWImpl_EnumDevices,
577 XCAST(GetDeviceStatus)IDirectInputAImpl_GetDeviceStatus,
578 XCAST(RunControlPanel)IDirectInputAImpl_RunControlPanel,
579 XCAST(Initialize)IDirectInputAImpl_Initialize,
580 XCAST(FindDevice)IDirectInput2WImpl_FindDevice,
581 XCAST(CreateDeviceEx)IDirectInput7WImpl_CreateDeviceEx
583 #undef XCAST
585 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
586 # define XCAST(fun) (typeof(ddi8avt.fun))
587 #else
588 # define XCAST(fun) (void*)
589 #endif
591 static IDirectInput8AVtbl ddi8avt = {
592 XCAST(QueryInterface)IDirectInput8AImpl_QueryInterface,
593 XCAST(AddRef)IDirectInputAImpl_AddRef,
594 XCAST(Release)IDirectInputAImpl_Release,
595 XCAST(CreateDevice)IDirectInputAImpl_CreateDevice,
596 XCAST(EnumDevices)IDirectInputAImpl_EnumDevices,
597 XCAST(GetDeviceStatus)IDirectInputAImpl_GetDeviceStatus,
598 XCAST(RunControlPanel)IDirectInputAImpl_RunControlPanel,
599 XCAST(Initialize)IDirectInputAImpl_Initialize,
600 XCAST(FindDevice)IDirectInput2AImpl_FindDevice,
601 XCAST(EnumDevicesBySemantics)IDirectInput8AImpl_EnumDevicesBySemantics,
602 XCAST(ConfigureDevices)IDirectInput8AImpl_ConfigureDevices
604 #undef XCAST
606 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
607 # define XCAST(fun) (typeof(ddi8wvt.fun))
608 #else
609 # define XCAST(fun) (void*)
610 #endif
611 static IDirectInput8WVtbl ddi8wvt = {
612 XCAST(QueryInterface)IDirectInput8WImpl_QueryInterface,
613 XCAST(AddRef)IDirectInputAImpl_AddRef,
614 XCAST(Release)IDirectInputAImpl_Release,
615 XCAST(CreateDevice)IDirectInputWImpl_CreateDevice,
616 XCAST(EnumDevices)IDirectInputWImpl_EnumDevices,
617 XCAST(GetDeviceStatus)IDirectInputAImpl_GetDeviceStatus,
618 XCAST(RunControlPanel)IDirectInputAImpl_RunControlPanel,
619 XCAST(Initialize)IDirectInputAImpl_Initialize,
620 XCAST(FindDevice)IDirectInput2WImpl_FindDevice,
621 XCAST(EnumDevicesBySemantics)IDirectInput8WImpl_EnumDevicesBySemantics,
622 XCAST(ConfigureDevices)IDirectInput8WImpl_ConfigureDevices
624 #undef XCAST
626 /*******************************************************************************
627 * DirectInput ClassFactory
629 typedef struct
631 /* IUnknown fields */
632 IClassFactoryVtbl *lpVtbl;
633 DWORD ref;
634 } IClassFactoryImpl;
636 static HRESULT WINAPI DICF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
637 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
639 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
640 return E_NOINTERFACE;
643 static ULONG WINAPI DICF_AddRef(LPCLASSFACTORY iface) {
644 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
645 return InterlockedIncrement(&(This->ref));
648 static ULONG WINAPI DICF_Release(LPCLASSFACTORY iface) {
649 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
650 /* static class, won't be freed */
651 return InterlockedDecrement(&(This->ref));
654 static HRESULT WINAPI DICF_CreateInstance(
655 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
657 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
659 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
660 if ( IsEqualGUID( &IID_IDirectInputA, riid ) ||
661 IsEqualGUID( &IID_IDirectInputW, riid ) ||
662 IsEqualGUID( &IID_IDirectInput2A, riid ) ||
663 IsEqualGUID( &IID_IDirectInput2W, riid ) ||
664 IsEqualGUID( &IID_IDirectInput7A, riid ) ||
665 IsEqualGUID( &IID_IDirectInput7W, riid ) ||
666 IsEqualGUID( &IID_IDirectInput8A, riid ) ||
667 IsEqualGUID( &IID_IDirectInput8W, riid ) ) {
668 /* FIXME: reuse already created dinput if present? */
669 return DirectInputCreateEx(0,0,riid,ppobj,pOuter);
672 FIXME("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj);
673 return E_NOINTERFACE;
676 static HRESULT WINAPI DICF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
677 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
678 FIXME("(%p)->(%d),stub!\n",This,dolock);
679 return S_OK;
682 static IClassFactoryVtbl DICF_Vtbl = {
683 DICF_QueryInterface,
684 DICF_AddRef,
685 DICF_Release,
686 DICF_CreateInstance,
687 DICF_LockServer
689 static IClassFactoryImpl DINPUT_CF = {&DICF_Vtbl, 1 };
691 /***********************************************************************
692 * DllCanUnloadNow (DINPUT.@)
694 HRESULT WINAPI DINPUT_DllCanUnloadNow(void)
696 FIXME("(void): stub\n");
698 return S_FALSE;
701 /***********************************************************************
702 * DllGetClassObject (DINPUT.@)
704 HRESULT WINAPI DINPUT_DllGetClassObject(REFCLSID rclsid, REFIID riid,
705 LPVOID *ppv)
707 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
708 if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
709 *ppv = (LPVOID)&DINPUT_CF;
710 IClassFactory_AddRef((IClassFactory*)*ppv);
711 return S_OK;
714 FIXME("(%s,%s,%p): no interface found.\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
715 return CLASS_E_CLASSNOTAVAILABLE;