2 * Copyright 2005 Jacek Caban
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/debug.h"
26 #include "wine/unicode.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(atl);
30 /**************************************************************
31 * ClassFactory implementation
34 static HRESULT WINAPI RegistrarCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppvObject)
36 TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppvObject);
38 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
40 IClassFactory_AddRef( iface );
47 static ULONG WINAPI RegistrarCF_AddRef(IClassFactory *iface)
52 static ULONG WINAPI RegistrarCF_Release(IClassFactory *iface)
57 static HRESULT WINAPI RegistrarCF_CreateInstance(IClassFactory *iface, LPUNKNOWN pUnkOuter,
58 REFIID riid, void **ppv)
60 IRegistrar *registrar;
63 TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
67 return CLASS_E_NOAGGREGATION;
70 hres = AtlCreateRegistrar(®istrar);
74 hres = IRegistrar_QueryInterface(registrar, riid, ppv);
75 IRegistrar_Release(registrar);
79 static HRESULT WINAPI RegistrarCF_LockServer(IClassFactory *iface, BOOL lock)
81 TRACE("(%p)->(%x)\n", iface, lock);
85 static const IClassFactoryVtbl IRegistrarCFVtbl = {
86 RegistrarCF_QueryInterface,
89 RegistrarCF_CreateInstance,
90 RegistrarCF_LockServer
93 static IClassFactory RegistrarCF = { &IRegistrarCFVtbl };
95 /**************************************************************
96 * DllGetClassObject (ATL.2)
98 HRESULT WINAPI DllGetClassObject(REFCLSID clsid, REFIID riid, LPVOID *ppvObject)
100 TRACE("(%s %s %p)\n", debugstr_guid(clsid), debugstr_guid(riid), ppvObject);
102 if(IsEqualGUID(&CLSID_Registrar, clsid))
103 return IClassFactory_QueryInterface( &RegistrarCF, riid, ppvObject );
105 FIXME("Not supported class %s\n", debugstr_guid(clsid));
106 return CLASS_E_CLASSNOTAVAILABLE;
109 extern HINSTANCE hInst;
111 static HRESULT do_register_dll_server(IRegistrar *pRegistrar, LPCOLESTR wszDll,
112 LPCOLESTR wszId, BOOL do_register,
113 const struct _ATL_REGMAP_ENTRY* pMapEntries)
115 IRegistrar *registrar;
117 const struct _ATL_REGMAP_ENTRY *pMapEntry;
119 static const WCHAR wszModule[] = {'M','O','D','U','L','E',0};
120 static const WCHAR wszRegistry[] = {'R','E','G','I','S','T','R','Y',0};
123 registrar = pRegistrar;
125 hres = AtlCreateRegistrar(®istrar);
130 IRegistrar_AddReplacement(registrar, wszModule, wszDll);
132 for (pMapEntry = pMapEntries; pMapEntry && pMapEntry->szKey; pMapEntry++)
133 IRegistrar_AddReplacement(registrar, pMapEntry->szKey, pMapEntry->szData);
136 hres = IRegistrar_ResourceRegisterSz(registrar, wszDll, wszId, wszRegistry);
138 hres = IRegistrar_ResourceUnregisterSz(registrar, wszDll, wszId, wszRegistry);
140 if(registrar != pRegistrar)
141 IRegistrar_Release(registrar);
145 /***********************************************************************
146 * AtlModuleUpdateRegistryFromResourceD [ATL.@]
149 HRESULT WINAPI AtlModuleUpdateRegistryFromResourceD(_ATL_MODULEW* pM, LPCOLESTR lpszRes,
150 BOOL bRegister, struct _ATL_REGMAP_ENTRY* pMapEntries, IRegistrar* pReg)
152 HINSTANCE lhInst = pM->m_hInst;
153 /* everything inside this function below this point
154 * should go into atl71.AtlUpdateRegistryFromResourceD
156 WCHAR module_name[MAX_PATH];
158 if(!GetModuleFileNameW(lhInst, module_name, MAX_PATH)) {
159 FIXME("hinst %p: did not get module name\n",
164 TRACE("%p (%s), %s, %d, %p, %p\n", hInst, debugstr_w(module_name),
165 debugstr_w(lpszRes), bRegister, pMapEntries, pReg);
167 return do_register_dll_server(pReg, module_name, lpszRes, bRegister, pMapEntries);
170 /***********************************************************************
171 * DllRegisterServer (ATL.@)
173 HRESULT WINAPI DllRegisterServer(void)
175 return __wine_register_resources( hInst );
178 /***********************************************************************
179 * DllUnRegisterServer (ATL.@)
181 HRESULT WINAPI DllUnregisterServer(void)
183 return __wine_unregister_resources( hInst );
186 /***********************************************************************
187 * DllCanUnloadNow (ATL.@)
189 HRESULT WINAPI DllCanUnloadNow(void)