dxdiagn: Remove unneeded casts.
[wine.git] / dlls / browseui / browseui_main.c
blob8e93cf3b062f16c1b3552f2e70904392e77f7b65
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 {&CLSID_ProgressDialog, ProgressDialog_Constructor},
54 {NULL, NULL}
57 typedef struct tagClassFactory
59 const IClassFactoryVtbl *vtbl;
60 LONG ref;
61 LPFNCONSTRUCTOR ctor;
62 } ClassFactory;
63 static const IClassFactoryVtbl ClassFactoryVtbl;
65 static HRESULT ClassFactory_Constructor(LPFNCONSTRUCTOR ctor, LPVOID *ppvOut)
67 ClassFactory *This = CoTaskMemAlloc(sizeof(ClassFactory));
68 This->vtbl = &ClassFactoryVtbl;
69 This->ref = 1;
70 This->ctor = ctor;
71 *ppvOut = (LPVOID)This;
72 TRACE("Created class factory %p\n", This);
73 BROWSEUI_refCount++;
74 return S_OK;
77 static void ClassFactory_Destructor(ClassFactory *This)
79 TRACE("Destroying class factory %p\n", This);
80 CoTaskMemFree(This);
81 BROWSEUI_refCount--;
84 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppvOut)
86 *ppvOut = NULL;
87 if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown)) {
88 IClassFactory_AddRef(iface);
89 *ppvOut = iface;
90 return S_OK;
93 WARN("Unknown interface %s\n", debugstr_guid(riid));
94 return E_NOINTERFACE;
97 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
99 ClassFactory *This = (ClassFactory *)iface;
100 return InterlockedIncrement(&This->ref);
103 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
105 ClassFactory *This = (ClassFactory *)iface;
106 ULONG ret = InterlockedDecrement(&This->ref);
108 if (ret == 0)
109 ClassFactory_Destructor(This);
110 return ret;
113 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID iid, LPVOID *ppvOut)
115 ClassFactory *This = (ClassFactory *)iface;
116 HRESULT ret;
117 IUnknown *obj;
119 TRACE("(%p, %p, %s, %p)\n", iface, punkOuter, debugstr_guid(iid), ppvOut);
120 ret = This->ctor(punkOuter, &obj);
121 if (FAILED(ret))
122 return ret;
123 ret = IUnknown_QueryInterface(obj, iid, ppvOut);
124 IUnknown_Release(obj);
125 return ret;
128 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
130 ClassFactory *This = (ClassFactory *)iface;
132 TRACE("(%p)->(%x)\n", This, fLock);
134 if(fLock)
135 InterlockedIncrement(&BROWSEUI_refCount);
136 else
137 InterlockedDecrement(&BROWSEUI_refCount);
139 return S_OK;
142 static const IClassFactoryVtbl ClassFactoryVtbl = {
143 /* IUnknown */
144 ClassFactory_QueryInterface,
145 ClassFactory_AddRef,
146 ClassFactory_Release,
148 /* IClassFactory*/
149 ClassFactory_CreateInstance,
150 ClassFactory_LockServer
153 /*************************************************************************
154 * BROWSEUI DllMain
156 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID fImpLoad)
158 TRACE("%p 0x%x %p\n", hinst, fdwReason, fImpLoad);
159 switch (fdwReason)
161 case DLL_WINE_PREATTACH:
162 return FALSE; /* prefer native version */
163 case DLL_PROCESS_ATTACH:
164 DisableThreadLibraryCalls(hinst);
165 BROWSEUI_hinstance = hinst;
166 break;
168 return TRUE;
171 /*************************************************************************
172 * DllCanUnloadNow (BROWSEUI.@)
174 HRESULT WINAPI DllCanUnloadNow(void)
176 return BROWSEUI_refCount ? S_FALSE : S_OK;
179 /***********************************************************************
180 * DllGetVersion (BROWSEUI.@)
182 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *info)
184 if (info->cbSize != sizeof(DLLVERSIONINFO)) FIXME("support DLLVERSIONINFO2\n");
186 /* this is what IE6 on Windows 98 reports */
187 info->dwMajorVersion = 6;
188 info->dwMinorVersion = 0;
189 info->dwBuildNumber = 2600;
190 info->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
192 return NOERROR;
195 /***********************************************************************
196 * DllGetClassObject (BROWSEUI.@)
198 HRESULT WINAPI DllGetClassObject(REFCLSID clsid, REFIID iid, LPVOID *ppvOut)
200 int i;
202 *ppvOut = NULL;
203 if (!IsEqualIID(iid, &IID_IUnknown) && !IsEqualIID(iid, &IID_IClassFactory))
204 return E_NOINTERFACE;
206 for (i = 0; ClassesTable[i].clsid != NULL; i++)
207 if (IsEqualCLSID(ClassesTable[i].clsid, clsid)) {
208 return ClassFactory_Constructor(ClassesTable[i].ctor, ppvOut);
210 FIXME("CLSID %s not supported\n", debugstr_guid(clsid));
211 return CLASS_E_CLASSNOTAVAILABLE;