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