push 735ae92a6c6e93f1d42ab1ae3fd17e22de57873e
[wine/hacks.git] / dlls / browseui / browseui_main.c
blob98b1424390e766d5b57658ed0e7374dcdef4bcd3
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 "config.h"
24 #include <stdarg.h>
25 #include <stdio.h>
27 #define COBJMACROS
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"
36 #include "initguid.h"
38 #include "browseui.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(browseui);
42 LONG BROWSEUI_refCount = 0;
44 HINSTANCE browseui_hinstance = 0;
46 typedef HRESULT (WINAPI *LPFNCONSTRUCTOR)(IUnknown *pUnkOuter, IUnknown **ppvOut);
48 static const struct {
49 REFCLSID clsid;
50 LPFNCONSTRUCTOR ctor;
51 } ClassesTable[] = {
52 {&CLSID_ACLMulti, ACLMulti_Constructor},
53 {NULL, NULL}
56 typedef struct tagClassFactory
58 const IClassFactoryVtbl *vtbl;
59 LONG ref;
60 LPFNCONSTRUCTOR ctor;
61 } ClassFactory;
62 static const IClassFactoryVtbl ClassFactoryVtbl;
64 static HRESULT ClassFactory_Constructor(LPFNCONSTRUCTOR ctor, LPVOID *ppvOut)
66 ClassFactory *This = CoTaskMemAlloc(sizeof(ClassFactory));
67 This->vtbl = &ClassFactoryVtbl;
68 This->ref = 1;
69 This->ctor = ctor;
70 *ppvOut = (LPVOID)This;
71 TRACE("Created class factory %p\n", This);
72 BROWSEUI_refCount++;
73 return S_OK;
76 static void ClassFactory_Destructor(ClassFactory *This)
78 TRACE("Destroying class factory %p\n", This);
79 CoTaskMemFree(This);
80 BROWSEUI_refCount--;
83 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppvOut)
85 *ppvOut = NULL;
86 if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown)) {
87 IClassFactory_AddRef(iface);
88 *ppvOut = iface;
89 return S_OK;
92 WARN("Unknown interface %s\n", debugstr_guid(riid));
93 return E_NOINTERFACE;
96 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
98 ClassFactory *This = (ClassFactory *)iface;
99 return InterlockedIncrement(&This->ref);
102 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
104 ClassFactory *This = (ClassFactory *)iface;
105 ULONG ret = InterlockedDecrement(&This->ref);
107 if (ret == 0)
108 ClassFactory_Destructor(This);
109 return ret;
112 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID iid, LPVOID *ppvOut)
114 ClassFactory *This = (ClassFactory *)iface;
115 HRESULT ret;
116 IUnknown *obj;
118 TRACE("(%p, %p, %s, %p)\n", iface, punkOuter, debugstr_guid(iid), ppvOut);
119 ret = This->ctor(punkOuter, &obj);
120 if (FAILED(ret))
121 return ret;
122 ret = IUnknown_QueryInterface(obj, iid, ppvOut);
123 IUnknown_Release(obj);
124 return ret;
127 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
129 ClassFactory *This = (ClassFactory *)iface;
131 TRACE("(%p)->(%x)\n", This, fLock);
133 if(fLock)
134 InterlockedIncrement(&BROWSEUI_refCount);
135 else
136 InterlockedDecrement(&BROWSEUI_refCount);
138 return S_OK;
141 static const IClassFactoryVtbl ClassFactoryVtbl = {
142 /* IUnknown */
143 ClassFactory_QueryInterface,
144 ClassFactory_AddRef,
145 ClassFactory_Release,
147 /* IClassFactory*/
148 ClassFactory_CreateInstance,
149 ClassFactory_LockServer
152 /*************************************************************************
153 * BROWSEUI DllMain
155 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID fImpLoad)
157 TRACE("%p 0x%x %p\n", hinst, fdwReason, fImpLoad);
158 switch (fdwReason)
160 case DLL_WINE_PREATTACH:
161 return FALSE; /* prefer native version */
162 case DLL_PROCESS_ATTACH:
163 DisableThreadLibraryCalls(hinst);
164 browseui_hinstance = hinst;
165 break;
167 return TRUE;
170 /*************************************************************************
171 * DllCanUnloadNow (BROWSEUI.@)
173 HRESULT WINAPI DllCanUnloadNow(void)
175 return BROWSEUI_refCount ? S_FALSE : S_OK;
178 /***********************************************************************
179 * DllGetVersion (BROWSEUI.@)
181 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *info)
183 if (info->cbSize != sizeof(DLLVERSIONINFO)) FIXME("support DLLVERSIONINFO2\n");
185 /* this is what IE6 on Windows 98 reports */
186 info->dwMajorVersion = 6;
187 info->dwMinorVersion = 0;
188 info->dwBuildNumber = 2600;
189 info->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
191 return NOERROR;
194 /***********************************************************************
195 * DllGetClassObject (BROWSEUI.@)
197 HRESULT WINAPI DllGetClassObject(REFCLSID clsid, REFIID iid, LPVOID *ppvOut)
199 int i;
201 *ppvOut = NULL;
202 if (!IsEqualIID(iid, &IID_IUnknown) && !IsEqualIID(iid, &IID_IClassFactory))
203 return E_NOINTERFACE;
205 for (i = 0; ClassesTable[i].clsid != NULL; i++)
206 if (IsEqualCLSID(ClassesTable[i].clsid, clsid)) {
207 return ClassFactory_Constructor(ClassesTable[i].ctor, ppvOut);
209 FIXME("CLSID %s not supported\n", debugstr_guid(clsid));
210 return CLASS_E_CLASSNOTAVAILABLE;