mshtml: Updated Korean resource.
[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     ClassFactory *This = (ClassFactory *)iface;
130
131     TRACE("(%p)->(%x)\n", This, fLock);
132
133     if(fLock)
134         InterlockedIncrement(&BROWSEUI_refCount);
135     else
136         InterlockedDecrement(&BROWSEUI_refCount);
137
138     return S_OK;
139 }
140
141 static const IClassFactoryVtbl ClassFactoryVtbl = {
142     /* IUnknown */
143     ClassFactory_QueryInterface,
144     ClassFactory_AddRef,
145     ClassFactory_Release,
146
147     /* IClassFactory*/
148     ClassFactory_CreateInstance,
149     ClassFactory_LockServer
150 };
151
152 /*************************************************************************
153  * BROWSEUI DllMain
154  */
155 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID fImpLoad)
156 {
157     TRACE("%p 0x%x %p\n", hinst, fdwReason, fImpLoad);
158     switch (fdwReason)
159     {
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;
166     }
167     return TRUE;
168 }
169
170 /*************************************************************************
171  *              DllCanUnloadNow (BROWSEUI.@)
172  */
173 HRESULT WINAPI DllCanUnloadNow(void)
174 {
175     return BROWSEUI_refCount ? S_FALSE : S_OK;
176 }
177
178 /***********************************************************************
179  *              DllGetVersion (BROWSEUI.@)
180  */
181 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *info)
182 {
183     if (info->cbSize != sizeof(DLLVERSIONINFO)) FIXME("support DLLVERSIONINFO2\n");
184
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;
190
191     return NOERROR;
192 }
193
194 /***********************************************************************
195  *              DllGetClassObject (BROWSEUI.@)
196  */
197 HRESULT WINAPI DllGetClassObject(REFCLSID clsid, REFIID iid, LPVOID *ppvOut)
198 {
199     int i;
200
201     *ppvOut = NULL;
202     if (!IsEqualIID(iid, &IID_IUnknown) && !IsEqualIID(iid, &IID_IClassFactory))
203         return E_NOINTERFACE;
204
205     for (i = 0; ClassesTable[i].clsid != NULL; i++)
206         if (IsEqualCLSID(ClassesTable[i].clsid, clsid)) {
207             return ClassFactory_Constructor(ClassesTable[i].ctor, ppvOut);
208         }
209     FIXME("CLSID %s not supported\n", debugstr_guid(clsid));
210     return CLASS_E_CLASSNOTAVAILABLE;
211 }