2 * Implementation of Active Template Library (atl.dll)
4 * Copyright 2004 Aric Stewart for CodeWeavers
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
29 #include "wine/debug.h"
30 #include "wine/unicode.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(atl);
34 DECLSPEC_HIDDEN HINSTANCE hInst;
36 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
38 TRACE("(0x%p, %d, %p)\n",hinstDLL,fdwReason,lpvReserved);
40 if (fdwReason == DLL_PROCESS_ATTACH) {
41 DisableThreadLibraryCalls(hinstDLL);
47 #define ATLVer1Size FIELD_OFFSET(_ATL_MODULEW, dwAtlBuildVer)
49 HRESULT WINAPI AtlModuleInit(_ATL_MODULEW* pM, _ATL_OBJMAP_ENTRYW* p, HINSTANCE h)
54 FIXME("SEMI-STUB (%p %p %p)\n",pM,p,h);
60 case sizeof(_ATL_MODULEW):
62 case sizeof(_ATL_MODULEW) + sizeof(void *):
66 WARN("Unknown structure version (size %i)\n",size);
70 memset(pM,0,pM->cbSize);
73 pM->m_hInstResource = h;
74 pM->m_hInstTypeLib = h;
76 pM->m_hHeap = GetProcessHeap();
78 InitializeCriticalSection(&pM->u.m_csTypeInfoHolder);
79 InitializeCriticalSection(&pM->m_csWindowCreate);
80 InitializeCriticalSection(&pM->m_csObjMap);
84 if (pM->m_pObjMap != NULL && size > ATLVer1Size)
86 while (pM->m_pObjMap[i].pclsid != NULL)
88 TRACE("Initializing object %i %p\n",i,p[i].pfnObjectMain);
89 if (p[i].pfnObjectMain)
90 p[i].pfnObjectMain(TRUE);
98 static _ATL_OBJMAP_ENTRYW_V1 *get_objmap_entry( _ATL_MODULEW *mod, unsigned int index )
100 _ATL_OBJMAP_ENTRYW_V1 *ret;
102 if (mod->cbSize == ATLVer1Size)
103 ret = (_ATL_OBJMAP_ENTRYW_V1 *)mod->m_pObjMap + index;
105 ret = (_ATL_OBJMAP_ENTRYW_V1 *)(mod->m_pObjMap + index);
107 if (!ret->pclsid) ret = NULL;
111 HRESULT WINAPI AtlModuleLoadTypeLib(_ATL_MODULEW *pM, LPCOLESTR lpszIndex,
112 BSTR *pbstrPath, ITypeLib **ppTypeLib)
114 TRACE("(%p, %s, %p, %p)\n", pM, debugstr_w(lpszIndex), pbstrPath, ppTypeLib);
119 return AtlLoadTypeLib(pM->m_hInstTypeLib, lpszIndex, pbstrPath, ppTypeLib);
122 HRESULT WINAPI AtlModuleTerm(_ATL_MODULE *pM)
124 _ATL_TERMFUNC_ELEM *iter = pM->m_pTermFuncs, *tmp;
129 iter->pFunc(iter->dw);
132 HeapFree(GetProcessHeap(), 0, tmp);
138 HRESULT WINAPI AtlModuleAddTermFunc(_ATL_MODULEW *pM, _ATL_TERMFUNC *pFunc, DWORD_PTR dw)
140 _ATL_TERMFUNC_ELEM *termfunc_elem;
142 TRACE("(%p %p %ld)\n", pM, pFunc, dw);
144 termfunc_elem = HeapAlloc(GetProcessHeap(), 0, sizeof(_ATL_TERMFUNC_ELEM));
145 termfunc_elem->pFunc = pFunc;
146 termfunc_elem->dw = dw;
147 termfunc_elem->pNext = pM->m_pTermFuncs;
149 pM->m_pTermFuncs = termfunc_elem;
154 HRESULT WINAPI AtlModuleRegisterClassObjects(_ATL_MODULEW *pM, DWORD dwClsContext,
157 _ATL_OBJMAP_ENTRYW_V1 *obj;
160 TRACE("(%p %i %i)\n",pM, dwClsContext, dwFlags);
165 while ((obj = get_objmap_entry( pM, i++ )))
170 TRACE("Registering object %i\n",i);
171 if (obj->pfnGetClassObject)
173 rc = obj->pfnGetClassObject(obj->pfnCreateInstance, &IID_IUnknown,
177 rc = CoRegisterClassObject(obj->pclsid, pUnknown, dwClsContext,
178 dwFlags, &obj->dwRegister);
181 WARN("Failed to register object %i: 0x%08x\n", i, rc);
184 IUnknown_Release(pUnknown);
192 HRESULT WINAPI AtlModuleUnregisterServerEx(_ATL_MODULEW* pM, BOOL bUnRegTypeLib, const CLSID* pCLSID)
194 FIXME("(%p, %i, %p) stub\n", pM, bUnRegTypeLib, pCLSID);
198 /***********************************************************************
199 * AtlModuleRegisterServer [ATL.@]
202 HRESULT WINAPI AtlModuleRegisterServer(_ATL_MODULEW* pM, BOOL bRegTypeLib, const CLSID* clsid)
204 const _ATL_OBJMAP_ENTRYW_V1 *obj;
208 TRACE("%p %d %s\n", pM, bRegTypeLib, debugstr_guid(clsid));
213 for (i = 0; (obj = get_objmap_entry( pM, i )) != NULL; i++) /* register CLSIDs */
215 if (!clsid || IsEqualCLSID(obj->pclsid, clsid))
217 TRACE("Registering clsid %s\n", debugstr_guid(obj->pclsid));
218 hRes = obj->pfnUpdateRegistry(TRUE); /* register */
226 hRes = AtlModuleRegisterTypeLib(pM, NULL);
234 /***********************************************************************
235 * AtlModuleGetClassObject [ATL.@]
237 HRESULT WINAPI AtlModuleGetClassObject(_ATL_MODULEW *pm, REFCLSID rclsid,
238 REFIID riid, LPVOID *ppv)
240 _ATL_OBJMAP_ENTRYW_V1 *obj;
242 HRESULT hres = CLASS_E_CLASSNOTAVAILABLE;
244 TRACE("%p %s %s %p\n", pm, debugstr_guid(rclsid), debugstr_guid(riid), ppv);
249 for (i = 0; (obj = get_objmap_entry( pm, i )) != NULL; i++)
251 if (IsEqualCLSID(obj->pclsid, rclsid))
253 TRACE("found object %i\n", i);
254 if (obj->pfnGetClassObject)
257 hres = obj->pfnGetClassObject(obj->pfnCreateInstance,
261 hres = IUnknown_QueryInterface(obj->pCF, riid, ppv);
267 WARN("no class object found for %s\n", debugstr_guid(rclsid));
272 /***********************************************************************
273 * AtlModuleGetClassObject [ATL.@]
275 HRESULT WINAPI AtlModuleRegisterTypeLib(_ATL_MODULEW *pm, LPCOLESTR lpszIndex)
281 TRACE("%p %s\n", pm, debugstr_w(lpszIndex));
286 hRes = AtlModuleLoadTypeLib(pm, lpszIndex, &path, &typelib);
290 hRes = RegisterTypeLib(typelib, path, NULL); /* FIXME: pass help directory */
291 ITypeLib_Release(typelib);
298 /***********************************************************************
299 * AtlModuleRevokeClassObjects [ATL.@]
301 HRESULT WINAPI AtlModuleRevokeClassObjects(_ATL_MODULEW *pm)
307 /***********************************************************************
308 * AtlModuleUnregisterServer [ATL.@]
310 HRESULT WINAPI AtlModuleUnregisterServer(_ATL_MODULEW *pm, const CLSID *clsid)
312 FIXME("%p %s\n", pm, debugstr_guid(clsid));
316 /***********************************************************************
317 * AtlModuleRegisterWndClassInfoA [ATL.@]
319 * See AtlModuleRegisterWndClassInfoW.
321 ATOM WINAPI AtlModuleRegisterWndClassInfoA(_ATL_MODULEA *pm, _ATL_WNDCLASSINFOA *wci, WNDPROC *pProc)
325 FIXME("%p %p %p semi-stub\n", pm, wci, pProc);
332 TRACE("wci->m_wc.lpszClassName = %s\n", wci->m_wc.lpszClassName);
334 if (wci->m_lpszOrigName)
335 FIXME( "subclassing %s not implemented\n", debugstr_a(wci->m_lpszOrigName));
337 if (!wci->m_wc.lpszClassName)
339 snprintf(wci->m_szAutoName, sizeof(wci->m_szAutoName), "ATL%08lx", (UINT_PTR)wci);
340 TRACE("auto-generated class name %s\n", wci->m_szAutoName);
341 wci->m_wc.lpszClassName = wci->m_szAutoName;
344 atom = GetClassInfoExA(pm->m_hInst, wci->m_wc.lpszClassName, &wc);
347 wci->m_wc.hInstance = pm->m_hInst;
348 wci->m_wc.hCursor = LoadCursorA( wci->m_bSystemCursor ? NULL : pm->m_hInst,
349 wci->m_lpszCursorID );
350 atom = RegisterClassExA(&wci->m_wc);
352 wci->pWndProc = wci->m_wc.lpfnWndProc;
356 if (wci->m_lpszOrigName) *pProc = wci->pWndProc;
358 TRACE("returning 0x%04x\n", atom);
362 /***********************************************************************
363 * AtlModuleRegisterWndClassInfoW [ATL.@]
366 * pm [IO] Information about the module registering the window.
367 * wci [IO] Information about the window being registered.
368 * pProc [O] Window procedure of the registered class.
371 * Atom representing the registered class.
374 * Can be called multiple times without error, unlike RegisterClassEx().
376 * If the class name is NULL, then a class with a name of "ATLxxxxxxxx" is
377 * registered, where the 'x's represent a unique value.
380 ATOM WINAPI AtlModuleRegisterWndClassInfoW(_ATL_MODULEW *pm, _ATL_WNDCLASSINFOW *wci, WNDPROC *pProc)
384 FIXME("%p %p %p semi-stub\n", pm, wci, pProc);
391 TRACE("wci->m_wc.lpszClassName = %s\n", debugstr_w(wci->m_wc.lpszClassName));
393 if (wci->m_lpszOrigName)
394 FIXME( "subclassing %s not implemented\n", debugstr_w(wci->m_lpszOrigName));
396 if (!wci->m_wc.lpszClassName)
398 static const WCHAR szFormat[] = {'A','T','L','%','0','8','l','x',0};
399 snprintfW(wci->m_szAutoName, sizeof(wci->m_szAutoName)/sizeof(WCHAR), szFormat, (UINT_PTR)wci);
400 TRACE("auto-generated class name %s\n", debugstr_w(wci->m_szAutoName));
401 wci->m_wc.lpszClassName = wci->m_szAutoName;
404 atom = GetClassInfoExW(pm->m_hInst, wci->m_wc.lpszClassName, &wc);
407 wci->m_wc.hInstance = pm->m_hInst;
408 wci->m_wc.hCursor = LoadCursorW( wci->m_bSystemCursor ? NULL : pm->m_hInst,
409 wci->m_lpszCursorID );
410 atom = RegisterClassExW(&wci->m_wc);
412 wci->pWndProc = wci->m_wc.lpfnWndProc;
416 if (wci->m_lpszOrigName) *pProc = wci->pWndProc;
418 TRACE("returning 0x%04x\n", atom);
422 /***********************************************************************
423 * AtlModuleAddCreateWndData [ATL.@]
425 void WINAPI AtlModuleAddCreateWndData(_ATL_MODULEW *pM, _AtlCreateWndData *pData, void* pvObject)
427 TRACE("(%p, %p, %p)\n", pM, pData, pvObject);
429 pData->m_pThis = pvObject;
430 pData->m_dwThreadID = GetCurrentThreadId();
431 pData->m_pNext = pM->m_pCreateWndList;
432 pM->m_pCreateWndList = pData;
435 /***********************************************************************
436 * AtlModuleExtractCreateWndData [ATL.@]
438 * NOTE: I failed to find any good description of this function.
439 * Tests show that this function extracts one of _AtlCreateWndData
440 * records from the current thread from a list
443 void* WINAPI AtlModuleExtractCreateWndData(_ATL_MODULEW *pM)
445 _AtlCreateWndData **ppData;
449 for(ppData = &pM->m_pCreateWndList; *ppData!=NULL; ppData = &(*ppData)->m_pNext)
451 if ((*ppData)->m_dwThreadID == GetCurrentThreadId())
453 _AtlCreateWndData *pData = *ppData;
454 *ppData = pData->m_pNext;
455 return pData->m_pThis;
461 /***********************************************************************
462 * AtlGetVersion [ATL.@]
464 DWORD WINAPI AtlGetVersion(void *pReserved)