browseui: Implement and test ACLMulti.
[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 WINE_DEFAULT_DEBUG_CHANNEL(browseui);
41
42 LONG BROWSEUI_refCount = 0;
43
44 HINSTANCE browseui_hinstance = 0;
45
46 typedef HRESULT (WINAPI *LPFNCONSTRUCTOR)(IUnknown *pUnkOuter, IUnknown **ppvOut);
47
48 static const struct {
49     REFCLSID clsid;
50     LPFNCONSTRUCTOR ctor;
51 } ClassesTable[] = {
52     {&CLSID_ACLMulti, ACLMulti_Constructor},
53     {NULL, NULL}
54 };
55
56 typedef struct tagClassFactory
57 {
58     const IClassFactoryVtbl *vtbl;
59     LONG   ref;
60     LPFNCONSTRUCTOR ctor;
61 } ClassFactory;
62 static const IClassFactoryVtbl ClassFactoryVtbl;
63
64 static HRESULT ClassFactory_Constructor(LPFNCONSTRUCTOR ctor, LPVOID *ppvOut)
65 {
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;
74 }
75
76 static void ClassFactory_Destructor(ClassFactory *This)
77 {
78     TRACE("Destroying class factory %p\n", This);
79     CoTaskMemFree(This);
80     BROWSEUI_refCount--;
81 }
82
83 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppvOut)
84 {
85     *ppvOut = NULL;
86     if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown)) {
87         IClassFactory_AddRef(iface);
88         *ppvOut = iface;
89         return S_OK;
90     }
91
92     WARN("Unknown interface %s\n", debugstr_guid(riid));
93     return E_NOINTERFACE;
94 }
95
96 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
97 {
98     ClassFactory *This = (ClassFactory *)iface;
99     return InterlockedIncrement(&This->ref);
100 }
101
102 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
103 {
104     ClassFactory *This = (ClassFactory *)iface;
105     ULONG ret = InterlockedDecrement(&This->ref);
106
107     if (ret == 0)
108         ClassFactory_Destructor(This);
109     return ret;
110 }
111
112 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID iid, LPVOID *ppvOut)
113 {
114     ClassFactory *This = (ClassFactory *)iface;
115     HRESULT ret;
116     IUnknown *obj;
117
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;
125 }
126
127 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
128 {
129     FIXME("(%p, %s) - not implemented\n", iface, (fLock ? "TRUE" : "FALSE"));
130     return E_NOTIMPL;
131 }
132
133 static const IClassFactoryVtbl ClassFactoryVtbl = {
134     /* IUnknown */
135     ClassFactory_QueryInterface,
136     ClassFactory_AddRef,
137     ClassFactory_Release,
138
139     /* IClassFactory*/
140     ClassFactory_CreateInstance,
141     ClassFactory_LockServer
142 };
143
144 /*************************************************************************
145  * BROWSEUI DllMain
146  */
147 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID fImpLoad)
148 {
149     TRACE("%p 0x%x %p\n", hinst, fdwReason, fImpLoad);
150     switch (fdwReason)
151     {
152         case DLL_WINE_PREATTACH:
153             return FALSE;   /* prefer native version */
154         case DLL_PROCESS_ATTACH:
155             DisableThreadLibraryCalls(hinst);
156             browseui_hinstance = hinst;
157             break;
158     }
159     return TRUE;
160 }
161
162 /*************************************************************************
163  *              DllCanUnloadNow (BROWSEUI.@)
164  */
165 HRESULT WINAPI DllCanUnloadNow(void)
166 {
167     return BROWSEUI_refCount ? S_FALSE : S_OK;
168 }
169
170 /***********************************************************************
171  *              DllGetVersion (BROWSEUI.@)
172  */
173 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *info)
174 {
175     if (info->cbSize != sizeof(DLLVERSIONINFO)) FIXME("support DLLVERSIONINFO2\n");
176
177     /* this is what IE6 on Windows 98 reports */
178     info->dwMajorVersion = 6;
179     info->dwMinorVersion = 0;
180     info->dwBuildNumber = 2600;
181     info->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
182
183     return NOERROR;
184 }
185
186 /***********************************************************************
187  *              DllGetClassObject (BROWSEUI.@)
188  */
189 HRESULT WINAPI DllGetClassObject(REFCLSID clsid, REFIID iid, LPVOID *ppvOut)
190 {
191     int i;
192
193     *ppvOut = NULL;
194     if (!IsEqualIID(iid, &IID_IUnknown) && !IsEqualIID(iid, &IID_IClassFactory))
195         return E_NOINTERFACE;
196
197     for (i = 0; ClassesTable[i].clsid != NULL; i++)
198         if (IsEqualCLSID(ClassesTable[i].clsid, clsid)) {
199             return ClassFactory_Constructor(ClassesTable[i].ctor, ppvOut);
200         }
201     FIXME("CLSID %s not supported\n", debugstr_guid(clsid));
202     return CLASS_E_CLASSNOTAVAILABLE;
203 }