Update the address of the Free Software Foundation.
[wine] / dlls / dinput8 / dinput8_main.c
1 /* DirectInput 8
2  *
3  * Copyright 2002 TransGaming Technologies Inc.
4  * Copyright 2006 Roderick Colenbrander
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "config.h"
22 #include <assert.h>
23 #include <stdarg.h>
24 #include <string.h>
25
26 #define COBJMACROS
27
28 #include "wine/debug.h"
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winerror.h"
32 #include "dinput.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
35 static LONG dll_count;
36
37 /*
38  * Dll lifetime tracking declaration
39  */
40 static void LockModule(void)
41 {
42     InterlockedIncrement(&dll_count);
43 }
44
45 static void UnlockModule(void)
46 {
47     InterlockedDecrement(&dll_count);
48 }
49
50 /******************************************************************************
51  *      DirectInput8Create (DINPUT8.@)
52  */
53 HRESULT WINAPI DirectInput8Create(HINSTANCE hinst, DWORD dwVersion, REFIID riid, LPVOID *ppDI, LPUNKNOWN punkOuter) {
54     /* TODO: Create the interface using CoCreateInstance as that's what windows does too and check if the version number >= 0x800 */
55     return DirectInputCreateEx(hinst, dwVersion, riid, ppDI, punkOuter);
56 }
57
58 /*******************************************************************************
59  * DirectInput8 ClassFactory
60  */
61 typedef struct
62 {
63     /* IUnknown fields */
64     const IClassFactoryVtbl    *lpVtbl;
65 } IClassFactoryImpl;
66
67 static HRESULT WINAPI DI8CF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
68     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
69     FIXME("%p %s %p\n",This,debugstr_guid(riid),ppobj);
70     return E_NOINTERFACE;
71 }
72
73 static ULONG WINAPI DI8CF_AddRef(LPCLASSFACTORY iface) {
74     LockModule();
75     return 2;
76 }
77
78 static ULONG WINAPI DI8CF_Release(LPCLASSFACTORY iface) {
79     UnlockModule();
80     return 1;
81 }
82
83 static HRESULT WINAPI DI8CF_CreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj) {
84     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
85
86     TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
87     if( IsEqualGUID( &IID_IDirectInput8A, riid ) || IsEqualGUID( &IID_IDirectInput8W, riid ) ) {
88         return DirectInput8Create(0, DIRECTINPUT_VERSION, riid, ppobj, pOuter);
89     }
90
91     ERR("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj);    
92     return E_NOINTERFACE;
93 }
94
95 static HRESULT WINAPI DI8CF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
96     TRACE("(%p)->(%d)\n", iface, dolock);
97
98     if(dolock)
99         LockModule();
100     else
101         UnlockModule();
102
103     return S_OK;
104 }
105
106 static const IClassFactoryVtbl DI8CF_Vtbl = {
107     DI8CF_QueryInterface,
108     DI8CF_AddRef,
109     DI8CF_Release,
110     DI8CF_CreateInstance,
111     DI8CF_LockServer
112 };
113 static IClassFactoryImpl DINPUT8_CF = { &DI8CF_Vtbl };
114
115
116 /***********************************************************************
117  *              DllCanUnloadNow (DINPUT8.@)
118  */
119 HRESULT WINAPI DllCanUnloadNow(void)
120 {
121     return dll_count == 0 ? S_OK : S_FALSE;
122 }
123
124 /***********************************************************************
125  *              DllGetClassObject (DINPUT8.@)
126  */
127 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
128 {
129     TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
130     if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
131         *ppv = (LPVOID)&DINPUT8_CF;
132         IClassFactory_AddRef((IClassFactory*)*ppv);
133         return S_OK;
134     }
135
136     FIXME("(%s,%s,%p): no interface found.\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
137     return CLASS_E_CLASSNOTAVAILABLE;
138 }
139
140 /***********************************************************************
141  *              DllRegisterServer (DINPUT8.@)
142  */
143 HRESULT WINAPI DllRegisterServer(void)
144 {
145     FIXME("(void): stub\n");
146
147     return S_OK;
148 }
149
150 /***********************************************************************
151  *              DllUnregisterServer (DINPUT8.@)
152  */
153 HRESULT WINAPI DllUnregisterServer(void)
154 {
155     FIXME("(void): stub\n");
156
157     return S_OK;
158 }