browseui: Add undocumented Component Category Cache Daemon stub.
[wine] / dlls / browseui / browseui_main.c
1 /*
2  * browseui - Internet Explorer / Windows Explorer standard UI
3  *
4  * Copyright 2001 John R. Sheets (for CodeWeavers)
5  * Copyright 2004 Mike McCormack (for CodeWeavers)
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include "config.h"
23
24 #include <stdarg.h>
25 #include <stdio.h>
26
27 #define COBJMACROS
28
29 #include "wine/debug.h"
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winreg.h"
33 #include "shlwapi.h"
34 #include "shlguid.h"
35
36 #include "initguid.h"
37
38 #include "browseui.h"
39
40 #include "initguid.h"
41 DEFINE_GUID(CLSID_CompCatCacheDaemon, 0x8C7461EF, 0x2b13, 0x11d2, 0xbe, 0x35, 0x30, 0x78, 0x30, 0x2c, 0x20, 0x30);
42
43 WINE_DEFAULT_DEBUG_CHANNEL(browseui);
44
45 LONG BROWSEUI_refCount = 0;
46
47 HINSTANCE BROWSEUI_hinstance = 0;
48
49 typedef HRESULT (WINAPI *LPFNCONSTRUCTOR)(IUnknown *pUnkOuter, IUnknown **ppvOut);
50
51 static const struct {
52     REFCLSID clsid;
53     LPFNCONSTRUCTOR ctor;
54 } ClassesTable[] = {
55     {&CLSID_ACLMulti, ACLMulti_Constructor},
56     {&CLSID_ProgressDialog, ProgressDialog_Constructor},
57     {&CLSID_CompCatCacheDaemon, CompCatCacheDaemon_Constructor},
58     {NULL, NULL}
59 };
60
61 typedef struct tagClassFactory
62 {
63     const IClassFactoryVtbl *vtbl;
64     LONG   ref;
65     LPFNCONSTRUCTOR ctor;
66 } ClassFactory;
67 static const IClassFactoryVtbl ClassFactoryVtbl;
68
69 static HRESULT ClassFactory_Constructor(LPFNCONSTRUCTOR ctor, LPVOID *ppvOut)
70 {
71     ClassFactory *This = CoTaskMemAlloc(sizeof(ClassFactory));
72     This->vtbl = &ClassFactoryVtbl;
73     This->ref = 1;
74     This->ctor = ctor;
75     *ppvOut = (LPVOID)This;
76     TRACE("Created class factory %p\n", This);
77     BROWSEUI_refCount++;
78     return S_OK;
79 }
80
81 static void ClassFactory_Destructor(ClassFactory *This)
82 {
83     TRACE("Destroying class factory %p\n", This);
84     CoTaskMemFree(This);
85     BROWSEUI_refCount--;
86 }
87
88 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppvOut)
89 {
90     *ppvOut = NULL;
91     if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown)) {
92         IClassFactory_AddRef(iface);
93         *ppvOut = iface;
94         return S_OK;
95     }
96
97     WARN("Unknown interface %s\n", debugstr_guid(riid));
98     return E_NOINTERFACE;
99 }
100
101 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
102 {
103     ClassFactory *This = (ClassFactory *)iface;
104     return InterlockedIncrement(&This->ref);
105 }
106
107 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
108 {
109     ClassFactory *This = (ClassFactory *)iface;
110     ULONG ret = InterlockedDecrement(&This->ref);
111
112     if (ret == 0)
113         ClassFactory_Destructor(This);
114     return ret;
115 }
116
117 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID iid, LPVOID *ppvOut)
118 {
119     ClassFactory *This = (ClassFactory *)iface;
120     HRESULT ret;
121     IUnknown *obj;
122
123     TRACE("(%p, %p, %s, %p)\n", iface, punkOuter, debugstr_guid(iid), ppvOut);
124     ret = This->ctor(punkOuter, &obj);
125     if (FAILED(ret))
126         return ret;
127     ret = IUnknown_QueryInterface(obj, iid, ppvOut);
128     IUnknown_Release(obj);
129     return ret;
130 }
131
132 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
133 {
134     ClassFactory *This = (ClassFactory *)iface;
135
136     TRACE("(%p)->(%x)\n", This, fLock);
137
138     if(fLock)
139         InterlockedIncrement(&BROWSEUI_refCount);
140     else
141         InterlockedDecrement(&BROWSEUI_refCount);
142
143     return S_OK;
144 }
145
146 static const IClassFactoryVtbl ClassFactoryVtbl = {
147     /* IUnknown */
148     ClassFactory_QueryInterface,
149     ClassFactory_AddRef,
150     ClassFactory_Release,
151
152     /* IClassFactory*/
153     ClassFactory_CreateInstance,
154     ClassFactory_LockServer
155 };
156
157 /*************************************************************************
158  * BROWSEUI DllMain
159  */
160 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID fImpLoad)
161 {
162     TRACE("%p 0x%x %p\n", hinst, fdwReason, fImpLoad);
163     switch (fdwReason)
164     {
165         case DLL_WINE_PREATTACH:
166             return FALSE;   /* prefer native version */
167         case DLL_PROCESS_ATTACH:
168             DisableThreadLibraryCalls(hinst);
169             BROWSEUI_hinstance = hinst;
170             break;
171     }
172     return TRUE;
173 }
174
175 /*************************************************************************
176  *              DllCanUnloadNow (BROWSEUI.@)
177  */
178 HRESULT WINAPI DllCanUnloadNow(void)
179 {
180     return BROWSEUI_refCount ? S_FALSE : S_OK;
181 }
182
183 /***********************************************************************
184  *              DllGetVersion (BROWSEUI.@)
185  */
186 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *info)
187 {
188     if (info->cbSize != sizeof(DLLVERSIONINFO)) FIXME("support DLLVERSIONINFO2\n");
189
190     /* this is what IE6 on Windows 98 reports */
191     info->dwMajorVersion = 6;
192     info->dwMinorVersion = 0;
193     info->dwBuildNumber = 2600;
194     info->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
195
196     return NOERROR;
197 }
198
199 /***********************************************************************
200  *              DllGetClassObject (BROWSEUI.@)
201  */
202 HRESULT WINAPI DllGetClassObject(REFCLSID clsid, REFIID iid, LPVOID *ppvOut)
203 {
204     int i;
205
206     *ppvOut = NULL;
207     if (!IsEqualIID(iid, &IID_IUnknown) && !IsEqualIID(iid, &IID_IClassFactory))
208         return E_NOINTERFACE;
209
210     for (i = 0; ClassesTable[i].clsid != NULL; i++)
211         if (IsEqualCLSID(ClassesTable[i].clsid, clsid)) {
212             return ClassFactory_Constructor(ClassesTable[i].ctor, ppvOut);
213         }
214     FIXME("CLSID %s not supported\n", debugstr_guid(clsid));
215     return CLASS_E_CLASSNOTAVAILABLE;
216 }