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
31 #include "wine/debug.h"
39 #include "wine/unicode.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(atl);
45 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
47 TRACE("(0x%p, %d, %p)\n",hinstDLL,fdwReason,lpvReserved);
49 if (fdwReason == DLL_PROCESS_ATTACH) {
50 DisableThreadLibraryCalls(hinstDLL);
56 #define ATLVer1Size 100
58 HRESULT WINAPI AtlModuleInit(_ATL_MODULEW* pM, _ATL_OBJMAP_ENTRYW* p, HINSTANCE h)
63 FIXME("SEMI-STUB (%p %p %p)\n",pM,p,h);
66 if (size != sizeof(_ATL_MODULEW) && size != ATLVer1Size)
68 FIXME("Unknown structure version (size %i)\n",size);
72 memset(pM,0,pM->cbSize);
75 pM->m_hInstResource = h;
76 pM->m_hInstTypeLib = h;
78 pM->m_hHeap = GetProcessHeap();
80 InitializeCriticalSection(&pM->u.m_csTypeInfoHolder);
81 InitializeCriticalSection(&pM->m_csWindowCreate);
82 InitializeCriticalSection(&pM->m_csObjMap);
86 if (pM->m_pObjMap != NULL && size > ATLVer1Size)
88 while (pM->m_pObjMap[i].pclsid != NULL)
90 TRACE("Initializing object %i %p\n",i,p[i].pfnObjectMain);
91 if (p[i].pfnObjectMain)
92 p[i].pfnObjectMain(TRUE);
100 HRESULT WINAPI AtlModuleLoadTypeLib(_ATL_MODULEW *pM, LPCOLESTR lpszIndex,
101 BSTR *pbstrPath, ITypeLib **ppTypeLib)
104 OLECHAR path[MAX_PATH+8]; /* leave some space for index */
106 TRACE("(%p, %s, %p, %p)\n", pM, debugstr_w(lpszIndex), pbstrPath, ppTypeLib);
111 GetModuleFileNameW(pM->m_hInstTypeLib, path, MAX_PATH);
113 lstrcatW(path, lpszIndex);
115 hRes = LoadTypeLib(path, ppTypeLib);
119 *pbstrPath = SysAllocString(path);
124 HRESULT WINAPI AtlModuleTerm(_ATL_MODULEW* pM)
126 _ATL_TERMFUNC_ELEM *iter = pM->m_pTermFuncs, *tmp;
131 iter->pFunc(iter->dw);
134 HeapFree(GetProcessHeap(), 0, tmp);
137 HeapFree(GetProcessHeap(), 0, pM);
142 HRESULT WINAPI AtlModuleAddTermFunc(_ATL_MODULEW *pM, _ATL_TERMFUNC *pFunc, DWORD_PTR dw)
144 _ATL_TERMFUNC_ELEM *termfunc_elem;
146 TRACE("(%p %p %ld)\n", pM, pFunc, dw);
148 termfunc_elem = HeapAlloc(GetProcessHeap(), 0, sizeof(_ATL_TERMFUNC_ELEM));
149 termfunc_elem->pFunc = pFunc;
150 termfunc_elem->dw = dw;
151 termfunc_elem->pNext = pM->m_pTermFuncs;
153 pM->m_pTermFuncs = termfunc_elem;
158 HRESULT WINAPI AtlModuleRegisterClassObjects(_ATL_MODULEW *pM, DWORD dwClsContext,
164 TRACE("(%p %i %i)\n",pM, dwClsContext, dwFlags);
169 while(pM->m_pObjMap[i].pclsid != NULL)
172 _ATL_OBJMAP_ENTRYW *obj = &(pM->m_pObjMap[i]);
175 TRACE("Registering object %i\n",i);
176 if (obj->pfnGetClassObject)
178 rc = obj->pfnGetClassObject(obj->pfnCreateInstance, &IID_IUnknown,
182 CoRegisterClassObject(obj->pclsid, pUnknown, dwClsContext,
183 dwFlags, &obj->dwRegister);
185 IUnknown_Release(pUnknown);
194 HRESULT WINAPI AtlModuleUnregisterServerEx(_ATL_MODULEW* pM, BOOL bUnRegTypeLib, const CLSID* pCLSID)
196 FIXME("(%p, %i, %p) stub\n", pM, bUnRegTypeLib, pCLSID);
201 IUnknown* WINAPI AtlComPtrAssign(IUnknown** pp, IUnknown *p)
203 TRACE("(%p %p)\n", pp, p);
205 if (p) IUnknown_AddRef(p);
206 if (*pp) IUnknown_Release(*pp);
212 HRESULT WINAPI AtlInternalQueryInterface(LPVOID this, const _ATL_INTMAP_ENTRY* pEntries, REFIID iid, LPVOID* ppvObject)
215 HRESULT rc = E_NOINTERFACE;
216 TRACE("(%p, %p, %p, %p)\n",this, pEntries, iid, ppvObject);
218 if (IsEqualGUID(iid,&IID_IUnknown))
220 TRACE("Returning IUnknown\n");
222 IUnknown_AddRef((IUnknown*)this);
226 while (pEntries[i].pFunc != 0)
228 TRACE("Trying entry %i (%p %i %p)\n",i,pEntries[i].piid,
229 pEntries[i].dw, pEntries[i].pFunc);
231 if (pEntries[i].piid && IsEqualGUID(iid,pEntries[i].piid))
234 if (pEntries[i].pFunc == (_ATL_CREATORARGFUNC*)1)
237 *ppvObject = ((LPSTR)this+pEntries[i].dw);
238 IUnknown_AddRef((IUnknown*)this);
244 rc = pEntries[i].pFunc(this, iid, ppvObject,0);
250 TRACE("Done returning (0x%x)\n",rc);
254 /***********************************************************************
255 * AtlModuleRegisterServer [ATL.@]
258 HRESULT WINAPI AtlModuleRegisterServer(_ATL_MODULEW* pM, BOOL bRegTypeLib, const CLSID* clsid)
260 FIXME("%p %d %s\n", pM, bRegTypeLib, debugstr_guid(clsid));
264 /***********************************************************************
267 HRESULT WINAPI AtlAdvise(IUnknown *pUnkCP, IUnknown *pUnk, const IID *iid, LPDWORD pdw)
269 FIXME("%p %p %p %p\n", pUnkCP, pUnk, iid, pdw);
273 /***********************************************************************
274 * AtlUnadvise [ATL.@]
276 HRESULT WINAPI AtlUnadvise(IUnknown *pUnkCP, const IID *iid, DWORD dw)
278 FIXME("%p %p %d\n", pUnkCP, iid, dw);
282 /***********************************************************************
283 * AtlFreeMarshalStream [ATL.@]
285 HRESULT WINAPI AtlFreeMarshalStream(IStream *stm)
291 /***********************************************************************
292 * AtlMarshalPtrInProc [ATL.@]
294 HRESULT WINAPI AtlMarshalPtrInProc(IUnknown *pUnk, const IID *iid, IStream **pstm)
296 FIXME("%p %p %p\n", pUnk, iid, pstm);
300 /***********************************************************************
301 * AtlUnmarshalPtr [ATL.@]
303 HRESULT WINAPI AtlUnmarshalPtr(IStream *stm, const IID *iid, IUnknown **ppUnk)
305 FIXME("%p %p %p\n", stm, iid, ppUnk);
309 /***********************************************************************
310 * AtlModuleGetClassObject [ATL.@]
312 HRESULT WINAPI AtlModuleGetClassObject(_ATL_MODULEW *pm, REFCLSID rclsid,
313 REFIID riid, LPVOID *ppv)
317 TRACE("%p %s %s %p\n", pm, debugstr_guid(rclsid), debugstr_guid(riid), ppv);
322 for (i = 0; pm->m_pObjMap[i].pclsid != NULL; i++)
324 if (IsEqualCLSID(pm->m_pObjMap[i].pclsid, rclsid))
326 _ATL_OBJMAP_ENTRYW *obj = &pm->m_pObjMap[i];
328 TRACE("found object %i\n", i);
329 if (obj->pfnGetClassObject)
330 return obj->pfnGetClassObject(obj->pfnCreateInstance, riid, ppv);
334 WARN("no class object found for %s\n", debugstr_guid(rclsid));
339 /***********************************************************************
340 * AtlModuleGetClassObject [ATL.@]
342 HRESULT WINAPI AtlModuleRegisterTypeLib(_ATL_MODULEW *pm, LPCOLESTR lpszIndex)
344 FIXME("%p %s\n", pm, debugstr_w(lpszIndex));
348 /***********************************************************************
349 * AtlModuleRevokeClassObjects [ATL.@]
351 HRESULT WINAPI AtlModuleRevokeClassObjects(_ATL_MODULEW *pm)
357 /***********************************************************************
358 * AtlModuleUnregisterServer [ATL.@]
360 HRESULT WINAPI AtlModuleUnregisterServer(_ATL_MODULEW *pm, const CLSID *clsid)
362 FIXME("%p %s\n", pm, debugstr_guid(clsid));
366 /***********************************************************************
367 * AtlModuleRegisterWndClassInfoW [ATL.@]
370 * pm [IO] Information about the module registering the window.
371 * wci [IO] Information about the window being registered.
372 * pProc [O] Window procedure of the registered class.
375 * Atom representing the registered class.
378 * Can be called multiple times without error, unlike RegisterClassEx().
380 * If the class name is NULL then it a class with a name of "ATLxxxxxxxx" is
381 * registered, where the x's represent an unique value.
384 ATOM WINAPI AtlModuleRegisterWndClassInfoW(_ATL_MODULEW *pm, _ATL_WNDCLASSINFOW *wci, WNDPROC *pProc)
388 FIXME("%p %p %p semi-stub\n", pm, wci, pProc);
395 TRACE("wci->m_wc.lpszClassName = %s\n", debugstr_w(wci->m_wc.lpszClassName));
397 if (!wci->m_wc.lpszClassName)
399 static const WCHAR szFormat[] = {'A','T','L','%','0','8','x',0};
400 sprintfW(wci->m_szAutoName, szFormat, (UINT)(UINT_PTR)wci);
401 TRACE("auto-generated class name %s\n", debugstr_w(wci->m_szAutoName));
402 wci->m_wc.lpszClassName = wci->m_szAutoName;
405 atom = GetClassInfoExW(pm->m_hInst, wci->m_wc.lpszClassName, &wc);
407 atom = RegisterClassExW(&wci->m_wc);
409 wci->pWndProc = wci->m_wc.lpfnWndProc;
412 *pProc = wci->pWndProc;
414 TRACE("returning 0x%04x\n", atom);
418 void WINAPI AtlHiMetricToPixel(const SIZEL* lpHiMetric, SIZEL* lpPix)
420 HDC dc = GetDC(NULL);
421 lpPix->cx = lpHiMetric->cx * GetDeviceCaps( dc, LOGPIXELSX ) / 100;
422 lpPix->cy = lpHiMetric->cy * GetDeviceCaps( dc, LOGPIXELSY ) / 100;
423 ReleaseDC( NULL, dc );
426 void WINAPI AtlPixelToHiMetric(const SIZEL* lpPix, SIZEL* lpHiMetric)
428 HDC dc = GetDC(NULL);
429 lpHiMetric->cx = 100 * lpPix->cx / GetDeviceCaps( dc, LOGPIXELSX );
430 lpHiMetric->cy = 100 * lpPix->cy / GetDeviceCaps( dc, LOGPIXELSY );
431 ReleaseDC( NULL, dc );
434 /***********************************************************************
435 * AtlModuleAddCreateWndData [ATL.@]
437 void WINAPI AtlModuleAddCreateWndData(_ATL_MODULEW *pM, _AtlCreateWndData *pData, LPVOID pvObject)
439 TRACE("(%p, %p, %p)\n", pM, pData, pvObject);
441 pData->m_pThis = pvObject;
442 pData->m_dwThreadID = GetCurrentThreadId();
443 pData->m_pNext = pM->m_pCreateWndList;
444 pM->m_pCreateWndList = pData;
447 /***********************************************************************
448 * AtlModuleExtractCreateWndData [ATL.@]
450 * NOTE: I failed to find any good description of this function.
451 * Tests show that this function extracts one of _AtlCreateWndData
452 * records from the current thread from a list
455 LPVOID WINAPI AtlModuleExtractCreateWndData(_ATL_MODULEW *pM)
457 _AtlCreateWndData **ppData;
461 for(ppData = &pM->m_pCreateWndList; *ppData!=NULL; ppData = &(*ppData)->m_pNext)
463 if ((*ppData)->m_dwThreadID == GetCurrentThreadId())
465 _AtlCreateWndData *pData = *ppData;
466 *ppData = pData->m_pNext;
467 return pData->m_pThis;