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_MODULEA* pM, _ATL_OBJMAP_ENTRYA* p, HINSTANCE h)
63 FIXME("SEMI-STUB (%p %p %p)\n",pM,p,h);
66 if (size != sizeof(_ATL_MODULEA) && 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_MODULEA *pM, LPCOLESTR lpszIndex,
101 BSTR *pbstrPath, ITypeLib **ppTypeLib)
103 FIXME("(%p, %s, %p, %p): stub\n", pM, debugstr_w(lpszIndex), pbstrPath, ppTypeLib);
107 HRESULT WINAPI AtlModuleTerm(_ATL_MODULEA* pM)
109 _ATL_TERMFUNC_ELEM *iter = pM->m_pTermFuncs, *tmp;
114 iter->pFunc(iter->dw);
117 HeapFree(GetProcessHeap(), 0, tmp);
120 HeapFree(GetProcessHeap(), 0, pM);
125 HRESULT WINAPI AtlModuleAddTermFunc(_ATL_MODULEW *pM, _ATL_TERMFUNC *pFunc, DWORD_PTR dw)
127 _ATL_TERMFUNC_ELEM *termfunc_elem;
129 TRACE("(%p %p %ld)\n", pM, pFunc, dw);
131 termfunc_elem = HeapAlloc(GetProcessHeap(), 0, sizeof(_ATL_TERMFUNC_ELEM));
132 termfunc_elem->pFunc = pFunc;
133 termfunc_elem->dw = dw;
134 termfunc_elem->pNext = pM->m_pTermFuncs;
136 pM->m_pTermFuncs = termfunc_elem;
141 HRESULT WINAPI AtlModuleRegisterClassObjects(_ATL_MODULEA *pM, DWORD dwClsContext,
147 TRACE("(%p %i %i)\n",pM, dwClsContext, dwFlags);
152 while(pM->m_pObjMap[i].pclsid != NULL)
155 _ATL_OBJMAP_ENTRYA *obj = &(pM->m_pObjMap[i]);
158 TRACE("Registering object %i\n",i);
159 if (obj->pfnGetClassObject)
161 rc = obj->pfnGetClassObject(obj->pfnCreateInstance, &IID_IUnknown,
165 CoRegisterClassObject(obj->pclsid, pUnknown, dwClsContext,
166 dwFlags, &obj->dwRegister);
168 IUnknown_Release(pUnknown);
177 HRESULT WINAPI AtlModuleUnregisterServerEx(_ATL_MODULEA* pM, BOOL bUnRegTypeLib, const CLSID* pCLSID)
179 FIXME("(%p, %i, %p) stub\n", pM, bUnRegTypeLib, pCLSID);
183 /***********************************************************************
184 * AtlAxWinInit [ATL.@]
185 * Initializes the control-hosting code: registering the AtlAxWin7 and AtlAxWinLic7 window
186 * classes and some messages.
192 BOOL WINAPI AtlAxWinInit(void)
194 FIXME("Try use native atl.dll if possible\n");
199 IUnknown* WINAPI AtlComPtrAssign(IUnknown** pp, IUnknown *p)
201 TRACE("(%p %p)\n", pp, p);
203 if (p) IUnknown_AddRef(p);
204 if (*pp) IUnknown_Release(*pp);
210 HRESULT WINAPI AtlInternalQueryInterface(LPVOID this, const _ATL_INTMAP_ENTRY* pEntries, REFIID iid, LPVOID* ppvObject)
213 HRESULT rc = E_NOINTERFACE;
214 TRACE("(%p, %p, %p, %p)\n",this, pEntries, iid, ppvObject);
216 if (IsEqualGUID(iid,&IID_IUnknown))
218 TRACE("Returning IUnknown\n");
220 IUnknown_AddRef((IUnknown*)this);
224 while (pEntries[i].pFunc != 0)
226 TRACE("Trying entry %i (%p %i %p)\n",i,pEntries[i].piid,
227 pEntries[i].dw, pEntries[i].pFunc);
229 if (pEntries[i].piid && IsEqualGUID(iid,pEntries[i].piid))
232 if (pEntries[i].pFunc == (_ATL_CREATORARGFUNC*)1)
235 *ppvObject = ((LPSTR)this+pEntries[i].dw);
236 IUnknown_AddRef((IUnknown*)this);
242 rc = pEntries[i].pFunc(this, iid, ppvObject,0);
248 TRACE("Done returning (0x%x)\n",rc);
252 /***********************************************************************
253 * AtlModuleRegisterServer [ATL.@]
256 HRESULT WINAPI AtlModuleRegisterServer(_ATL_MODULEW* pM, BOOL bRegTypeLib, const CLSID* clsid)
258 FIXME("%p %d %s\n", pM, bRegTypeLib, debugstr_guid(clsid));
262 /***********************************************************************
265 HRESULT WINAPI AtlAdvise(IUnknown *pUnkCP, IUnknown *pUnk, const IID *iid, LPDWORD pdw)
267 FIXME("%p %p %p %p\n", pUnkCP, pUnk, iid, pdw);
271 /***********************************************************************
272 * AtlUnadvise [ATL.@]
274 HRESULT WINAPI AtlUnadvise(IUnknown *pUnkCP, const IID *iid, DWORD dw)
276 FIXME("%p %p %d\n", pUnkCP, iid, dw);
280 /***********************************************************************
281 * AtlFreeMarshalStream [ATL.@]
283 HRESULT WINAPI AtlFreeMarshalStream(IStream *stm)
289 /***********************************************************************
290 * AtlMarshalPtrInProc [ATL.@]
292 HRESULT WINAPI AtlMarshalPtrInProc(IUnknown *pUnk, const IID *iid, IStream **pstm)
294 FIXME("%p %p %p\n", pUnk, iid, pstm);
298 /***********************************************************************
299 * AtlUnmarshalPtr [ATL.@]
301 HRESULT WINAPI AtlUnmarshalPtr(IStream *stm, const IID *iid, IUnknown **ppUnk)
303 FIXME("%p %p %p\n", stm, iid, ppUnk);
307 /***********************************************************************
308 * AtlModuleGetClassObject [ATL.@]
310 HRESULT WINAPI AtlModuleGetClassObject(_ATL_MODULEW *pm, REFCLSID rclsid,
311 REFIID riid, LPVOID *ppv)
315 TRACE("%p %s %s %p\n", pm, debugstr_guid(rclsid), debugstr_guid(riid), ppv);
320 for (i = 0; pm->m_pObjMap[i].pclsid != NULL; i++)
322 if (IsEqualCLSID(pm->m_pObjMap[i].pclsid, rclsid))
324 _ATL_OBJMAP_ENTRYW *obj = &pm->m_pObjMap[i];
326 TRACE("found object %i\n", i);
327 if (obj->pfnGetClassObject)
328 return obj->pfnGetClassObject(obj->pfnCreateInstance, riid, ppv);
332 WARN("no class object found for %s\n", debugstr_guid(rclsid));
337 /***********************************************************************
338 * AtlModuleGetClassObject [ATL.@]
340 HRESULT WINAPI AtlModuleRegisterTypeLib(_ATL_MODULEW *pm, LPCOLESTR lpszIndex)
342 FIXME("%p %s\n", pm, debugstr_w(lpszIndex));
346 /***********************************************************************
347 * AtlModuleRevokeClassObjects [ATL.@]
349 HRESULT WINAPI AtlModuleRevokeClassObjects(_ATL_MODULEW *pm)
355 /***********************************************************************
356 * AtlModuleUnregisterServer [ATL.@]
358 HRESULT WINAPI AtlModuleUnregisterServer(_ATL_MODULEW *pm, const CLSID *clsid)
360 FIXME("%p %s\n", pm, debugstr_guid(clsid));
364 /***********************************************************************
365 * AtlAxCreateControl [ATL.@]
367 HRESULT WINAPI AtlAxCreateControl(LPCOLESTR lpszName, HWND hWnd,
368 IStream *pStream, IUnknown **ppUnkContainer)
370 FIXME("%s %p %p %p)\n", debugstr_w(lpszName), hWnd, pStream, ppUnkContainer);
374 /***********************************************************************
375 * AtlModuleRegisterWndClassInfoW [ATL.@]
378 * pm [IO] Information about the module registering the window.
379 * wci [IO] Information about the window being registered.
380 * pProc [O] Window procedure of the registered class.
383 * Atom representing the registered class.
386 * Can be called multiple times without error, unlike RegisterClassEx().
388 * If the class name is NULL then it a class with a name of "ATLxxxxxxxx" is
389 * registered, where the x's represent an unique value.
392 ATOM WINAPI AtlModuleRegisterWndClassInfoW(_ATL_MODULEW *pm, _ATL_WNDCLASSINFOW *wci, WNDPROC *pProc)
396 FIXME("%p %p %p semi-stub\n", pm, wci, pProc);
403 TRACE("wci->m_wc.lpszClassName = %s\n", debugstr_w(wci->m_wc.lpszClassName));
405 if (!wci->m_wc.lpszClassName)
407 static const WCHAR szFormat[] = {'A','T','L','%','0','8','x',0};
408 sprintfW(wci->m_szAutoName, szFormat, (UINT)(UINT_PTR)wci);
409 TRACE("auto-generated class name %s\n", debugstr_w(wci->m_szAutoName));
410 wci->m_wc.lpszClassName = wci->m_szAutoName;
413 atom = GetClassInfoExW(pm->m_hInst, wci->m_wc.lpszClassName, &wc);
415 atom = RegisterClassExW(&wci->m_wc);
417 wci->pWndProc = wci->m_wc.lpfnWndProc;
420 *pProc = wci->pWndProc;
422 TRACE("returning 0x%04x\n", atom);
426 void WINAPI AtlHiMetricToPixel(const SIZEL* lpHiMetric, SIZEL* lpPix)
428 HDC dc = GetDC(NULL);
429 lpPix->cx = lpHiMetric->cx * GetDeviceCaps( dc, LOGPIXELSX ) / 100;
430 lpPix->cy = lpHiMetric->cy * GetDeviceCaps( dc, LOGPIXELSY ) / 100;
431 ReleaseDC( NULL, dc );
434 void WINAPI AtlPixelToHiMetric(const SIZEL* lpPix, SIZEL* lpHiMetric)
436 HDC dc = GetDC(NULL);
437 lpHiMetric->cx = 100 * lpPix->cx / GetDeviceCaps( dc, LOGPIXELSX );
438 lpHiMetric->cy = 100 * lpPix->cy / GetDeviceCaps( dc, LOGPIXELSY );
439 ReleaseDC( NULL, dc );