Release 1.3.7.
[wine/gsoc-2012-control.git] / dlls / explorerframe / explorerframe_main.c
blobcc535e7777de6acb21cbb129ed472963f3f173be
1 /*
2 * ExplorerFrame main functions
4 * Copyright 2010 David Hedberg
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winuser.h"
31 #include "winreg.h"
32 #include "shlwapi.h"
33 #include "advpub.h"
34 #include "shobjidl.h"
36 #include "wine/debug.h"
38 #include "explorerframe_main.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(explorerframe);
42 HINSTANCE explorerframe_hinstance;
43 LONG EFRAME_refCount = 0;
45 /*************************************************************************
46 * DllMain (ExplorerFrame.@)
48 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID fImpLoad)
50 TRACE("%p, 0x%x, %p\n", hinst, fdwReason, fImpLoad);
51 switch (fdwReason)
53 case DLL_PROCESS_ATTACH:
54 DisableThreadLibraryCalls(hinst);
55 explorerframe_hinstance = hinst;
56 break;
57 case DLL_PROCESS_DETACH:
58 break;
60 return TRUE;
63 /*************************************************************************
64 * DllCanUnloadNow (ExplorerFrame.@)
66 HRESULT WINAPI DllCanUnloadNow(void)
68 TRACE("refCount is %d\n", EFRAME_refCount);
69 return EFRAME_refCount ? S_FALSE : S_OK;
72 /*************************************************************************
73 * DllGetVersion (ExplorerFrame.@)
75 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *info)
77 TRACE("%p\n", info);
78 if(info->cbSize == sizeof(DLLVERSIONINFO) ||
79 info->cbSize == sizeof(DLLVERSIONINFO2))
81 /* Windows 7 */
82 info->dwMajorVersion = 6;
83 info->dwMinorVersion = 1;
84 info->dwBuildNumber = 7600;
85 info->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
86 if(info->cbSize == sizeof(DLLVERSIONINFO2))
88 DLLVERSIONINFO2 *info2 = (DLLVERSIONINFO2*)info;
89 info2->dwFlags = 0;
90 info2->ullVersion = MAKEDLLVERULL(info->dwMajorVersion,
91 info->dwMinorVersion,
92 info->dwBuildNumber,
93 16385); /* "hotfix number" */
95 return S_OK;
98 WARN("wrong DLLVERSIONINFO size from app.\n");
99 return E_INVALIDARG;
102 /*************************************************************************
103 * Implement the ExplorerFrame class factory
105 * (Taken from shdocvw/factory.c; based on implementation in
106 * ddraw/main.c)
109 #define FACTORY(x) ((IClassFactory*) &(x)->lpClassFactoryVtbl)
111 typedef struct
113 const IClassFactoryVtbl *lpClassFactoryVtbl;
114 HRESULT (*cf)(IUnknown*, REFIID, void**);
115 LONG ref;
116 } IClassFactoryImpl;
118 /*************************************************************************
119 * EFCF_QueryInterface (IUnknown)
121 static HRESULT WINAPI EFCF_QueryInterface(IClassFactory* iface,
122 REFIID riid, void **ppobj)
124 TRACE("%p (%s %p)\n", iface, debugstr_guid(riid), ppobj);
126 if(!ppobj)
127 return E_POINTER;
129 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid))
131 *ppobj = iface;
132 IClassFactory_AddRef(iface);
133 return S_OK;
136 WARN("Interface not supported.\n");
138 *ppobj = NULL;
139 return E_NOINTERFACE;
142 /*************************************************************************
143 * EFCF_AddRef (IUnknown)
145 static ULONG WINAPI EFCF_AddRef(IClassFactory *iface)
147 EFRAME_LockModule();
149 return 2; /* non-heap based object */
152 /*************************************************************************
153 * EFCF_Release (IUnknown)
155 static ULONG WINAPI EFCF_Release(IClassFactory *iface)
157 EFRAME_UnlockModule();
159 return 1; /* non-heap based object */
162 /*************************************************************************
163 * EFCF_CreateInstance (IClassFactory)
165 static HRESULT WINAPI EFCF_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
166 REFIID riid, void **ppobj)
168 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
169 return This->cf(pOuter, riid, ppobj);
172 /*************************************************************************
173 * EFCF_LockServer (IClassFactory)
175 static HRESULT WINAPI EFCF_LockServer(IClassFactory *iface, BOOL dolock)
177 TRACE("%p (%d)\n", iface, dolock);
179 if (dolock)
180 EFRAME_LockModule();
181 else
182 EFRAME_UnlockModule();
184 return S_OK;
187 static const IClassFactoryVtbl EFCF_Vtbl =
189 EFCF_QueryInterface,
190 EFCF_AddRef,
191 EFCF_Release,
192 EFCF_CreateInstance,
193 EFCF_LockServer
196 /*************************************************************************
197 * DllGetClassObject (ExplorerFrame.@)
199 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
201 static IClassFactoryImpl NSTCClassFactory = {&EFCF_Vtbl, NamespaceTreeControl_Constructor};
203 TRACE("%s, %s, %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
205 if(IsEqualGUID(&CLSID_NamespaceTreeControl, rclsid))
206 return IClassFactory_QueryInterface(FACTORY(&NSTCClassFactory), riid, ppv);
208 return CLASS_E_CLASSNOTAVAILABLE;
211 /*************************************************************************
212 * Register/Unregister DLL, based on shdocvw/factory.c
214 static HRESULT reg_install(LPCSTR section, const STRTABLEA *strtable)
216 HRESULT (WINAPI *pRegInstall)(HMODULE hm, LPCSTR pszSection, const STRTABLEA* pstTable);
217 HMODULE hadvpack;
218 HRESULT hres;
220 static const WCHAR advpackW[] = {'a','d','v','p','a','c','k','.','d','l','l',0};
222 hadvpack = LoadLibraryW(advpackW);
223 pRegInstall = (void *)GetProcAddress(hadvpack, "RegInstall");
225 hres = pRegInstall(explorerframe_hinstance, section, strtable);
227 FreeLibrary(hadvpack);
228 return hres;
231 #define INF_SET_CLSID(clsid) \
232 do \
234 static CHAR name[] = "CLSID_" #clsid; \
236 pse[i].pszName = name; \
237 clsids[i++] = &CLSID_ ## clsid; \
238 } while (0)
240 static HRESULT register_server(BOOL doregister)
242 STRTABLEA strtable;
243 STRENTRYA pse[1];
244 static CLSID const *clsids[1];
245 unsigned int i = 0;
246 HRESULT hres;
248 INF_SET_CLSID(NamespaceTreeControl);
250 for(i = 0; i < sizeof(pse)/sizeof(pse[0]); i++)
252 pse[i].pszValue = HeapAlloc(GetProcessHeap(), 0, 39);
253 sprintf(pse[i].pszValue, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
254 clsids[i]->Data1, clsids[i]->Data2, clsids[i]->Data3, clsids[i]->Data4[0],
255 clsids[i]->Data4[1], clsids[i]->Data4[2], clsids[i]->Data4[3], clsids[i]->Data4[4],
256 clsids[i]->Data4[5], clsids[i]->Data4[6], clsids[i]->Data4[7]);
259 strtable.cEntries = sizeof(pse)/sizeof(pse[0]);
260 strtable.pse = pse;
262 hres = reg_install(doregister ? "RegisterDll" : "UnregisterDll", &strtable);
264 for(i=0; i < sizeof(pse)/sizeof(pse[0]); i++)
265 HeapFree(GetProcessHeap(), 0, pse[i].pszValue);
267 return hres;
270 #undef INF_SET_CLSID
272 /*************************************************************************
273 * DllRegisterServer (ExplorerFrame.@)
275 HRESULT WINAPI DllRegisterServer(void)
277 return register_server(TRUE);
280 /*************************************************************************
281 * DllUnregisterServer (ExplorerFrame.@)
283 HRESULT WINAPI DllUnregisterServer(void)
285 return register_server(FALSE);