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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * - Tomb Raider 2 Demo:
24 * Playable using keyboard only.
25 * - WingCommander Prophecy Demo:
26 * Doesn't get Input Focus.
28 * - Fallout : works great in X and DGA mode
30 * FIXME: The keyboard handling needs to (and will) be merged into keyboard.c
31 * (The current implementation is currently only a proof of concept and
39 #include "wine/debug.h"
44 #include "dinput_private.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(dinput
);
48 static ICOM_VTABLE(IDirectInputA
) ddiavt
;
49 static ICOM_VTABLE(IDirectInput7A
) ddi7avt
;
51 /* This array will be filled a dinput.so loading */
52 #define MAX_WINE_DINPUT_DEVICES 4
53 static dinput_device
* dinput_devices
[MAX_WINE_DINPUT_DEVICES
];
54 static int nrof_dinput_devices
= 0;
56 BOOL WINAPI
Init( HINSTANCE inst
, DWORD reason
, LPVOID reserv
)
60 case DLL_PROCESS_ATTACH
:
61 keyboard_hook
= SetWindowsHookExW( WH_KEYBOARD_LL
, KeyboardCallback
, 0, 0 );
63 case DLL_PROCESS_DETACH
:
64 UnhookWindowsHookEx(keyboard_hook
);
71 /* register a direct draw driver. We better not use malloc for we are in
72 * the ELF startup initialisation at this point.
74 void dinput_register_device(dinput_device
*device
) {
77 /* insert according to priority */
78 for (i
=0;i
<nrof_dinput_devices
;i
++) {
79 if (dinput_devices
[i
]->pref
<= device
->pref
) {
80 memcpy(dinput_devices
+i
+1,dinput_devices
+i
,sizeof(dinput_devices
[0])*(nrof_dinput_devices
-i
));
81 dinput_devices
[i
] = device
;
85 if (i
==nrof_dinput_devices
) /* not found, or too low priority */
86 dinput_devices
[nrof_dinput_devices
] = device
;
88 nrof_dinput_devices
++;
90 /* increase MAX_DDRAW_DRIVERS if the line below triggers */
91 assert(nrof_dinput_devices
<= MAX_WINE_DINPUT_DEVICES
);
94 /******************************************************************************
95 * DirectInputCreateEx (DINPUT.@)
97 HRESULT WINAPI
DirectInputCreateEx(
98 HINSTANCE hinst
, DWORD dwVersion
, REFIID riid
, LPVOID
*ppDI
,
101 IDirectInputAImpl
* This
;
103 TRACE("(0x%08lx,%04lx,%s,%p,%p)\n",
104 (DWORD
)hinst
,dwVersion
,debugstr_guid(riid
),ppDI
,punkOuter
106 if (IsEqualGUID(&IID_IDirectInputA
,riid
)) {
107 This
= (IDirectInputAImpl
*)HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputAImpl
));
109 ICOM_VTBL(This
) = &ddiavt
;
115 if (IsEqualGUID(&IID_IDirectInput7A
,riid
)) {
116 This
= (IDirectInputAImpl
*)HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputAImpl
));
118 ICOM_VTBL(This
) = (ICOM_VTABLE(IDirectInputA
) *) &ddi7avt
;
124 return DIERR_OLDDIRECTINPUTVERSION
;
127 /******************************************************************************
128 * DirectInputCreateA (DINPUT.@)
130 HRESULT WINAPI
DirectInputCreateA(HINSTANCE hinst
, DWORD dwVersion
, LPDIRECTINPUTA
*ppDI
, LPUNKNOWN punkOuter
)
132 IDirectInputAImpl
* This
;
133 TRACE("(0x%08lx,%04lx,%p,%p)\n",
134 (DWORD
)hinst
,dwVersion
,ppDI
,punkOuter
136 This
= (IDirectInputAImpl
*)HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputAImpl
));
138 ICOM_VTBL(This
) = &ddiavt
;
139 *ppDI
=(IDirectInputA
*)This
;
142 /******************************************************************************
143 * IDirectInputA_EnumDevices
145 static HRESULT WINAPI
IDirectInputAImpl_EnumDevices(
146 LPDIRECTINPUT7A iface
, DWORD dwDevType
, LPDIENUMDEVICESCALLBACKA lpCallback
,
147 LPVOID pvRef
, DWORD dwFlags
150 ICOM_THIS(IDirectInputAImpl
,iface
);
151 DIDEVICEINSTANCEA devInstance
;
154 TRACE("(this=%p,0x%04lx,%p,%p,%04lx)\n", This
, dwDevType
, lpCallback
, pvRef
, dwFlags
);
156 for (i
= 0; i
< nrof_dinput_devices
; i
++) {
157 if (dinput_devices
[i
]->enum_device(dwDevType
, dwFlags
, &devInstance
)) {
158 if (lpCallback(&devInstance
,pvRef
) == DIENUM_STOP
)
166 static ULONG WINAPI
IDirectInputAImpl_AddRef(LPDIRECTINPUT7A iface
)
168 ICOM_THIS(IDirectInputAImpl
,iface
);
169 return ++(This
->ref
);
172 static ULONG WINAPI
IDirectInputAImpl_Release(LPDIRECTINPUT7A iface
)
174 ICOM_THIS(IDirectInputAImpl
,iface
);
175 if (!(--This
->ref
)) {
176 HeapFree(GetProcessHeap(),0,This
);
182 static HRESULT WINAPI
IDirectInputAImpl_CreateDevice(
183 LPDIRECTINPUT7A iface
,REFGUID rguid
,LPDIRECTINPUTDEVICEA
* pdev
,
186 ICOM_THIS(IDirectInputAImpl
,iface
);
187 HRESULT ret_value
= DIERR_DEVICENOTREG
;
190 TRACE("(this=%p,%s,%p,%p)\n",This
,debugstr_guid(rguid
),pdev
,punk
);
192 /* Loop on all the devices to see if anyone matches the given GUID */
193 for (i
= 0; i
< nrof_dinput_devices
; i
++) {
195 if ((ret
= dinput_devices
[i
]->create_device(This
, rguid
, NULL
, pdev
)) == DI_OK
)
198 if (ret
== DIERR_NOINTERFACE
)
199 ret_value
= DIERR_NOINTERFACE
;
205 static HRESULT WINAPI
IDirectInputAImpl_QueryInterface(
206 LPDIRECTINPUT7A iface
,REFIID riid
,LPVOID
*ppobj
208 ICOM_THIS(IDirectInputAImpl
,iface
);
210 TRACE("(this=%p,%s,%p)\n",This
,debugstr_guid(riid
),ppobj
);
211 if (IsEqualGUID(&IID_IUnknown
,riid
)) {
212 IDirectInputA_AddRef(iface
);
216 if (IsEqualGUID(&IID_IDirectInputA
,riid
)) {
217 IDirectInputA_AddRef(iface
);
221 TRACE("Unsupported interface !\n");
225 static HRESULT WINAPI
IDirectInputAImpl_Initialize(
226 LPDIRECTINPUT7A iface
,HINSTANCE hinst
,DWORD x
228 return DIERR_ALREADYINITIALIZED
;
231 static HRESULT WINAPI
IDirectInputAImpl_GetDeviceStatus(LPDIRECTINPUT7A iface
,
233 ICOM_THIS(IDirectInputAImpl
,iface
);
235 FIXME("(%p)->(%s): stub\n",This
,debugstr_guid(rguid
));
240 static HRESULT WINAPI
IDirectInputAImpl_RunControlPanel(LPDIRECTINPUT7A iface
,
243 ICOM_THIS(IDirectInputAImpl
,iface
);
244 FIXME("(%p)->(%08lx,%08lx): stub\n",This
, (DWORD
) hwndOwner
, dwFlags
);
249 static HRESULT WINAPI
IDirectInput2AImpl_FindDevice(LPDIRECTINPUT2A iface
, REFGUID rguid
,
250 LPCSTR pszName
, LPGUID pguidInstance
) {
251 ICOM_THIS(IDirectInputAImpl
,iface
);
252 FIXME("(%p)->(%s, %s, %p): stub\n", This
, debugstr_guid(rguid
), pszName
, pguidInstance
);
257 static HRESULT WINAPI
IDirectInput7AImpl_CreateDeviceEx(LPDIRECTINPUT7A iface
, REFGUID rguid
,
258 REFIID riid
, LPVOID
* pvOut
, LPUNKNOWN lpUnknownOuter
)
260 ICOM_THIS(IDirectInputAImpl
,iface
);
261 HRESULT ret_value
= DIERR_DEVICENOTREG
;
264 TRACE("(%p)->(%s, %s, %p, %p)\n", This
, debugstr_guid(rguid
), debugstr_guid(riid
), pvOut
, lpUnknownOuter
);
266 /* Loop on all the devices to see if anyone matches the given GUID */
267 for (i
= 0; i
< nrof_dinput_devices
; i
++) {
269 if ((ret
= dinput_devices
[i
]->create_device(This
, rguid
, riid
, (LPDIRECTINPUTDEVICEA
*) pvOut
)) == DI_OK
)
272 if (ret
== DIERR_NOINTERFACE
)
273 ret_value
= DIERR_NOINTERFACE
;
279 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
280 # define XCAST(fun) (typeof(ddiavt.fun))
282 # define XCAST(fun) (void*)
285 static ICOM_VTABLE(IDirectInputA
) ddiavt
=
287 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
288 XCAST(QueryInterface
)IDirectInputAImpl_QueryInterface
,
289 XCAST(AddRef
)IDirectInputAImpl_AddRef
,
290 XCAST(Release
)IDirectInputAImpl_Release
,
291 XCAST(CreateDevice
)IDirectInputAImpl_CreateDevice
,
292 XCAST(EnumDevices
)IDirectInputAImpl_EnumDevices
,
293 XCAST(GetDeviceStatus
)IDirectInputAImpl_GetDeviceStatus
,
294 XCAST(RunControlPanel
)IDirectInputAImpl_RunControlPanel
,
295 XCAST(Initialize
)IDirectInputAImpl_Initialize
299 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
300 # define XCAST(fun) (typeof(ddi7avt.fun))
302 # define XCAST(fun) (void*)
305 static ICOM_VTABLE(IDirectInput7A
) ddi7avt
= {
306 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
307 XCAST(QueryInterface
)IDirectInputAImpl_QueryInterface
,
308 XCAST(AddRef
)IDirectInputAImpl_AddRef
,
309 XCAST(Release
)IDirectInputAImpl_Release
,
310 XCAST(CreateDevice
)IDirectInputAImpl_CreateDevice
,
311 XCAST(EnumDevices
)IDirectInputAImpl_EnumDevices
,
312 XCAST(GetDeviceStatus
)IDirectInputAImpl_GetDeviceStatus
,
313 XCAST(RunControlPanel
)IDirectInputAImpl_RunControlPanel
,
314 XCAST(Initialize
)IDirectInputAImpl_Initialize
,
315 XCAST(FindDevice
)IDirectInput2AImpl_FindDevice
,
316 IDirectInput7AImpl_CreateDeviceEx
320 /***********************************************************************
321 * DllCanUnloadNow (DINPUT.@)
323 HRESULT WINAPI
DINPUT_DllCanUnloadNow(void)
325 FIXME("(void): stub\n");
330 /***********************************************************************
331 * DllGetClassObject (DINPUT.@)
333 HRESULT WINAPI
DINPUT_DllGetClassObject(REFCLSID rclsid
, REFIID riid
,
336 FIXME("(%p, %p, %p): stub\n", debugstr_guid(rclsid
),
337 debugstr_guid(riid
), ppv
);
339 return CLASS_E_CLASSNOTAVAILABLE
;
342 /***********************************************************************
343 * DllRegisterServer (DINPUT.@)
345 HRESULT WINAPI
DINPUT_DllRegisterServer(void)
347 FIXME("(void): stub\n");
352 /***********************************************************************
353 * DllUnregisterServer (DINPUT.@)
355 HRESULT WINAPI
DINPUT_DllUnregisterServer(void)
357 FIXME("(void): stub\n");