Removed W->A from DEFWND_ImmIsUIMessageW.
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 "itss.h"
39 #include "uuids.h"
40
41 #include "wine/unicode.h"
42 #include "wine/debug.h"
43
44 #include "itsstor.h"
45
46 WINE_DEFAULT_DEBUG_CHANNEL(itss);
47
48 #include "initguid.h"
49
50 DEFINE_GUID(CLSID_ITStorage,0x5d02926a,0x212e,0x11d0,0x9d,0xf9,0x00,0xa0,0xc9,0x22,0xe6,0xec );
51 DEFINE_GUID(CLSID_ITSProtocol,0x9d148290,0xb9c8,0x11d0,0xa4,0xcc,0x00,0x00,0xf8,0x01,0x49,0xf6);
52 DEFINE_GUID(IID_IITStorage, 0x88cc31de, 0x27ab, 0x11d0, 0x9d, 0xf9, 0x0, 0xa0, 0xc9, 0x22, 0xe6, 0xec);
53
54 static HRESULT ITSS_create(IUnknown *pUnkOuter, LPVOID *ppObj);
55
56 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
57 {
58     switch(fdwReason) {
59     case DLL_PROCESS_ATTACH:
60         DisableThreadLibraryCalls(hInstDLL);
61         break;
62     case DLL_PROCESS_DETACH:
63         break;
64     }
65     return TRUE;
66 }
67
68 /******************************************************************************
69  * ITSS ClassFactory
70  */
71 typedef struct {
72     IClassFactory ITF_IClassFactory;
73
74     DWORD ref;
75     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
76 } IClassFactoryImpl;
77
78 struct object_creation_info
79 {
80     const CLSID *clsid;
81     LPCSTR szClassName;
82     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
83 };
84
85 static const struct object_creation_info object_creation[] =
86 {
87     { &CLSID_ITStorage, "ITStorage", ITSS_create },
88     { &CLSID_ITSProtocol, "ITSProtocol", ITS_IParseDisplayName_create },
89 };
90
91 static HRESULT WINAPI
92 ITSSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
93 {
94     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
95
96     if (IsEqualGUID(riid, &IID_IUnknown)
97         || IsEqualGUID(riid, &IID_IClassFactory))
98     {
99         IClassFactory_AddRef(iface);
100         *ppobj = This;
101         return S_OK;
102     }
103
104     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
105     return E_NOINTERFACE;
106 }
107
108 static ULONG WINAPI ITSSCF_AddRef(LPCLASSFACTORY iface)
109 {
110     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
111     return InterlockedIncrement(&This->ref);
112 }
113
114 static ULONG WINAPI ITSSCF_Release(LPCLASSFACTORY iface)
115 {
116     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
117
118     ULONG ref = InterlockedDecrement(&This->ref);
119
120     if (ref == 0)
121         HeapFree(GetProcessHeap(), 0, This);
122
123     return ref;
124 }
125
126
127 static HRESULT WINAPI ITSSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
128                                           REFIID riid, LPVOID *ppobj)
129 {
130     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
131     HRESULT hres;
132     LPUNKNOWN punk;
133     
134     TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
135
136     *ppobj = NULL;
137     hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
138     if (SUCCEEDED(hres)) {
139         hres = IUnknown_QueryInterface(punk, riid, ppobj);
140         IUnknown_Release(punk);
141     }
142     return hres;
143 }
144
145 static HRESULT WINAPI ITSSCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
146 {
147     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
148     FIXME("(%p)->(%d),stub!\n",This,dolock);
149     return S_OK;
150 }
151
152 static IClassFactoryVtbl ITSSCF_Vtbl =
153 {
154     ITSSCF_QueryInterface,
155     ITSSCF_AddRef,
156     ITSSCF_Release,
157     ITSSCF_CreateInstance,
158     ITSSCF_LockServer
159 };
160
161
162 HRESULT WINAPI ITSS_DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
163 {
164     DWORD i;
165     IClassFactoryImpl *factory;
166
167     TRACE("%s %s %p\n",debugstr_guid(rclsid), debugstr_guid(iid), ppv);
168     
169     if ( !IsEqualGUID( &IID_IClassFactory, iid )
170          && ! IsEqualGUID( &IID_IUnknown, iid) )
171         return E_NOINTERFACE;
172
173     for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
174     {
175         if (IsEqualGUID(object_creation[i].clsid, rclsid))
176             break;
177     }
178
179     if (i == sizeof(object_creation)/sizeof(object_creation[0]))
180     {
181         FIXME("%s: no class found.\n", debugstr_guid(rclsid));
182         return CLASS_E_CLASSNOTAVAILABLE;
183     }
184
185     TRACE("Creating a class factory for %s\n",object_creation[i].szClassName);
186
187     factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
188     if (factory == NULL) return E_OUTOFMEMORY;
189
190     factory->ITF_IClassFactory.lpVtbl = &ITSSCF_Vtbl;
191     factory->ref = 1;
192
193     factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
194
195     *ppv = &(factory->ITF_IClassFactory);
196
197     TRACE("(%p) <- %p\n", ppv, &(factory->ITF_IClassFactory) );
198
199     return S_OK;
200 }
201
202 /*****************************************************************************/
203
204 typedef struct {
205     IITStorageVtbl *vtbl_IITStorage;
206     DWORD ref;
207 } ITStorageImpl;
208
209
210 HRESULT WINAPI ITStorageImpl_QueryInterface(
211     IITStorage* iface,
212     REFIID riid,
213     void** ppvObject)
214 {
215     ITStorageImpl *This = (ITStorageImpl *)iface;
216     if (IsEqualGUID(riid, &IID_IUnknown)
217         || IsEqualGUID(riid, &IID_IITStorage))
218     {
219         IClassFactory_AddRef(iface);
220         *ppvObject = This;
221         return S_OK;
222     }
223
224     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
225     return E_NOINTERFACE;
226 }
227
228 ULONG WINAPI ITStorageImpl_AddRef(
229     IITStorage* iface)
230 {
231     ITStorageImpl *This = (ITStorageImpl *)iface;
232     TRACE("%p\n", This);
233     return InterlockedIncrement(&This->ref);
234 }
235
236 ULONG WINAPI ITStorageImpl_Release(
237     IITStorage* iface)
238 {
239     ITStorageImpl *This = (ITStorageImpl *)iface;
240     ULONG ref = InterlockedDecrement(&This->ref);
241
242     if (ref == 0)
243         HeapFree(GetProcessHeap(), 0, This);
244
245     return ref;
246 }
247
248 HRESULT WINAPI ITStorageImpl_StgCreateDocfile(
249     IITStorage* iface,
250     const WCHAR* pwcsName,
251     DWORD grfMode,
252     DWORD reserved,
253     IStorage** ppstgOpen)
254 {
255     ITStorageImpl *This = (ITStorageImpl *)iface;
256
257     TRACE("%p %s %lu %lu %p\n", This,
258           debugstr_w(pwcsName), grfMode, reserved, ppstgOpen );
259
260     return ITSS_StgOpenStorage( pwcsName, NULL, grfMode,
261                                 0, reserved, ppstgOpen);
262 }
263
264 HRESULT WINAPI ITStorageImpl_StgCreateDocfileOnILockBytes(
265     IITStorage* iface,
266     ILockBytes* plkbyt,
267     DWORD grfMode,
268     DWORD reserved,
269     IStorage** ppstgOpen)
270 {
271     ITStorageImpl *This = (ITStorageImpl *)iface;
272     FIXME("%p\n", This);
273     return E_NOTIMPL;
274 }
275
276 HRESULT WINAPI ITStorageImpl_StgIsStorageFile(
277     IITStorage* iface,
278     const WCHAR* pwcsName)
279 {
280     ITStorageImpl *This = (ITStorageImpl *)iface;
281     FIXME("%p\n", This);
282     return E_NOTIMPL;
283 }
284
285 HRESULT WINAPI ITStorageImpl_StgIsStorageILockBytes(
286     IITStorage* iface,
287     ILockBytes* plkbyt)
288 {
289     ITStorageImpl *This = (ITStorageImpl *)iface;
290     FIXME("%p\n", This);
291     return E_NOTIMPL;
292 }
293
294 HRESULT WINAPI ITStorageImpl_StgOpenStorage(
295     IITStorage* iface,
296     const WCHAR* pwcsName,
297     IStorage* pstgPriority,
298     DWORD grfMode,
299     SNB snbExclude,
300     DWORD reserved,
301     IStorage** ppstgOpen)
302 {
303     ITStorageImpl *This = (ITStorageImpl *)iface;
304
305     TRACE("%p %s %p %ld %p\n", This, debugstr_w( pwcsName ),
306            pstgPriority, grfMode, snbExclude );
307
308     return ITSS_StgOpenStorage( pwcsName, pstgPriority, grfMode,
309                                 snbExclude, reserved, ppstgOpen);
310 }
311
312 HRESULT WINAPI ITStorageImpl_StgOpenStorageOnILockBytes(
313     IITStorage* iface,
314     ILockBytes* plkbyt,
315     IStorage* pStgPriority,
316     DWORD grfMode,
317     SNB snbExclude,
318     DWORD reserved,
319     IStorage** ppstgOpen)
320 {
321     ITStorageImpl *This = (ITStorageImpl *)iface;
322     FIXME("%p\n", This);
323     return E_NOTIMPL;
324 }
325
326 HRESULT WINAPI ITStorageImpl_StgSetTimes(
327     IITStorage* iface,
328     WCHAR* lpszName,
329     FILETIME* pctime,
330     FILETIME* patime,
331     FILETIME* pmtime)
332 {
333     ITStorageImpl *This = (ITStorageImpl *)iface;
334     FIXME("%p\n", This);
335     return E_NOTIMPL;
336 }
337
338 HRESULT WINAPI ITStorageImpl_SetControlData(
339     IITStorage* iface,
340     PITS_Control_Data pControlData)
341 {
342     ITStorageImpl *This = (ITStorageImpl *)iface;
343     FIXME("%p\n", This);
344     return E_NOTIMPL;
345 }
346
347 HRESULT WINAPI ITStorageImpl_DefaultControlData(
348     IITStorage* iface,
349     PITS_Control_Data* ppControlData)
350 {
351     ITStorageImpl *This = (ITStorageImpl *)iface;
352     FIXME("%p\n", This);
353     return E_NOTIMPL;
354 }
355
356 HRESULT WINAPI ITStorageImpl_Compact(
357     IITStorage* iface,
358     const WCHAR* pwcsName,
359     ECompactionLev iLev)
360 {
361     ITStorageImpl *This = (ITStorageImpl *)iface;
362     FIXME("%p\n", This);
363     return E_NOTIMPL;
364 }
365
366 static IITStorageVtbl ITStorageImpl_Vtbl =
367 {
368     ITStorageImpl_QueryInterface,
369     ITStorageImpl_AddRef,
370     ITStorageImpl_Release,
371     ITStorageImpl_StgCreateDocfile,
372     ITStorageImpl_StgCreateDocfileOnILockBytes,
373     ITStorageImpl_StgIsStorageFile,
374     ITStorageImpl_StgIsStorageILockBytes,
375     ITStorageImpl_StgOpenStorage,
376     ITStorageImpl_StgOpenStorageOnILockBytes,
377     ITStorageImpl_StgSetTimes,
378     ITStorageImpl_SetControlData,
379     ITStorageImpl_DefaultControlData,
380     ITStorageImpl_Compact,
381 };
382
383 static HRESULT ITSS_create(IUnknown *pUnkOuter, LPVOID *ppObj)
384 {
385     ITStorageImpl *its;
386
387     if( pUnkOuter )
388         return CLASS_E_NOAGGREGATION;
389
390     its = HeapAlloc( GetProcessHeap(), 0, sizeof(ITStorageImpl) );
391     its->vtbl_IITStorage = &ITStorageImpl_Vtbl;
392     its->ref = 1;
393
394     TRACE("-> %p\n", its);
395     *ppObj = (LPVOID) its;
396
397     return S_OK;
398 }
399
400 /*****************************************************************************/
401
402 HRESULT WINAPI ITSS_DllRegisterServer(void)
403 {
404     FIXME("\n");
405     return S_OK;
406 }
407
408 BOOL WINAPI ITSS_DllCanUnloadNow(void)
409 {
410     FIXME("\n");
411
412     return FALSE;
413 }