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"
43 #include "dinput_private.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(dinput
);
47 static ICOM_VTABLE(IDirectInputA
) ddiavt
;
48 static ICOM_VTABLE(IDirectInput7A
) ddi7avt
;
50 /* This array will be filled a dinput.so loading */
51 #define MAX_WINE_DINPUT_DEVICES 4
52 static dinput_device
* dinput_devices
[MAX_WINE_DINPUT_DEVICES
];
53 static int nrof_dinput_devices
= 0;
55 /* register a direct draw driver. We better not use malloc for we are in
56 * the ELF startup initialisation at this point.
58 void dinput_register_device(dinput_device
*device
) {
61 /* insert according to priority */
62 for (i
=0;i
<nrof_dinput_devices
;i
++) {
63 if (dinput_devices
[i
]->pref
<= device
->pref
) {
64 memcpy(dinput_devices
+i
+1,dinput_devices
+i
,sizeof(dinput_devices
[0])*(nrof_dinput_devices
-i
));
65 dinput_devices
[i
] = device
;
69 if (i
==nrof_dinput_devices
) /* not found, or too low priority */
70 dinput_devices
[nrof_dinput_devices
] = device
;
72 nrof_dinput_devices
++;
74 /* increase MAX_DDRAW_DRIVERS if the line below triggers */
75 assert(nrof_dinput_devices
<= MAX_WINE_DINPUT_DEVICES
);
78 /******************************************************************************
79 * DirectInputCreateEx (DINPUT.@)
81 HRESULT WINAPI
DirectInputCreateEx(
82 HINSTANCE hinst
, DWORD dwVersion
, REFIID riid
, LPVOID
*ppDI
,
85 IDirectInputAImpl
* This
;
87 TRACE("(0x%08lx,%04lx,%s,%p,%p)\n",
88 (DWORD
)hinst
,dwVersion
,debugstr_guid(riid
),ppDI
,punkOuter
90 if (IsEqualGUID(&IID_IDirectInputA
,riid
)) {
91 This
= (IDirectInputAImpl
*)HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputAImpl
));
93 ICOM_VTBL(This
) = &ddiavt
;
99 if (IsEqualGUID(&IID_IDirectInput7A
,riid
)) {
100 This
= (IDirectInputAImpl
*)HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputAImpl
));
102 ICOM_VTBL(This
) = (ICOM_VTABLE(IDirectInputA
) *) &ddi7avt
;
108 return DIERR_OLDDIRECTINPUTVERSION
;
111 /******************************************************************************
112 * DirectInputCreateA (DINPUT.@)
114 HRESULT WINAPI
DirectInputCreateA(HINSTANCE hinst
, DWORD dwVersion
, LPDIRECTINPUTA
*ppDI
, LPUNKNOWN punkOuter
)
116 IDirectInputAImpl
* This
;
117 TRACE("(0x%08lx,%04lx,%p,%p)\n",
118 (DWORD
)hinst
,dwVersion
,ppDI
,punkOuter
120 This
= (IDirectInputAImpl
*)HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputAImpl
));
122 ICOM_VTBL(This
) = &ddiavt
;
123 *ppDI
=(IDirectInputA
*)This
;
126 /******************************************************************************
127 * IDirectInputA_EnumDevices
129 static HRESULT WINAPI
IDirectInputAImpl_EnumDevices(
130 LPDIRECTINPUT7A iface
, DWORD dwDevType
, LPDIENUMDEVICESCALLBACKA lpCallback
,
131 LPVOID pvRef
, DWORD dwFlags
134 ICOM_THIS(IDirectInputAImpl
,iface
);
135 DIDEVICEINSTANCEA devInstance
;
138 TRACE("(this=%p,0x%04lx,%p,%p,%04lx)\n", This
, dwDevType
, lpCallback
, pvRef
, dwFlags
);
140 for (i
= 0; i
< nrof_dinput_devices
; i
++) {
141 if (dinput_devices
[i
]->enum_device(dwDevType
, dwFlags
, &devInstance
)) {
142 if (lpCallback(&devInstance
,pvRef
) == DIENUM_STOP
)
150 static ULONG WINAPI
IDirectInputAImpl_AddRef(LPDIRECTINPUT7A iface
)
152 ICOM_THIS(IDirectInputAImpl
,iface
);
153 return ++(This
->ref
);
156 static ULONG WINAPI
IDirectInputAImpl_Release(LPDIRECTINPUT7A iface
)
158 ICOM_THIS(IDirectInputAImpl
,iface
);
159 if (!(--This
->ref
)) {
160 HeapFree(GetProcessHeap(),0,This
);
166 static HRESULT WINAPI
IDirectInputAImpl_CreateDevice(
167 LPDIRECTINPUT7A iface
,REFGUID rguid
,LPDIRECTINPUTDEVICEA
* pdev
,
170 ICOM_THIS(IDirectInputAImpl
,iface
);
171 HRESULT ret_value
= DIERR_DEVICENOTREG
;
174 TRACE("(this=%p,%s,%p,%p)\n",This
,debugstr_guid(rguid
),pdev
,punk
);
176 /* Loop on all the devices to see if anyone matches the given GUID */
177 for (i
= 0; i
< nrof_dinput_devices
; i
++) {
179 if ((ret
= dinput_devices
[i
]->create_device(This
, rguid
, NULL
, pdev
)) == DI_OK
)
182 if (ret
== DIERR_NOINTERFACE
)
183 ret_value
= DIERR_NOINTERFACE
;
189 static HRESULT WINAPI
IDirectInputAImpl_QueryInterface(
190 LPDIRECTINPUT7A iface
,REFIID riid
,LPVOID
*ppobj
192 ICOM_THIS(IDirectInputAImpl
,iface
);
194 TRACE("(this=%p,%s,%p)\n",This
,debugstr_guid(riid
),ppobj
);
195 if (IsEqualGUID(&IID_IUnknown
,riid
)) {
196 IDirectInputA_AddRef(iface
);
200 if (IsEqualGUID(&IID_IDirectInputA
,riid
)) {
201 IDirectInputA_AddRef(iface
);
205 TRACE("Unsupported interface !\n");
209 static HRESULT WINAPI
IDirectInputAImpl_Initialize(
210 LPDIRECTINPUT7A iface
,HINSTANCE hinst
,DWORD x
212 return DIERR_ALREADYINITIALIZED
;
215 static HRESULT WINAPI
IDirectInputAImpl_GetDeviceStatus(LPDIRECTINPUT7A iface
,
217 ICOM_THIS(IDirectInputAImpl
,iface
);
219 FIXME("(%p)->(%s): stub\n",This
,debugstr_guid(rguid
));
224 static HRESULT WINAPI
IDirectInputAImpl_RunControlPanel(LPDIRECTINPUT7A iface
,
227 ICOM_THIS(IDirectInputAImpl
,iface
);
228 FIXME("(%p)->(%08lx,%08lx): stub\n",This
, (DWORD
) hwndOwner
, dwFlags
);
233 static HRESULT WINAPI
IDirectInput2AImpl_FindDevice(LPDIRECTINPUT2A iface
, REFGUID rguid
,
234 LPCSTR pszName
, LPGUID pguidInstance
) {
235 ICOM_THIS(IDirectInputAImpl
,iface
);
236 FIXME("(%p)->(%s, %s, %p): stub\n", This
, debugstr_guid(rguid
), pszName
, pguidInstance
);
241 static HRESULT WINAPI
IDirectInput7AImpl_CreateDeviceEx(LPDIRECTINPUT7A iface
, REFGUID rguid
,
242 REFIID riid
, LPVOID
* pvOut
, LPUNKNOWN lpUnknownOuter
)
244 ICOM_THIS(IDirectInputAImpl
,iface
);
245 HRESULT ret_value
= DIERR_DEVICENOTREG
;
248 TRACE("(%p)->(%s, %s, %p, %p)\n", This
, debugstr_guid(rguid
), debugstr_guid(riid
), pvOut
, lpUnknownOuter
);
250 /* Loop on all the devices to see if anyone matches the given GUID */
251 for (i
= 0; i
< nrof_dinput_devices
; i
++) {
253 if ((ret
= dinput_devices
[i
]->create_device(This
, rguid
, riid
, (LPDIRECTINPUTDEVICEA
*) pvOut
)) == DI_OK
)
256 if (ret
== DIERR_NOINTERFACE
)
257 ret_value
= DIERR_NOINTERFACE
;
263 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
264 # define XCAST(fun) (typeof(ddiavt.fun))
266 # define XCAST(fun) (void*)
269 static ICOM_VTABLE(IDirectInputA
) ddiavt
=
271 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
272 XCAST(QueryInterface
)IDirectInputAImpl_QueryInterface
,
273 XCAST(AddRef
)IDirectInputAImpl_AddRef
,
274 XCAST(Release
)IDirectInputAImpl_Release
,
275 XCAST(CreateDevice
)IDirectInputAImpl_CreateDevice
,
276 XCAST(EnumDevices
)IDirectInputAImpl_EnumDevices
,
277 XCAST(GetDeviceStatus
)IDirectInputAImpl_GetDeviceStatus
,
278 XCAST(RunControlPanel
)IDirectInputAImpl_RunControlPanel
,
279 XCAST(Initialize
)IDirectInputAImpl_Initialize
283 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
284 # define XCAST(fun) (typeof(ddi7avt.fun))
286 # define XCAST(fun) (void*)
289 static ICOM_VTABLE(IDirectInput7A
) ddi7avt
= {
290 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
291 XCAST(QueryInterface
)IDirectInputAImpl_QueryInterface
,
292 XCAST(AddRef
)IDirectInputAImpl_AddRef
,
293 XCAST(Release
)IDirectInputAImpl_Release
,
294 XCAST(CreateDevice
)IDirectInputAImpl_CreateDevice
,
295 XCAST(EnumDevices
)IDirectInputAImpl_EnumDevices
,
296 XCAST(GetDeviceStatus
)IDirectInputAImpl_GetDeviceStatus
,
297 XCAST(RunControlPanel
)IDirectInputAImpl_RunControlPanel
,
298 XCAST(Initialize
)IDirectInputAImpl_Initialize
,
299 XCAST(FindDevice
)IDirectInput2AImpl_FindDevice
,
300 IDirectInput7AImpl_CreateDeviceEx
304 /***********************************************************************
305 * DllCanUnloadNow (DINPUT.@)
307 HRESULT WINAPI
DINPUT_DllCanUnloadNow(void)
309 FIXME("(void): stub\n");
314 /***********************************************************************
315 * DllGetClassObject (DINPUT.@)
317 HRESULT WINAPI
DINPUT_DllGetClassObject(REFCLSID rclsid
, REFIID riid
,
320 FIXME("(%p, %p, %p): stub\n", debugstr_guid(rclsid
),
321 debugstr_guid(riid
), ppv
);
323 return CLASS_E_CLASSNOTAVAILABLE
;
326 /***********************************************************************
327 * DllRegisterServer (DINPUT.@)
329 HRESULT WINAPI
DINPUT_DllRegisterServer(void)
331 FIXME("(void): stub\n");
336 /***********************************************************************
337 * DllUnregisterServer (DINPUT.@)
339 HRESULT WINAPI
DINPUT_DllUnregisterServer(void)
341 FIXME("(void): stub\n");