3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998,1999 Lionel Ulmer
9 * - Tomb Raider 2 Demo:
10 * Playable using keyboard only.
11 * - WingCommander Prophecy Demo:
12 * Doesn't get Input Focus.
14 * - Fallout : works great in X and DGA mode
16 * FIXME: The keyboard handling needs to (and will) be merged into keyboard.c
17 * (The current implementation is currently only a proof of concept and
24 #include "debugtools.h"
28 #include "dinput_private.h"
30 DEFAULT_DEBUG_CHANNEL(dinput);
32 static ICOM_VTABLE(IDirectInputA) ddiavt;
33 static ICOM_VTABLE(IDirectInput7A) ddi7avt;
35 /* This array will be filled a dinput.so loading */
36 #define MAX_WINE_DINPUT_DEVICES 4
37 static dinput_device * dinput_devices[MAX_WINE_DINPUT_DEVICES];
38 static int nrof_dinput_devices = 0;
40 /* register a direct draw driver. We better not use malloc for we are in
41 * the ELF startup initialisation at this point.
43 void dinput_register_device(dinput_device *device) {
46 /* insert according to priority */
47 for (i=0;i<nrof_dinput_devices;i++) {
48 if (dinput_devices[i]->pref <= device->pref) {
49 memcpy(dinput_devices+i+1,dinput_devices+i,sizeof(dinput_devices[0])*(nrof_dinput_devices-i));
50 dinput_devices[i] = device;
54 if (i==nrof_dinput_devices) /* not found, or too low priority */
55 dinput_devices[nrof_dinput_devices] = device;
57 nrof_dinput_devices++;
59 /* increase MAX_DDRAW_DRIVERS if the line below triggers */
60 assert(nrof_dinput_devices <= MAX_WINE_DINPUT_DEVICES);
63 /******************************************************************************
66 HRESULT WINAPI DirectInputCreateEx(
67 HINSTANCE hinst, DWORD dwVersion, REFIID riid, LPVOID *ppDI,
70 IDirectInputAImpl* This;
72 TRACE("(0x%08lx,%04lx,%s,%p,%p)\n",
73 (DWORD)hinst,dwVersion,debugstr_guid(riid),ppDI,punkOuter
75 if (IsEqualGUID(&IID_IDirectInputA,riid)) {
76 This = (IDirectInputAImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputAImpl));
78 ICOM_VTBL(This) = &ddiavt;
84 if (IsEqualGUID(&IID_IDirectInput7A,riid)) {
85 This = (IDirectInputAImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputAImpl));
87 ICOM_VTBL(This) = (ICOM_VTABLE(IDirectInputA) *) &ddi7avt;
93 return DIERR_OLDDIRECTINPUTVERSION;
96 /******************************************************************************
99 HRESULT WINAPI DirectInputCreateA(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUTA *ppDI, LPUNKNOWN punkOuter)
101 IDirectInputAImpl* This;
102 TRACE("(0x%08lx,%04lx,%p,%p)\n",
103 (DWORD)hinst,dwVersion,ppDI,punkOuter
105 This = (IDirectInputAImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputAImpl));
107 ICOM_VTBL(This) = &ddiavt;
108 *ppDI=(IDirectInputA*)This;
111 /******************************************************************************
112 * IDirectInputA_EnumDevices
114 static HRESULT WINAPI IDirectInputAImpl_EnumDevices(
115 LPDIRECTINPUTA iface, DWORD dwDevType, LPDIENUMDEVICESCALLBACKA lpCallback,
116 LPVOID pvRef, DWORD dwFlags
119 ICOM_THIS(IDirectInputAImpl,iface);
120 DIDEVICEINSTANCEA devInstance;
123 TRACE("(this=%p,0x%04lx,%p,%p,%04lx)\n", This, dwDevType, lpCallback, pvRef, dwFlags);
125 for (i = 0; i < nrof_dinput_devices; i++) {
126 if (dinput_devices[i]->enum_device(dwDevType, dwFlags, &devInstance)) {
127 if (lpCallback(&devInstance,pvRef) == DIENUM_STOP)
135 static ULONG WINAPI IDirectInputAImpl_AddRef(LPDIRECTINPUTA iface)
137 ICOM_THIS(IDirectInputAImpl,iface);
138 return ++(This->ref);
141 static ULONG WINAPI IDirectInputAImpl_Release(LPDIRECTINPUTA iface)
143 ICOM_THIS(IDirectInputAImpl,iface);
144 if (!(--This->ref)) {
145 HeapFree(GetProcessHeap(),0,This);
151 static HRESULT WINAPI IDirectInputAImpl_CreateDevice(
152 LPDIRECTINPUTA iface,REFGUID rguid,LPDIRECTINPUTDEVICEA* pdev,
155 ICOM_THIS(IDirectInputAImpl,iface);
156 HRESULT ret_value = DIERR_DEVICENOTREG;
159 TRACE("(this=%p,%s,%p,%p)\n",This,debugstr_guid(rguid),pdev,punk);
161 /* Loop on all the devices to see if anyone matches the given GUID */
162 for (i = 0; i < nrof_dinput_devices; i++) {
164 if ((ret = dinput_devices[i]->create_device(This, rguid, NULL, pdev)) == DI_OK)
167 if (ret == DIERR_NOINTERFACE)
168 ret_value = DIERR_NOINTERFACE;
174 static HRESULT WINAPI IDirectInputAImpl_QueryInterface(
175 LPDIRECTINPUTA iface,REFIID riid,LPVOID *ppobj
177 ICOM_THIS(IDirectInputAImpl,iface);
179 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
180 if (IsEqualGUID(&IID_IUnknown,riid)) {
181 IDirectInputA_AddRef(iface);
185 if (IsEqualGUID(&IID_IDirectInputA,riid)) {
186 IDirectInputA_AddRef(iface);
190 TRACE("Unsupported interface !\n");
194 static HRESULT WINAPI IDirectInputAImpl_Initialize(
195 LPDIRECTINPUTA iface,HINSTANCE hinst,DWORD x
197 return DIERR_ALREADYINITIALIZED;
200 static HRESULT WINAPI IDirectInputAImpl_GetDeviceStatus(LPDIRECTINPUTA iface,
202 ICOM_THIS(IDirectInputAImpl,iface);
204 FIXME("(%p)->(%s): stub\n",This,debugstr_guid(rguid));
209 static HRESULT WINAPI IDirectInputAImpl_RunControlPanel(LPDIRECTINPUTA iface,
212 ICOM_THIS(IDirectInputAImpl,iface);
213 FIXME("(%p)->(%08lx,%08lx): stub\n",This, (DWORD) hwndOwner, dwFlags);
218 static HRESULT WINAPI IDirectInput2AImpl_FindDevice(LPDIRECTINPUT2A iface, REFGUID rguid,
219 LPCSTR pszName, LPGUID pguidInstance) {
220 ICOM_THIS(IDirectInputAImpl,iface);
221 FIXME("(%p)->(%s, %s, %p): stub\n", This, debugstr_guid(rguid), pszName, pguidInstance);
226 static HRESULT WINAPI IDirectInput7AImpl_CreateDeviceEx(LPDIRECTINPUT7A iface, REFGUID rguid,
227 REFIID riid, LPVOID* pvOut, LPUNKNOWN lpUnknownOuter)
229 ICOM_THIS(IDirectInputAImpl,iface);
230 HRESULT ret_value = DIERR_DEVICENOTREG;
233 TRACE("(%p)->(%s, %s, %p, %p)\n", This, debugstr_guid(rguid), debugstr_guid(riid), pvOut, lpUnknownOuter);
235 /* Loop on all the devices to see if anyone matches the given GUID */
236 for (i = 0; i < nrof_dinput_devices; i++) {
238 if ((ret = dinput_devices[i]->create_device(This, rguid, riid, (LPDIRECTINPUTDEVICEA*) pvOut)) == DI_OK)
241 if (ret == DIERR_NOINTERFACE)
242 ret_value = DIERR_NOINTERFACE;
248 static ICOM_VTABLE(IDirectInputA) ddiavt =
250 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
251 IDirectInputAImpl_QueryInterface,
252 IDirectInputAImpl_AddRef,
253 IDirectInputAImpl_Release,
254 IDirectInputAImpl_CreateDevice,
255 IDirectInputAImpl_EnumDevices,
256 IDirectInputAImpl_GetDeviceStatus,
257 IDirectInputAImpl_RunControlPanel,
258 IDirectInputAImpl_Initialize
261 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
262 # define XCAST(fun) (typeof(ddi7avt.fn##fun))
264 # define XCAST(fun) (void*)
267 static ICOM_VTABLE(IDirectInput7A) ddi7avt = {
268 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
269 XCAST(QueryInterface)IDirectInputAImpl_QueryInterface,
270 XCAST(AddRef)IDirectInputAImpl_AddRef,
271 XCAST(Release)IDirectInputAImpl_Release,
272 XCAST(CreateDevice)IDirectInputAImpl_CreateDevice,
273 XCAST(EnumDevices)IDirectInputAImpl_EnumDevices,
274 XCAST(GetDeviceStatus)IDirectInputAImpl_GetDeviceStatus,
275 XCAST(RunControlPanel)IDirectInputAImpl_RunControlPanel,
276 XCAST(Initialize)IDirectInputAImpl_Initialize,
277 XCAST(FindDevice)IDirectInput2AImpl_FindDevice,
278 IDirectInput7AImpl_CreateDeviceEx
282 /***********************************************************************
283 * DllCanUnloadNow (DINPUT.@)
285 HRESULT WINAPI DINPUT_DllCanUnloadNow(void)
287 FIXME("(void): stub\n");
292 /***********************************************************************
293 * DllGetClassObject (DINPUT.@)
295 HRESULT WINAPI DINPUT_DllGetClassObject(REFCLSID rclsid, REFIID riid,
298 FIXME("(%p, %p, %p): stub\n", debugstr_guid(rclsid),
299 debugstr_guid(riid), ppv);
301 return CLASS_E_CLASSNOTAVAILABLE;
304 /***********************************************************************
305 * DllRegisterServer (DINPUT.@)
307 HRESULT WINAPI DINPUT_DllRegisterServer(void)
309 FIXME("(void): stub\n");
314 /***********************************************************************
315 * DllUnregisterServer (DINPUT.@)
317 HRESULT WINAPI DINPUT_DllUnregisterServer(void)
319 FIXME("(void): stub\n");