wineusb.sys: Move event handling to a single thread.
[wine.git] / dlls / browseui / browseui_main.c
blob6d089725d3ce363b0a3d3ff4f0fb259f24145a3b
1 /*
2 * browseui - Internet Explorer / Windows Explorer standard UI
4 * Copyright 2001 John R. Sheets (for CodeWeavers)
5 * Copyright 2004 Mike McCormack (for CodeWeavers)
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.
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.
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
22 #include <stdarg.h>
23 #include <stdio.h>
25 #define COBJMACROS
27 #include "wine/debug.h"
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winreg.h"
31 #include "shlwapi.h"
32 #include "shlguid.h"
33 #include "rpcproxy.h"
35 #include "browseui.h"
37 #include "initguid.h"
38 DEFINE_GUID(CLSID_CompCatCacheDaemon, 0x8C7461EF, 0x2b13, 0x11d2, 0xbe, 0x35, 0x30, 0x78, 0x30, 0x2c, 0x20, 0x30);
40 WINE_DEFAULT_DEBUG_CHANNEL(browseui);
42 LONG BROWSEUI_refCount = 0;
44 HINSTANCE BROWSEUI_hinstance = 0;
46 typedef HRESULT (*LPFNCONSTRUCTOR)(IUnknown *pUnkOuter, IUnknown **ppvOut);
48 static const struct {
49 REFCLSID clsid;
50 LPFNCONSTRUCTOR ctor;
51 } ClassesTable[] = {
52 {&CLSID_ACLMulti, ACLMulti_Constructor},
53 {&CLSID_ProgressDialog, ProgressDialog_Constructor},
54 {&CLSID_CompCatCacheDaemon, CompCatCacheDaemon_Constructor},
55 {&CLSID_ACListISF, ACLShellSource_Constructor},
56 {NULL, NULL}
59 typedef struct tagClassFactory
61 IClassFactory IClassFactory_iface;
62 LONG ref;
63 LPFNCONSTRUCTOR ctor;
64 } ClassFactory;
66 static inline ClassFactory *impl_from_IClassFactory(IClassFactory *iface)
68 return CONTAINING_RECORD(iface, ClassFactory, IClassFactory_iface);
71 static void ClassFactory_Destructor(ClassFactory *This)
73 TRACE("Destroying class factory %p\n", This);
74 free(This);
75 InterlockedDecrement(&BROWSEUI_refCount);
78 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppvOut)
80 *ppvOut = NULL;
81 if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown)) {
82 IClassFactory_AddRef(iface);
83 *ppvOut = iface;
84 return S_OK;
87 WARN("Unknown interface %s\n", debugstr_guid(riid));
88 return E_NOINTERFACE;
91 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
93 ClassFactory *This = impl_from_IClassFactory(iface);
94 return InterlockedIncrement(&This->ref);
97 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
99 ClassFactory *This = impl_from_IClassFactory(iface);
100 ULONG ret = InterlockedDecrement(&This->ref);
102 if (ret == 0)
103 ClassFactory_Destructor(This);
104 return ret;
107 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID iid, LPVOID *ppvOut)
109 ClassFactory *This = impl_from_IClassFactory(iface);
110 HRESULT ret;
111 IUnknown *obj;
113 TRACE("(%p, %p, %s, %p)\n", iface, punkOuter, debugstr_guid(iid), ppvOut);
114 ret = This->ctor(punkOuter, &obj);
115 if (FAILED(ret))
116 return ret;
117 ret = IUnknown_QueryInterface(obj, iid, ppvOut);
118 IUnknown_Release(obj);
119 return ret;
122 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
124 ClassFactory *This = impl_from_IClassFactory(iface);
126 TRACE("(%p)->(%x)\n", This, fLock);
128 if(fLock)
129 InterlockedIncrement(&BROWSEUI_refCount);
130 else
131 InterlockedDecrement(&BROWSEUI_refCount);
133 return S_OK;
136 static const IClassFactoryVtbl ClassFactoryVtbl = {
137 /* IUnknown */
138 ClassFactory_QueryInterface,
139 ClassFactory_AddRef,
140 ClassFactory_Release,
142 /* IClassFactory*/
143 ClassFactory_CreateInstance,
144 ClassFactory_LockServer
147 static HRESULT ClassFactory_Constructor(LPFNCONSTRUCTOR ctor, LPVOID *ppvOut)
149 ClassFactory *This = malloc(sizeof(*This));
150 This->IClassFactory_iface.lpVtbl = &ClassFactoryVtbl;
151 This->ref = 1;
152 This->ctor = ctor;
153 *ppvOut = &This->IClassFactory_iface;
154 TRACE("Created class factory %p\n", This);
155 InterlockedIncrement(&BROWSEUI_refCount);
156 return S_OK;
159 /*************************************************************************
160 * BROWSEUI DllMain
162 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID fImpLoad)
164 TRACE("%p 0x%lx %p\n", hinst, fdwReason, fImpLoad);
165 switch (fdwReason)
167 case DLL_PROCESS_ATTACH:
168 DisableThreadLibraryCalls(hinst);
169 BROWSEUI_hinstance = hinst;
170 break;
172 return TRUE;
175 /*************************************************************************
176 * DllCanUnloadNow (BROWSEUI.@)
178 HRESULT WINAPI DllCanUnloadNow(void)
180 return BROWSEUI_refCount ? S_FALSE : S_OK;
183 /***********************************************************************
184 * DllGetVersion (BROWSEUI.@)
186 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *info)
188 if(info->cbSize == sizeof(DLLVERSIONINFO) ||
189 info->cbSize == sizeof(DLLVERSIONINFO2))
191 /* this is what IE6 on Windows 98 reports */
192 info->dwMajorVersion = 6;
193 info->dwMinorVersion = 0;
194 info->dwBuildNumber = 2600;
195 info->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
196 if(info->cbSize == sizeof(DLLVERSIONINFO2))
198 DLLVERSIONINFO2 *info2 = (DLLVERSIONINFO2*) info;
199 info2->dwFlags = 0;
200 info2->ullVersion = MAKEDLLVERULL(info->dwMajorVersion,
201 info->dwMinorVersion,
202 info->dwBuildNumber,
203 0); /* FIXME: correct hotfix number */
205 return S_OK;
208 WARN("wrong DLLVERSIONINFO size from app.\n");
209 return E_INVALIDARG;
212 /***********************************************************************
213 * DllGetClassObject (BROWSEUI.@)
215 HRESULT WINAPI DllGetClassObject(REFCLSID clsid, REFIID iid, LPVOID *ppvOut)
217 int i;
219 *ppvOut = NULL;
220 if (!IsEqualIID(iid, &IID_IUnknown) && !IsEqualIID(iid, &IID_IClassFactory))
221 return E_NOINTERFACE;
223 for (i = 0; ClassesTable[i].clsid != NULL; i++)
224 if (IsEqualCLSID(ClassesTable[i].clsid, clsid)) {
225 return ClassFactory_Constructor(ClassesTable[i].ctor, ppvOut);
227 FIXME("CLSID %s not supported\n", debugstr_guid(clsid));
228 return CLASS_E_CLASSNOTAVAILABLE;
231 /***********************************************************************
232 * DllInstall (BROWSEUI.@)
234 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
236 FIXME("(%s, %s): stub\n", bInstall ? "TRUE" : "FALSE", debugstr_w(cmdline));
237 return S_OK;