David Hedberg | e2cf9ad | 2010-07-31 20:02:45 +0200 | [diff] [blame] | 1 | /* |
| 2 | * ExplorerFrame main functions |
| 3 | * |
| 4 | * Copyright 2010 David Hedberg |
| 5 | * |
| 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. |
| 10 | * |
| 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. |
| 15 | * |
| 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 |
| 19 | */ |
| 20 | |
| 21 | #include <stdarg.h> |
David Hedberg | d6db373 | 2010-07-31 20:02:50 +0200 | [diff] [blame] | 22 | #include <stdio.h> |
David Hedberg | e2cf9ad | 2010-07-31 20:02:45 +0200 | [diff] [blame] | 23 | |
| 24 | #define COBJMACROS |
| 25 | #define NONAMELESSUNION |
| 26 | #define NONAMELESSSTRUCT |
| 27 | |
| 28 | #include "windef.h" |
| 29 | #include "winbase.h" |
David Hedberg | d6db373 | 2010-07-31 20:02:50 +0200 | [diff] [blame] | 30 | #include "winuser.h" |
David Hedberg | e2cf9ad | 2010-07-31 20:02:45 +0200 | [diff] [blame] | 31 | #include "winreg.h" |
| 32 | #include "shlwapi.h" |
David Hedberg | d6db373 | 2010-07-31 20:02:50 +0200 | [diff] [blame] | 33 | #include "shobjidl.h" |
Alexandre Julliard | a967d98 | 2010-12-10 15:02:43 +0100 | [diff] [blame] | 34 | #include "rpcproxy.h" |
David Hedberg | e2cf9ad | 2010-07-31 20:02:45 +0200 | [diff] [blame] | 35 | |
| 36 | #include "wine/debug.h" |
| 37 | |
| 38 | #include "explorerframe_main.h" |
| 39 | |
| 40 | WINE_DEFAULT_DEBUG_CHANNEL(explorerframe); |
| 41 | |
| 42 | HINSTANCE explorerframe_hinstance; |
| 43 | LONG EFRAME_refCount = 0; |
| 44 | |
| 45 | /************************************************************************* |
| 46 | * DllMain (ExplorerFrame.@) |
| 47 | */ |
| 48 | BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID fImpLoad) |
| 49 | { |
| 50 | TRACE("%p, 0x%x, %p\n", hinst, fdwReason, fImpLoad); |
| 51 | switch (fdwReason) |
| 52 | { |
| 53 | case DLL_PROCESS_ATTACH: |
| 54 | DisableThreadLibraryCalls(hinst); |
| 55 | explorerframe_hinstance = hinst; |
| 56 | break; |
| 57 | case DLL_PROCESS_DETACH: |
| 58 | break; |
| 59 | } |
| 60 | return TRUE; |
| 61 | } |
| 62 | |
| 63 | /************************************************************************* |
| 64 | * DllCanUnloadNow (ExplorerFrame.@) |
| 65 | */ |
| 66 | HRESULT WINAPI DllCanUnloadNow(void) |
| 67 | { |
| 68 | TRACE("refCount is %d\n", EFRAME_refCount); |
| 69 | return EFRAME_refCount ? S_FALSE : S_OK; |
| 70 | } |
David Hedberg | ddfab6b | 2010-07-31 20:02:46 +0200 | [diff] [blame] | 71 | |
| 72 | /************************************************************************* |
| 73 | * DllGetVersion (ExplorerFrame.@) |
| 74 | */ |
| 75 | HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *info) |
| 76 | { |
| 77 | TRACE("%p\n", info); |
| 78 | if(info->cbSize == sizeof(DLLVERSIONINFO) || |
| 79 | info->cbSize == sizeof(DLLVERSIONINFO2)) |
| 80 | { |
| 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)) |
| 87 | { |
| 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" */ |
| 94 | } |
| 95 | return S_OK; |
| 96 | } |
| 97 | |
| 98 | WARN("wrong DLLVERSIONINFO size from app.\n"); |
| 99 | return E_INVALIDARG; |
| 100 | } |
David Hedberg | 46a3e7c | 2010-07-31 20:02:48 +0200 | [diff] [blame] | 101 | |
| 102 | /************************************************************************* |
| 103 | * Implement the ExplorerFrame class factory |
David Hedberg | 46a3e7c | 2010-07-31 20:02:48 +0200 | [diff] [blame] | 104 | */ |
| 105 | |
David Hedberg | 46a3e7c | 2010-07-31 20:02:48 +0200 | [diff] [blame] | 106 | typedef struct |
| 107 | { |
Michael Stefaniuc | 4156a80 | 2011-01-20 01:59:16 +0100 | [diff] [blame] | 108 | IClassFactory IClassFactory_iface; |
David Hedberg | 46a3e7c | 2010-07-31 20:02:48 +0200 | [diff] [blame] | 109 | HRESULT (*cf)(IUnknown*, REFIID, void**); |
| 110 | LONG ref; |
| 111 | } IClassFactoryImpl; |
| 112 | |
Michael Stefaniuc | 4156a80 | 2011-01-20 01:59:16 +0100 | [diff] [blame] | 113 | static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface) |
| 114 | { |
| 115 | return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface); |
| 116 | } |
| 117 | |
David Hedberg | 46a3e7c | 2010-07-31 20:02:48 +0200 | [diff] [blame] | 118 | /************************************************************************* |
Michael Stefaniuc | 4156a80 | 2011-01-20 01:59:16 +0100 | [diff] [blame] | 119 | * EFCF_QueryInterface |
David Hedberg | 46a3e7c | 2010-07-31 20:02:48 +0200 | [diff] [blame] | 120 | */ |
| 121 | static HRESULT WINAPI EFCF_QueryInterface(IClassFactory* iface, |
| 122 | REFIID riid, void **ppobj) |
| 123 | { |
| 124 | TRACE("%p (%s %p)\n", iface, debugstr_guid(riid), ppobj); |
| 125 | |
| 126 | if(!ppobj) |
| 127 | return E_POINTER; |
| 128 | |
| 129 | if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) |
| 130 | { |
| 131 | *ppobj = iface; |
| 132 | IClassFactory_AddRef(iface); |
| 133 | return S_OK; |
| 134 | } |
| 135 | |
| 136 | WARN("Interface not supported.\n"); |
| 137 | |
| 138 | *ppobj = NULL; |
| 139 | return E_NOINTERFACE; |
| 140 | } |
| 141 | |
| 142 | /************************************************************************* |
Michael Stefaniuc | 4156a80 | 2011-01-20 01:59:16 +0100 | [diff] [blame] | 143 | * EFCF_AddRef |
David Hedberg | 46a3e7c | 2010-07-31 20:02:48 +0200 | [diff] [blame] | 144 | */ |
| 145 | static ULONG WINAPI EFCF_AddRef(IClassFactory *iface) |
| 146 | { |
| 147 | EFRAME_LockModule(); |
| 148 | |
| 149 | return 2; /* non-heap based object */ |
| 150 | } |
| 151 | |
| 152 | /************************************************************************* |
Michael Stefaniuc | 4156a80 | 2011-01-20 01:59:16 +0100 | [diff] [blame] | 153 | * EFCF_Release |
David Hedberg | 46a3e7c | 2010-07-31 20:02:48 +0200 | [diff] [blame] | 154 | */ |
| 155 | static ULONG WINAPI EFCF_Release(IClassFactory *iface) |
| 156 | { |
| 157 | EFRAME_UnlockModule(); |
| 158 | |
| 159 | return 1; /* non-heap based object */ |
| 160 | } |
| 161 | |
| 162 | /************************************************************************* |
| 163 | * EFCF_CreateInstance (IClassFactory) |
| 164 | */ |
| 165 | static HRESULT WINAPI EFCF_CreateInstance(IClassFactory *iface, IUnknown *pOuter, |
| 166 | REFIID riid, void **ppobj) |
| 167 | { |
Michael Stefaniuc | 4156a80 | 2011-01-20 01:59:16 +0100 | [diff] [blame] | 168 | IClassFactoryImpl *This = impl_from_IClassFactory(iface); |
David Hedberg | 46a3e7c | 2010-07-31 20:02:48 +0200 | [diff] [blame] | 169 | return This->cf(pOuter, riid, ppobj); |
| 170 | } |
| 171 | |
| 172 | /************************************************************************* |
| 173 | * EFCF_LockServer (IClassFactory) |
| 174 | */ |
| 175 | static HRESULT WINAPI EFCF_LockServer(IClassFactory *iface, BOOL dolock) |
| 176 | { |
| 177 | TRACE("%p (%d)\n", iface, dolock); |
| 178 | |
| 179 | if (dolock) |
| 180 | EFRAME_LockModule(); |
| 181 | else |
| 182 | EFRAME_UnlockModule(); |
| 183 | |
| 184 | return S_OK; |
| 185 | } |
| 186 | |
| 187 | static const IClassFactoryVtbl EFCF_Vtbl = |
| 188 | { |
| 189 | EFCF_QueryInterface, |
| 190 | EFCF_AddRef, |
| 191 | EFCF_Release, |
| 192 | EFCF_CreateInstance, |
| 193 | EFCF_LockServer |
| 194 | }; |
| 195 | |
| 196 | /************************************************************************* |
| 197 | * DllGetClassObject (ExplorerFrame.@) |
| 198 | */ |
| 199 | HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv) |
| 200 | { |
Michael Stefaniuc | 4156a80 | 2011-01-20 01:59:16 +0100 | [diff] [blame] | 201 | static IClassFactoryImpl NSTCClassFactory = {{&EFCF_Vtbl}, NamespaceTreeControl_Constructor}; |
David Hedberg | 46a3e7c | 2010-07-31 20:02:48 +0200 | [diff] [blame] | 202 | |
| 203 | TRACE("%s, %s, %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv); |
| 204 | |
| 205 | if(IsEqualGUID(&CLSID_NamespaceTreeControl, rclsid)) |
Michael Stefaniuc | 4156a80 | 2011-01-20 01:59:16 +0100 | [diff] [blame] | 206 | return IClassFactory_QueryInterface(&NSTCClassFactory.IClassFactory_iface, riid, ppv); |
David Hedberg | 46a3e7c | 2010-07-31 20:02:48 +0200 | [diff] [blame] | 207 | |
| 208 | return CLASS_E_CLASSNOTAVAILABLE; |
| 209 | } |
David Hedberg | d6db373 | 2010-07-31 20:02:50 +0200 | [diff] [blame] | 210 | |
| 211 | /************************************************************************* |
David Hedberg | d6db373 | 2010-07-31 20:02:50 +0200 | [diff] [blame] | 212 | * DllRegisterServer (ExplorerFrame.@) |
| 213 | */ |
| 214 | HRESULT WINAPI DllRegisterServer(void) |
| 215 | { |
Alexandre Julliard | b56dc9a | 2011-08-02 15:51:55 +0200 | [diff] [blame] | 216 | return __wine_register_resources( explorerframe_hinstance ); |
David Hedberg | d6db373 | 2010-07-31 20:02:50 +0200 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | /************************************************************************* |
| 220 | * DllUnregisterServer (ExplorerFrame.@) |
| 221 | */ |
| 222 | HRESULT WINAPI DllUnregisterServer(void) |
| 223 | { |
Alexandre Julliard | b56dc9a | 2011-08-02 15:51:55 +0200 | [diff] [blame] | 224 | return __wine_unregister_resources( explorerframe_hinstance ); |
David Hedberg | d6db373 | 2010-07-31 20:02:50 +0200 | [diff] [blame] | 225 | } |