Don't mistake frames for bytes.
[wine/multimedia.git] / dlls / atl / atl_main.c
blobf4b48c92e18dcba7074c4314cc18a496cb662868
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"
36 WINE_DEFAULT_DEBUG_CHANNEL(atl);
38 HINSTANCE hInst;
40 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
42 TRACE("(0x%p, %ld, %p)\n",hinstDLL,fdwReason,lpvReserved);
44 if (fdwReason == DLL_PROCESS_ATTACH) {
45 DisableThreadLibraryCalls(hinstDLL);
46 hInst = hinstDLL;
48 return TRUE;
51 HRESULT WINAPI AtlModuleInit(_ATL_MODULEA* pM, _ATL_OBJMAP_ENTRYA* p, HINSTANCE h)
53 INT i;
55 FIXME("SEMI-STUB (%p %p %p)\n",pM,p,h);
57 memset(pM,0,sizeof(_ATL_MODULEA));
58 pM->cbSize = sizeof(_ATL_MODULEA);
59 pM->m_hInst = h;
60 pM->m_hInstResource = h;
61 pM->m_hInstTypeLib = h;
62 pM->m_pObjMap = p;
63 pM->m_hHeap = GetProcessHeap();
65 /* call mains */
66 i = 0;
67 while (pM->m_pObjMap[i].pclsid != NULL)
69 TRACE("Initializing object %i\n",i);
70 p[i].pfnObjectMain(TRUE);
71 i++;
74 return S_OK;
77 HRESULT WINAPI AtlModuleTerm(_ATL_MODULEA* pM)
79 HeapFree(GetProcessHeap(), 0, pM);
80 return S_OK;
83 HRESULT WINAPI AtlModuleRegisterClassObjects(_ATL_MODULEA *pM, DWORD dwClsContext,
84 DWORD dwFlags)
86 HRESULT hRes = S_OK;
87 int i=0;
89 TRACE("(%p %li %li)\n",pM, dwClsContext, dwFlags);
91 if (pM == NULL)
92 return E_INVALIDARG;
94 while(pM->m_pObjMap[i].pclsid != NULL)
96 IUnknown* pUnknown;
97 _ATL_OBJMAP_ENTRYA *obj = &(pM->m_pObjMap[i]);
98 HRESULT rc;
100 TRACE("Registering object %i\n",i);
101 if (obj->pfnGetClassObject)
103 rc = obj->pfnGetClassObject(obj->pfnCreateInstance, &IID_IUnknown,
104 (LPVOID*)&pUnknown);
105 if (SUCCEEDED (rc) )
107 CoRegisterClassObject(obj->pclsid, pUnknown, dwClsContext,
108 dwFlags, &obj->dwRegister);
109 if (pUnknown)
110 IUnknown_Release(pUnknown);
113 i++;
116 return hRes;
119 HRESULT WINAPI AtlModuleUnregisterServerEx(_ATL_MODULEA* pM, BOOL bUnRegTypeLib, const CLSID* pCLSID)
121 FIXME("(%p, %i, %p) stub\n", pM, bUnRegTypeLib, pCLSID);
122 return S_OK;
125 HRESULT WINAPI AtlInternalQueryInterface(LPVOID this, const _ATL_INTMAP_ENTRY* pEntries, REFIID iid, LPVOID* ppvObject)
127 int i = 0;
128 HRESULT rc = E_NOINTERFACE;
129 TRACE("(%p, %p, %p, %p)\n",this, pEntries, iid, ppvObject);
131 if (IsEqualGUID(iid,&IID_IUnknown))
133 TRACE("Returning IUnknown\n");
134 *ppvObject = this;
135 IUnknown_AddRef((IUnknown*)this);
136 return S_OK;
139 while (pEntries[i].pFunc != 0)
141 TRACE("Trying entry %i (%p %li %p)\n",i,pEntries[i].piid,
142 pEntries[i].dw, pEntries[i].pFunc);
144 if (pEntries[i].piid && IsEqualGUID(iid,pEntries[i].piid))
146 TRACE("MATCH\n");
147 if (pEntries[i].pFunc == (_ATL_CREATORARGFUNC*)1)
149 TRACE("Offset\n");
150 *ppvObject = ((LPSTR)this+pEntries[i].dw);
151 IUnknown_AddRef((IUnknown*)this);
152 rc = S_OK;
154 else
156 TRACE("Function\n");
157 rc = pEntries[i].pFunc(this, iid, ppvObject,0);
159 break;
161 i++;
163 TRACE("Done returning (0x%lx)\n",rc);
164 return rc;
167 /***********************************************************************
168 * AtlModuleUpdateRegistryFromResourceD [ATL.@]
171 HRESULT WINAPI AtlModuleUpdateRegistryFromResourceD(_ATL_MODULEW* pM, LPCOLESTR lpszRes,
172 BOOL bRegister, /* struct _ATL_REGMAP_ENTRY* */ void* pMapEntries, /* IRegistrar* */ void* pReg)
174 HINSTANCE hInst = pM->m_hInst;
175 /* everything inside this function below this point
176 * should go into atl71.AtlUpdateRegistryFromResourceD
178 WCHAR module_name[MAX_PATH];
180 GetModuleFileNameW(hInst, module_name, MAX_PATH);
182 FIXME("stub %p (%s), %s, %d, %p, %p\n", hInst, debugstr_w(module_name),
183 debugstr_w(lpszRes), bRegister, pMapEntries, pReg);
185 return S_OK;
188 /***********************************************************************
189 * AtlModuleRegisterServer [ATL.@]
192 HRESULT WINAPI AtlModuleRegisterServer(_ATL_MODULEW* pM, BOOL bRegTypeLib, const CLSID* clsid)
194 FIXME("%p %d %s\n", pM, bRegTypeLib, debugstr_guid(clsid));
195 return S_OK;
198 /***********************************************************************
199 * AtlAdvise [ATL.@]
201 HRESULT WINAPI AtlAdvise(IUnknown *pUnkCP, IUnknown *pUnk, const IID *iid, LPDWORD pdw)
203 FIXME("%p %p %p %p\n", pUnkCP, pUnk, iid, pdw);
204 return E_FAIL;
207 /***********************************************************************
208 * AtlUnadvise [ATL.@]
210 HRESULT WINAPI AtlUnadvise(IUnknown *pUnkCP, const IID *iid, DWORD dw)
212 FIXME("%p %p %ld\n", pUnkCP, iid, dw);
213 return S_OK;
216 /***********************************************************************
217 * AtlFreeMarshalStream [ATL.@]
219 HRESULT WINAPI AtlFreeMarshalStream(IStream *stm)
221 FIXME("%p\n", stm);
222 return S_OK;
225 /***********************************************************************
226 * AtlMarshalPtrInProc [ATL.@]
228 HRESULT WINAPI AtlMarshalPtrInProc(IUnknown *pUnk, const IID *iid, IStream **pstm)
230 FIXME("%p %p %p\n", pUnk, iid, pstm);
231 return E_FAIL;
234 /***********************************************************************
235 * AtlUnmarshalPtr [ATL.@]
237 HRESULT WINAPI AtlUnmarshalPtr(IStream *stm, const IID *iid, IUnknown **ppUnk)
239 FIXME("%p %p %p\n", stm, iid, ppUnk);
240 return E_FAIL;
243 /***********************************************************************
244 * AtlModuleGetClassObject [ATL.@]
246 HRESULT WINAPI AtlModuleGetClassObject(_ATL_MODULEW *pm, REFCLSID rclsid,
247 REFIID riid, LPVOID *ppv)
249 FIXME("%p %p %p %p\n", pm, rclsid, riid, ppv);
250 return E_FAIL;
253 /***********************************************************************
254 * AtlModuleGetClassObject [ATL.@]
256 HRESULT WINAPI AtlModuleRegisterTypeLib(_ATL_MODULEW *pm, LPCOLESTR lpszIndex)
258 FIXME("%p %s\n", pm, debugstr_w(lpszIndex));
259 return E_FAIL;
262 /***********************************************************************
263 * AtlModuleRevokeClassObjects [ATL.@]
265 HRESULT WINAPI AtlModuleRevokeClassObjects(_ATL_MODULEW *pm)
267 FIXME("%p\n", pm);
268 return E_FAIL;
271 /***********************************************************************
272 * AtlModuleUnregisterServer [ATL.@]
274 HRESULT WINAPI AtlModuleUnregisterServer(_ATL_MODULEW *pm, const CLSID *clsid)
276 FIXME("%p %s\n", pm, debugstr_guid(clsid));
277 return E_FAIL;