ntdll: More compatible exception information for protection faults.
[wine/multimedia.git] / dlls / atl / atl_main.c
blobbcf25f04e480a0ed03aeefd7b9b282377e9012c5
1 /*
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winerror.h"
29 #include "winuser.h"
30 #include "wine/debug.h"
31 #include "objbase.h"
32 #include "objidl.h"
33 #include "ole2.h"
34 #include "atlbase.h"
35 #include "atliface.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(atl);
39 HINSTANCE hInst;
41 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
43 TRACE("(0x%p, %ld, %p)\n",hinstDLL,fdwReason,lpvReserved);
45 if (fdwReason == DLL_PROCESS_ATTACH) {
46 DisableThreadLibraryCalls(hinstDLL);
47 hInst = hinstDLL;
49 return TRUE;
52 #define ATLVer1Size 100
54 HRESULT WINAPI AtlModuleInit(_ATL_MODULEA* pM, _ATL_OBJMAP_ENTRYA* p, HINSTANCE h)
56 INT i;
57 UINT size;
59 FIXME("SEMI-STUB (%p %p %p)\n",pM,p,h);
61 size = pM->cbSize;
62 if (size != sizeof(_ATL_MODULEA) && size != ATLVer1Size)
64 FIXME("Unknown structure version (size %i)\n",size);
65 return E_INVALIDARG;
68 memset(pM,0,pM->cbSize);
69 pM->cbSize = size;
70 pM->m_hInst = h;
71 pM->m_hInstResource = h;
72 pM->m_hInstTypeLib = h;
73 pM->m_pObjMap = p;
74 pM->m_hHeap = GetProcessHeap();
76 /* call mains */
77 i = 0;
78 if (pM->m_pObjMap != NULL && size > ATLVer1Size)
80 while (pM->m_pObjMap[i].pclsid != NULL)
82 TRACE("Initializing object %i %p\n",i,p[i].pfnObjectMain);
83 if (p[i].pfnObjectMain)
84 p[i].pfnObjectMain(TRUE);
85 i++;
89 return S_OK;
92 HRESULT WINAPI AtlModuleTerm(_ATL_MODULEA* pM)
94 _ATL_TERMFUNC_ELEM *iter = pM->m_pTermFuncs, *tmp;
96 TRACE("(%p)\n", pM);
98 while(iter) {
99 iter->pFunc(iter->dw);
100 tmp = iter;
101 iter = iter->pNext;
102 HeapFree(GetProcessHeap(), 0, tmp);
105 HeapFree(GetProcessHeap(), 0, pM);
107 return S_OK;
110 HRESULT WINAPI AtlModuleAddTermFunc(_ATL_MODULEW *pM, _ATL_TERMFUNC *pFunc, DWORD_PTR dw)
112 _ATL_TERMFUNC_ELEM *termfunc_elem;
114 TRACE("(%p %p %ld)\n", pM, pFunc, dw);
116 termfunc_elem = HeapAlloc(GetProcessHeap(), 0, sizeof(_ATL_TERMFUNC_ELEM));
117 termfunc_elem->pFunc = pFunc;
118 termfunc_elem->dw = dw;
119 termfunc_elem->pNext = pM->m_pTermFuncs;
121 pM->m_pTermFuncs = termfunc_elem;
123 return S_OK;
126 HRESULT WINAPI AtlModuleRegisterClassObjects(_ATL_MODULEA *pM, DWORD dwClsContext,
127 DWORD dwFlags)
129 HRESULT hRes = S_OK;
130 int i=0;
132 TRACE("(%p %li %li)\n",pM, dwClsContext, dwFlags);
134 if (pM == NULL)
135 return E_INVALIDARG;
137 while(pM->m_pObjMap[i].pclsid != NULL)
139 IUnknown* pUnknown;
140 _ATL_OBJMAP_ENTRYA *obj = &(pM->m_pObjMap[i]);
141 HRESULT rc;
143 TRACE("Registering object %i\n",i);
144 if (obj->pfnGetClassObject)
146 rc = obj->pfnGetClassObject(obj->pfnCreateInstance, &IID_IUnknown,
147 (LPVOID*)&pUnknown);
148 if (SUCCEEDED (rc) )
150 CoRegisterClassObject(obj->pclsid, pUnknown, dwClsContext,
151 dwFlags, &obj->dwRegister);
152 if (pUnknown)
153 IUnknown_Release(pUnknown);
156 i++;
159 return hRes;
162 HRESULT WINAPI AtlModuleUnregisterServerEx(_ATL_MODULEA* pM, BOOL bUnRegTypeLib, const CLSID* pCLSID)
164 FIXME("(%p, %i, %p) stub\n", pM, bUnRegTypeLib, pCLSID);
165 return S_OK;
168 /***********************************************************************
169 * AtlAxWinInit [ATL.@]
170 * Initializes the control-hosting code: registering the AtlAxWin7 and AtlAxWinLic7 window
171 * classes and some messages.
173 * RETURNS
174 * TRUE or FALSE
177 BOOL WINAPI AtlAxWinInit(void)
179 FIXME("Try use native atl.dll if possible\n");
180 return FALSE;
184 HRESULT WINAPI AtlInternalQueryInterface(LPVOID this, const _ATL_INTMAP_ENTRY* pEntries, REFIID iid, LPVOID* ppvObject)
186 int i = 0;
187 HRESULT rc = E_NOINTERFACE;
188 TRACE("(%p, %p, %p, %p)\n",this, pEntries, iid, ppvObject);
190 if (IsEqualGUID(iid,&IID_IUnknown))
192 TRACE("Returning IUnknown\n");
193 *ppvObject = this;
194 IUnknown_AddRef((IUnknown*)this);
195 return S_OK;
198 while (pEntries[i].pFunc != 0)
200 TRACE("Trying entry %i (%p %li %p)\n",i,pEntries[i].piid,
201 pEntries[i].dw, pEntries[i].pFunc);
203 if (pEntries[i].piid && IsEqualGUID(iid,pEntries[i].piid))
205 TRACE("MATCH\n");
206 if (pEntries[i].pFunc == (_ATL_CREATORARGFUNC*)1)
208 TRACE("Offset\n");
209 *ppvObject = ((LPSTR)this+pEntries[i].dw);
210 IUnknown_AddRef((IUnknown*)this);
211 rc = S_OK;
213 else
215 TRACE("Function\n");
216 rc = pEntries[i].pFunc(this, iid, ppvObject,0);
218 break;
220 i++;
222 TRACE("Done returning (0x%lx)\n",rc);
223 return rc;
226 /***********************************************************************
227 * AtlModuleRegisterServer [ATL.@]
230 HRESULT WINAPI AtlModuleRegisterServer(_ATL_MODULEW* pM, BOOL bRegTypeLib, const CLSID* clsid)
232 FIXME("%p %d %s\n", pM, bRegTypeLib, debugstr_guid(clsid));
233 return S_OK;
236 /***********************************************************************
237 * AtlAdvise [ATL.@]
239 HRESULT WINAPI AtlAdvise(IUnknown *pUnkCP, IUnknown *pUnk, const IID *iid, LPDWORD pdw)
241 FIXME("%p %p %p %p\n", pUnkCP, pUnk, iid, pdw);
242 return E_FAIL;
245 /***********************************************************************
246 * AtlUnadvise [ATL.@]
248 HRESULT WINAPI AtlUnadvise(IUnknown *pUnkCP, const IID *iid, DWORD dw)
250 FIXME("%p %p %ld\n", pUnkCP, iid, dw);
251 return S_OK;
254 /***********************************************************************
255 * AtlFreeMarshalStream [ATL.@]
257 HRESULT WINAPI AtlFreeMarshalStream(IStream *stm)
259 FIXME("%p\n", stm);
260 return S_OK;
263 /***********************************************************************
264 * AtlMarshalPtrInProc [ATL.@]
266 HRESULT WINAPI AtlMarshalPtrInProc(IUnknown *pUnk, const IID *iid, IStream **pstm)
268 FIXME("%p %p %p\n", pUnk, iid, pstm);
269 return E_FAIL;
272 /***********************************************************************
273 * AtlUnmarshalPtr [ATL.@]
275 HRESULT WINAPI AtlUnmarshalPtr(IStream *stm, const IID *iid, IUnknown **ppUnk)
277 FIXME("%p %p %p\n", stm, iid, ppUnk);
278 return E_FAIL;
281 /***********************************************************************
282 * AtlModuleGetClassObject [ATL.@]
284 HRESULT WINAPI AtlModuleGetClassObject(_ATL_MODULEW *pm, REFCLSID rclsid,
285 REFIID riid, LPVOID *ppv)
287 FIXME("%p %p %p %p\n", pm, rclsid, riid, ppv);
288 return E_FAIL;
291 /***********************************************************************
292 * AtlModuleGetClassObject [ATL.@]
294 HRESULT WINAPI AtlModuleRegisterTypeLib(_ATL_MODULEW *pm, LPCOLESTR lpszIndex)
296 FIXME("%p %s\n", pm, debugstr_w(lpszIndex));
297 return E_FAIL;
300 /***********************************************************************
301 * AtlModuleRevokeClassObjects [ATL.@]
303 HRESULT WINAPI AtlModuleRevokeClassObjects(_ATL_MODULEW *pm)
305 FIXME("%p\n", pm);
306 return E_FAIL;
309 /***********************************************************************
310 * AtlModuleUnregisterServer [ATL.@]
312 HRESULT WINAPI AtlModuleUnregisterServer(_ATL_MODULEW *pm, const CLSID *clsid)
314 FIXME("%p %s\n", pm, debugstr_guid(clsid));
315 return E_FAIL;
318 /***********************************************************************
319 * AtlAxCreateControl [ATL.@]
321 HRESULT WINAPI AtlAxCreateControl(LPCOLESTR lpszName, HWND hWnd,
322 IStream *pStream, IUnknown **ppUnkContainer)
324 FIXME("%s %p %p %p)\n", debugstr_w(lpszName), hWnd, pStream, ppUnkContainer);
325 return E_NOTIMPL;