dsound/tests: Win64 printf format warning fixes.
[wine] / dlls / itss / itss.c
1 /*
2  *    ITSS Class Factory
3  *
4  * Copyright 2002 Lionel Ulmer
5  * Copyright 2004 Mike McCormack
6  *
7  *  see http://bonedaddy.net/pabs3/hhm/#chmspec
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23
24 #include "config.h"
25
26 #include <stdarg.h>
27 #include <stdio.h>
28
29 #define COBJMACROS
30
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winuser.h"
34 #include "winnls.h"
35 #include "winreg.h"
36 #include "ole2.h"
37
38 #include "uuids.h"
39
40 #include "wine/unicode.h"
41 #include "wine/debug.h"
42
43 #include "itsstor.h"
44
45 #include "initguid.h"
46 #include "wine/itss.h"
47
48 WINE_DEFAULT_DEBUG_CHANNEL(itss);
49
50 static HRESULT ITSS_create(IUnknown *pUnkOuter, LPVOID *ppObj);
51
52 LONG dll_count = 0;
53
54 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
55 {
56     switch(fdwReason) {
57     case DLL_PROCESS_ATTACH:
58         DisableThreadLibraryCalls(hInstDLL);
59         break;
60     case DLL_PROCESS_DETACH:
61         break;
62     }
63     return TRUE;
64 }
65
66 /******************************************************************************
67  * ITSS ClassFactory
68  */
69 typedef struct {
70     const IClassFactoryVtbl *lpVtbl;
71     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
72 } IClassFactoryImpl;
73
74 static HRESULT WINAPI
75 ITSSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
76 {
77     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
78
79     if (IsEqualGUID(riid, &IID_IUnknown) ||
80         IsEqualGUID(riid, &IID_IClassFactory))
81     {
82         IClassFactory_AddRef(iface);
83         *ppobj = This;
84         return S_OK;
85     }
86
87     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
88     return E_NOINTERFACE;
89 }
90
91 static ULONG WINAPI ITSSCF_AddRef(LPCLASSFACTORY iface)
92 {
93     InterlockedIncrement(&dll_count);
94     return 2;
95 }
96
97 static ULONG WINAPI ITSSCF_Release(LPCLASSFACTORY iface)
98 {
99     InterlockedDecrement(&dll_count);
100     return 1;
101 }
102
103
104 static HRESULT WINAPI ITSSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
105                                           REFIID riid, LPVOID *ppobj)
106 {
107     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
108     HRESULT hres;
109     LPUNKNOWN punk;
110
111     TRACE("(%p)->(%p,%s,%p)\n", This, pOuter, debugstr_guid(riid), ppobj);
112
113     *ppobj = NULL;
114     hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
115     if (SUCCEEDED(hres)) {
116         hres = IUnknown_QueryInterface(punk, riid, ppobj);
117         IUnknown_Release(punk);
118     }
119     return hres;
120 }
121
122 static HRESULT WINAPI ITSSCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
123 {
124     TRACE("(%p)->(%d)\n", iface, dolock);
125
126     if (dolock)
127         InterlockedIncrement(&dll_count);
128     else
129         InterlockedDecrement(&dll_count);
130
131     return S_OK;
132 }
133
134 static const IClassFactoryVtbl ITSSCF_Vtbl =
135 {
136     ITSSCF_QueryInterface,
137     ITSSCF_AddRef,
138     ITSSCF_Release,
139     ITSSCF_CreateInstance,
140     ITSSCF_LockServer
141 };
142
143 static const IClassFactoryImpl ITStorage_factory = { &ITSSCF_Vtbl, ITSS_create };
144 static const IClassFactoryImpl ITSProtocol_factory = { &ITSSCF_Vtbl, ITS_IParseDisplayName_create };
145
146 /***********************************************************************
147  *              DllGetClassObject       (ITSS.@)
148  */
149 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
150 {
151     const IClassFactoryImpl *factory;
152
153     TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);
154
155     if (IsEqualGUID(&CLSID_ITStorage, rclsid))
156         factory = &ITStorage_factory;
157     else if (IsEqualGUID(&CLSID_ITSProtocol, rclsid))
158         factory = &ITSProtocol_factory;
159     else
160     {
161         FIXME("%s: no class found.\n", debugstr_guid(rclsid));
162         return CLASS_E_CLASSNOTAVAILABLE;
163     }
164
165     return IUnknown_QueryInterface( (IUnknown*) factory, iid, ppv );
166 }
167
168 /*****************************************************************************/
169
170 typedef struct {
171     const IITStorageVtbl *vtbl_IITStorage;
172     LONG ref;
173 } ITStorageImpl;
174
175
176 static HRESULT WINAPI ITStorageImpl_QueryInterface(
177     IITStorage* iface,
178     REFIID riid,
179     void** ppvObject)
180 {
181     ITStorageImpl *This = (ITStorageImpl *)iface;
182     if (IsEqualGUID(riid, &IID_IUnknown)
183         || IsEqualGUID(riid, &IID_IITStorage))
184     {
185         IClassFactory_AddRef(iface);
186         *ppvObject = This;
187         return S_OK;
188     }
189
190     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
191     return E_NOINTERFACE;
192 }
193
194 static ULONG WINAPI ITStorageImpl_AddRef(
195     IITStorage* iface)
196 {
197     ITStorageImpl *This = (ITStorageImpl *)iface;
198     TRACE("%p\n", This);
199     return InterlockedIncrement(&This->ref);
200 }
201
202 static ULONG WINAPI ITStorageImpl_Release(
203     IITStorage* iface)
204 {
205     ITStorageImpl *This = (ITStorageImpl *)iface;
206     ULONG ref = InterlockedDecrement(&This->ref);
207
208     if (ref == 0) {
209         HeapFree(GetProcessHeap(), 0, This);
210         InterlockedDecrement(&dll_count);
211     }
212
213     return ref;
214 }
215
216 static HRESULT WINAPI ITStorageImpl_StgCreateDocfile(
217     IITStorage* iface,
218     const WCHAR* pwcsName,
219     DWORD grfMode,
220     DWORD reserved,
221     IStorage** ppstgOpen)
222 {
223     ITStorageImpl *This = (ITStorageImpl *)iface;
224
225     TRACE("%p %s %lu %lu %p\n", This,
226           debugstr_w(pwcsName), grfMode, reserved, ppstgOpen );
227
228     return ITSS_StgOpenStorage( pwcsName, NULL, grfMode,
229                                 0, reserved, ppstgOpen);
230 }
231
232 static HRESULT WINAPI ITStorageImpl_StgCreateDocfileOnILockBytes(
233     IITStorage* iface,
234     ILockBytes* plkbyt,
235     DWORD grfMode,
236     DWORD reserved,
237     IStorage** ppstgOpen)
238 {
239     ITStorageImpl *This = (ITStorageImpl *)iface;
240     FIXME("%p\n", This);
241     return E_NOTIMPL;
242 }
243
244 static HRESULT WINAPI ITStorageImpl_StgIsStorageFile(
245     IITStorage* iface,
246     const WCHAR* pwcsName)
247 {
248     ITStorageImpl *This = (ITStorageImpl *)iface;
249     FIXME("%p\n", This);
250     return E_NOTIMPL;
251 }
252
253 static HRESULT WINAPI ITStorageImpl_StgIsStorageILockBytes(
254     IITStorage* iface,
255     ILockBytes* plkbyt)
256 {
257     ITStorageImpl *This = (ITStorageImpl *)iface;
258     FIXME("%p\n", This);
259     return E_NOTIMPL;
260 }
261
262 static HRESULT WINAPI ITStorageImpl_StgOpenStorage(
263     IITStorage* iface,
264     const WCHAR* pwcsName,
265     IStorage* pstgPriority,
266     DWORD grfMode,
267     SNB snbExclude,
268     DWORD reserved,
269     IStorage** ppstgOpen)
270 {
271     ITStorageImpl *This = (ITStorageImpl *)iface;
272
273     TRACE("%p %s %p %ld %p\n", This, debugstr_w( pwcsName ),
274            pstgPriority, grfMode, snbExclude );
275
276     return ITSS_StgOpenStorage( pwcsName, pstgPriority, grfMode,
277                                 snbExclude, reserved, ppstgOpen);
278 }
279
280 static HRESULT WINAPI ITStorageImpl_StgOpenStorageOnILockBytes(
281     IITStorage* iface,
282     ILockBytes* plkbyt,
283     IStorage* pStgPriority,
284     DWORD grfMode,
285     SNB snbExclude,
286     DWORD reserved,
287     IStorage** ppstgOpen)
288 {
289     ITStorageImpl *This = (ITStorageImpl *)iface;
290     FIXME("%p\n", This);
291     return E_NOTIMPL;
292 }
293
294 static HRESULT WINAPI ITStorageImpl_StgSetTimes(
295     IITStorage* iface,
296     WCHAR* lpszName,
297     FILETIME* pctime,
298     FILETIME* patime,
299     FILETIME* pmtime)
300 {
301     ITStorageImpl *This = (ITStorageImpl *)iface;
302     FIXME("%p\n", This);
303     return E_NOTIMPL;
304 }
305
306 static HRESULT WINAPI ITStorageImpl_SetControlData(
307     IITStorage* iface,
308     PITS_Control_Data pControlData)
309 {
310     ITStorageImpl *This = (ITStorageImpl *)iface;
311     FIXME("%p\n", This);
312     return E_NOTIMPL;
313 }
314
315 static HRESULT WINAPI ITStorageImpl_DefaultControlData(
316     IITStorage* iface,
317     PITS_Control_Data* ppControlData)
318 {
319     ITStorageImpl *This = (ITStorageImpl *)iface;
320     FIXME("%p\n", This);
321     return E_NOTIMPL;
322 }
323
324 static HRESULT WINAPI ITStorageImpl_Compact(
325     IITStorage* iface,
326     const WCHAR* pwcsName,
327     ECompactionLev iLev)
328 {
329     ITStorageImpl *This = (ITStorageImpl *)iface;
330     FIXME("%p\n", This);
331     return E_NOTIMPL;
332 }
333
334 static const IITStorageVtbl ITStorageImpl_Vtbl =
335 {
336     ITStorageImpl_QueryInterface,
337     ITStorageImpl_AddRef,
338     ITStorageImpl_Release,
339     ITStorageImpl_StgCreateDocfile,
340     ITStorageImpl_StgCreateDocfileOnILockBytes,
341     ITStorageImpl_StgIsStorageFile,
342     ITStorageImpl_StgIsStorageILockBytes,
343     ITStorageImpl_StgOpenStorage,
344     ITStorageImpl_StgOpenStorageOnILockBytes,
345     ITStorageImpl_StgSetTimes,
346     ITStorageImpl_SetControlData,
347     ITStorageImpl_DefaultControlData,
348     ITStorageImpl_Compact,
349 };
350
351 static HRESULT ITSS_create(IUnknown *pUnkOuter, LPVOID *ppObj)
352 {
353     ITStorageImpl *its;
354
355     if( pUnkOuter )
356         return CLASS_E_NOAGGREGATION;
357
358     its = HeapAlloc( GetProcessHeap(), 0, sizeof(ITStorageImpl) );
359     its->vtbl_IITStorage = &ITStorageImpl_Vtbl;
360     its->ref = 1;
361
362     TRACE("-> %p\n", its);
363     *ppObj = (LPVOID) its;
364     InterlockedIncrement(&dll_count);
365
366     return S_OK;
367 }
368
369 /*****************************************************************************/
370
371 HRESULT WINAPI DllCanUnloadNow(void)
372 {
373     TRACE("dll_count = %lu\n", dll_count);
374     return dll_count ? S_FALSE : S_OK;
375 }