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
)
115 OLECHAR path
[MAX_PATH
+8]; /* leave some space for index */
117 TRACE("(%p, %s, %p, %p)\n", pM
, debugstr_w(lpszIndex
), pbstrPath
, ppTypeLib
);
122 GetModuleFileNameW(pM
->m_hInstTypeLib
, path
, MAX_PATH
);
124 lstrcatW(path
, lpszIndex
);
126 hRes
= LoadTypeLib(path
, ppTypeLib
);
130 *pbstrPath
= SysAllocString(path
);
135 HRESULT WINAPI
AtlModuleTerm(_ATL_MODULEW
* pM
)
137 _ATL_TERMFUNC_ELEM
*iter
= pM
->m_pTermFuncs
, *tmp
;
142 iter
->pFunc(iter
->dw
);
145 HeapFree(GetProcessHeap(), 0, tmp
);
148 HeapFree(GetProcessHeap(), 0, pM
);
153 HRESULT WINAPI
AtlModuleAddTermFunc(_ATL_MODULEW
*pM
, _ATL_TERMFUNC
*pFunc
, DWORD_PTR dw
)
155 _ATL_TERMFUNC_ELEM
*termfunc_elem
;
157 TRACE("(%p %p %ld)\n", pM
, pFunc
, dw
);
159 termfunc_elem
= HeapAlloc(GetProcessHeap(), 0, sizeof(_ATL_TERMFUNC_ELEM
));
160 termfunc_elem
->pFunc
= pFunc
;
161 termfunc_elem
->dw
= dw
;
162 termfunc_elem
->pNext
= pM
->m_pTermFuncs
;
164 pM
->m_pTermFuncs
= termfunc_elem
;
169 HRESULT WINAPI
AtlModuleRegisterClassObjects(_ATL_MODULEW
*pM
, DWORD dwClsContext
,
172 _ATL_OBJMAP_ENTRYW_V1
*obj
;
175 TRACE("(%p %i %i)\n",pM
, dwClsContext
, dwFlags
);
180 while ((obj
= get_objmap_entry( pM
, i
++ )))
185 TRACE("Registering object %i\n",i
);
186 if (obj
->pfnGetClassObject
)
188 rc
= obj
->pfnGetClassObject(obj
->pfnCreateInstance
, &IID_IUnknown
,
192 rc
= CoRegisterClassObject(obj
->pclsid
, pUnknown
, dwClsContext
,
193 dwFlags
, &obj
->dwRegister
);
196 WARN("Failed to register object %i: 0x%08x\n", i
, rc
);
199 IUnknown_Release(pUnknown
);
207 HRESULT WINAPI
AtlModuleUnregisterServerEx(_ATL_MODULEW
* pM
, BOOL bUnRegTypeLib
, const CLSID
* pCLSID
)
209 FIXME("(%p, %i, %p) stub\n", pM
, bUnRegTypeLib
, pCLSID
);
213 /***********************************************************************
214 * AtlModuleRegisterServer [ATL.@]
217 HRESULT WINAPI
AtlModuleRegisterServer(_ATL_MODULEW
* pM
, BOOL bRegTypeLib
, const CLSID
* clsid
)
219 const _ATL_OBJMAP_ENTRYW_V1
*obj
;
223 TRACE("%p %d %s\n", pM
, bRegTypeLib
, debugstr_guid(clsid
));
228 for (i
= 0; (obj
= get_objmap_entry( pM
, i
)) != NULL
; i
++) /* register CLSIDs */
230 if (!clsid
|| IsEqualCLSID(obj
->pclsid
, clsid
))
232 TRACE("Registering clsid %s\n", debugstr_guid(obj
->pclsid
));
233 hRes
= obj
->pfnUpdateRegistry(TRUE
); /* register */
241 hRes
= AtlModuleRegisterTypeLib(pM
, NULL
);
249 /***********************************************************************
250 * AtlModuleGetClassObject [ATL.@]
252 HRESULT WINAPI
AtlModuleGetClassObject(_ATL_MODULEW
*pm
, REFCLSID rclsid
,
253 REFIID riid
, LPVOID
*ppv
)
255 _ATL_OBJMAP_ENTRYW_V1
*obj
;
257 HRESULT hres
= CLASS_E_CLASSNOTAVAILABLE
;
259 TRACE("%p %s %s %p\n", pm
, debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
264 for (i
= 0; (obj
= get_objmap_entry( pm
, i
)) != NULL
; i
++)
266 if (IsEqualCLSID(obj
->pclsid
, rclsid
))
268 TRACE("found object %i\n", i
);
269 if (obj
->pfnGetClassObject
)
272 hres
= obj
->pfnGetClassObject(obj
->pfnCreateInstance
,
276 hres
= IUnknown_QueryInterface(obj
->pCF
, riid
, ppv
);
282 WARN("no class object found for %s\n", debugstr_guid(rclsid
));
287 /***********************************************************************
288 * AtlModuleGetClassObject [ATL.@]
290 HRESULT WINAPI
AtlModuleRegisterTypeLib(_ATL_MODULEW
*pm
, LPCOLESTR lpszIndex
)
296 TRACE("%p %s\n", pm
, debugstr_w(lpszIndex
));
301 hRes
= AtlModuleLoadTypeLib(pm
, lpszIndex
, &path
, &typelib
);
305 hRes
= RegisterTypeLib(typelib
, path
, NULL
); /* FIXME: pass help directory */
306 ITypeLib_Release(typelib
);
313 /***********************************************************************
314 * AtlModuleRevokeClassObjects [ATL.@]
316 HRESULT WINAPI
AtlModuleRevokeClassObjects(_ATL_MODULEW
*pm
)
322 /***********************************************************************
323 * AtlModuleUnregisterServer [ATL.@]
325 HRESULT WINAPI
AtlModuleUnregisterServer(_ATL_MODULEW
*pm
, const CLSID
*clsid
)
327 FIXME("%p %s\n", pm
, debugstr_guid(clsid
));
331 /***********************************************************************
332 * AtlModuleRegisterWndClassInfoA [ATL.@]
334 * See AtlModuleRegisterWndClassInfoW.
336 ATOM WINAPI
AtlModuleRegisterWndClassInfoA(_ATL_MODULEA
*pm
, _ATL_WNDCLASSINFOA
*wci
, WNDPROC
*pProc
)
340 FIXME("%p %p %p semi-stub\n", pm
, wci
, pProc
);
347 TRACE("wci->m_wc.lpszClassName = %s\n", wci
->m_wc
.lpszClassName
);
349 if (wci
->m_lpszOrigName
)
350 FIXME( "subclassing %s not implemented\n", debugstr_a(wci
->m_lpszOrigName
));
352 if (!wci
->m_wc
.lpszClassName
)
354 snprintf(wci
->m_szAutoName
, sizeof(wci
->m_szAutoName
), "ATL%08lx", (UINT_PTR
)wci
);
355 TRACE("auto-generated class name %s\n", wci
->m_szAutoName
);
356 wci
->m_wc
.lpszClassName
= wci
->m_szAutoName
;
359 atom
= GetClassInfoExA(pm
->m_hInst
, wci
->m_wc
.lpszClassName
, &wc
);
362 wci
->m_wc
.hInstance
= pm
->m_hInst
;
363 wci
->m_wc
.hCursor
= LoadCursorA( wci
->m_bSystemCursor
? NULL
: pm
->m_hInst
,
364 wci
->m_lpszCursorID
);
365 atom
= RegisterClassExA(&wci
->m_wc
);
367 wci
->pWndProc
= wci
->m_wc
.lpfnWndProc
;
371 if (wci
->m_lpszOrigName
) *pProc
= wci
->pWndProc
;
373 TRACE("returning 0x%04x\n", atom
);
377 /***********************************************************************
378 * AtlModuleRegisterWndClassInfoW [ATL.@]
381 * pm [IO] Information about the module registering the window.
382 * wci [IO] Information about the window being registered.
383 * pProc [O] Window procedure of the registered class.
386 * Atom representing the registered class.
389 * Can be called multiple times without error, unlike RegisterClassEx().
391 * If the class name is NULL, then a class with a name of "ATLxxxxxxxx" is
392 * registered, where the 'x's represent a unique value.
395 ATOM WINAPI
AtlModuleRegisterWndClassInfoW(_ATL_MODULEW
*pm
, _ATL_WNDCLASSINFOW
*wci
, WNDPROC
*pProc
)
399 FIXME("%p %p %p semi-stub\n", pm
, wci
, pProc
);
406 TRACE("wci->m_wc.lpszClassName = %s\n", debugstr_w(wci
->m_wc
.lpszClassName
));
408 if (wci
->m_lpszOrigName
)
409 FIXME( "subclassing %s not implemented\n", debugstr_w(wci
->m_lpszOrigName
));
411 if (!wci
->m_wc
.lpszClassName
)
413 static const WCHAR szFormat
[] = {'A','T','L','%','0','8','l','x',0};
414 snprintfW(wci
->m_szAutoName
, sizeof(wci
->m_szAutoName
)/sizeof(WCHAR
), szFormat
, (UINT_PTR
)wci
);
415 TRACE("auto-generated class name %s\n", debugstr_w(wci
->m_szAutoName
));
416 wci
->m_wc
.lpszClassName
= wci
->m_szAutoName
;
419 atom
= GetClassInfoExW(pm
->m_hInst
, wci
->m_wc
.lpszClassName
, &wc
);
422 wci
->m_wc
.hInstance
= pm
->m_hInst
;
423 wci
->m_wc
.hCursor
= LoadCursorW( wci
->m_bSystemCursor
? NULL
: pm
->m_hInst
,
424 wci
->m_lpszCursorID
);
425 atom
= RegisterClassExW(&wci
->m_wc
);
427 wci
->pWndProc
= wci
->m_wc
.lpfnWndProc
;
431 if (wci
->m_lpszOrigName
) *pProc
= wci
->pWndProc
;
433 TRACE("returning 0x%04x\n", atom
);
437 /***********************************************************************
438 * AtlModuleAddCreateWndData [ATL.@]
440 void WINAPI
AtlModuleAddCreateWndData(_ATL_MODULEW
*pM
, _AtlCreateWndData
*pData
, void* pvObject
)
442 TRACE("(%p, %p, %p)\n", pM
, pData
, pvObject
);
444 pData
->m_pThis
= pvObject
;
445 pData
->m_dwThreadID
= GetCurrentThreadId();
446 pData
->m_pNext
= pM
->m_pCreateWndList
;
447 pM
->m_pCreateWndList
= pData
;
450 /***********************************************************************
451 * AtlModuleExtractCreateWndData [ATL.@]
453 * NOTE: I failed to find any good description of this function.
454 * Tests show that this function extracts one of _AtlCreateWndData
455 * records from the current thread from a list
458 void* WINAPI
AtlModuleExtractCreateWndData(_ATL_MODULEW
*pM
)
460 _AtlCreateWndData
**ppData
;
464 for(ppData
= &pM
->m_pCreateWndList
; *ppData
!=NULL
; ppData
= &(*ppData
)->m_pNext
)
466 if ((*ppData
)->m_dwThreadID
== GetCurrentThreadId())
468 _AtlCreateWndData
*pData
= *ppData
;
469 *ppData
= pData
->m_pNext
;
470 return pData
->m_pThis
;
476 /***********************************************************************
477 * AtlGetVersion [ATL.@]
479 DWORD WINAPI
AtlGetVersion(void *pReserved
)