Fixes for -Wmissing-declaration and -Wwrite-string warnings.
[wine] / dlls / atl / atl_main.c
1 /*
2  * Implementation of Active Template Library (atl.dll)
3  *
4  * Copyright 2004 Aric Stewart for CodeWeavers
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #define COBJMACROS
25
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"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(atl);
38
39 HINSTANCE hInst;
40
41 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
42 {
43     TRACE("(0x%p, %ld, %p)\n",hinstDLL,fdwReason,lpvReserved);
44
45     if (fdwReason == DLL_PROCESS_ATTACH) {
46         DisableThreadLibraryCalls(hinstDLL);
47         hInst = hinstDLL;
48     }
49     return TRUE;
50 }
51
52 HRESULT WINAPI AtlModuleInit(_ATL_MODULEA* pM, _ATL_OBJMAP_ENTRYA* p, HINSTANCE h)
53 {
54     INT i;
55
56     FIXME("SEMI-STUB (%p %p %p)\n",pM,p,h);
57
58     memset(pM,0,sizeof(_ATL_MODULEA));
59     pM->cbSize = sizeof(_ATL_MODULEA);
60     pM->m_hInst = h;
61     pM->m_hInstResource = h;
62     pM->m_hInstTypeLib = h;
63     pM->m_pObjMap = p;
64     pM->m_hHeap = GetProcessHeap();
65
66     /* call mains */
67     i = 0;
68     while (pM->m_pObjMap[i].pclsid != NULL)
69     {
70         TRACE("Initializing object %i\n",i);
71         p[i].pfnObjectMain(TRUE);
72         i++;
73     }
74
75     return S_OK;
76 }
77
78 HRESULT WINAPI AtlModuleTerm(_ATL_MODULEA* pM)
79 {
80     HeapFree(GetProcessHeap(), 0, pM);
81     return S_OK;
82 }
83
84 HRESULT WINAPI AtlModuleRegisterClassObjects(_ATL_MODULEA *pM, DWORD dwClsContext,
85                                              DWORD dwFlags)
86 {
87     HRESULT hRes = S_OK;
88     int i=0;
89
90     TRACE("(%p %li %li)\n",pM, dwClsContext, dwFlags);
91
92     if (pM == NULL)
93         return E_INVALIDARG;
94
95     while(pM->m_pObjMap[i].pclsid != NULL)
96     {
97         IUnknown* pUnknown;
98         _ATL_OBJMAP_ENTRYA *obj = &(pM->m_pObjMap[i]);
99         HRESULT rc;
100
101         TRACE("Registering object %i\n",i);
102         if (obj->pfnGetClassObject)
103         {
104             rc = obj->pfnGetClassObject(obj->pfnCreateInstance, &IID_IUnknown,
105                                    (LPVOID*)&pUnknown);
106             if (SUCCEEDED (rc) )
107             {
108                 CoRegisterClassObject(obj->pclsid, pUnknown, dwClsContext,
109                                       dwFlags, &obj->dwRegister);
110                 if (pUnknown)
111                     IUnknown_Release(pUnknown);
112             }
113         }
114         i++;
115     }
116
117    return hRes;
118 }
119
120 HRESULT WINAPI AtlModuleUnregisterServerEx(_ATL_MODULEA* pM, BOOL bUnRegTypeLib, const CLSID* pCLSID)
121 {
122     FIXME("(%p, %i, %p) stub\n", pM, bUnRegTypeLib, pCLSID);
123     return S_OK;
124 }
125
126 HRESULT WINAPI AtlInternalQueryInterface(LPVOID this, const _ATL_INTMAP_ENTRY* pEntries,  REFIID iid, LPVOID* ppvObject)
127 {
128     int i = 0;
129     HRESULT rc = E_NOINTERFACE;
130     TRACE("(%p, %p, %p, %p)\n",this, pEntries, iid, ppvObject);
131
132     if (IsEqualGUID(iid,&IID_IUnknown))
133     {
134         TRACE("Returning IUnknown\n");
135         *ppvObject = this;
136         IUnknown_AddRef((IUnknown*)this);
137         return S_OK;
138     }
139
140     while (pEntries[i].pFunc != 0)
141     {
142         TRACE("Trying entry %i (%p %li %p)\n",i,pEntries[i].piid,
143               pEntries[i].dw, pEntries[i].pFunc);
144
145         if (pEntries[i].piid && IsEqualGUID(iid,pEntries[i].piid))
146         {
147             TRACE("MATCH\n");
148             if (pEntries[i].pFunc == (_ATL_CREATORARGFUNC*)1)
149             {
150                 TRACE("Offset\n");
151                 *ppvObject = ((LPSTR)this+pEntries[i].dw);
152                 IUnknown_AddRef((IUnknown*)this);
153                 rc = S_OK;
154             }
155             else
156             {
157                 TRACE("Function\n");
158                 rc = pEntries[i].pFunc(this, iid, ppvObject,0);
159             }
160             break;
161         }
162         i++;
163     }
164     TRACE("Done returning (0x%lx)\n",rc);
165     return rc;
166 }
167
168 /***********************************************************************
169  *           AtlModuleUpdateRegistryFromResourceD         [ATL.@]
170  *
171  */
172 HRESULT WINAPI AtlModuleUpdateRegistryFromResourceD(_ATL_MODULEW* pM, LPCOLESTR lpszRes,
173                 BOOL bRegister, struct _ATL_REGMAP_ENTRY* pMapEntries, IRegistrar* pReg)
174 {
175     HINSTANCE hInst = pM->m_hInst;
176     /* everything inside this function below this point
177      * should go into atl71.AtlUpdateRegistryFromResourceD
178      */
179     WCHAR module_name[MAX_PATH];
180
181     GetModuleFileNameW(hInst, module_name, MAX_PATH);
182
183     FIXME("stub %p (%s), %s, %d, %p, %p\n", hInst, debugstr_w(module_name),
184         debugstr_w(lpszRes), bRegister, pMapEntries, pReg);
185
186     return S_OK;
187 }
188
189 /***********************************************************************
190  *           AtlModuleRegisterServer         [ATL.@]
191  *
192  */
193 HRESULT WINAPI AtlModuleRegisterServer(_ATL_MODULEW* pM, BOOL bRegTypeLib, const CLSID* clsid) 
194 {
195     FIXME("%p %d %s\n", pM, bRegTypeLib, debugstr_guid(clsid));
196     return S_OK;
197 }
198
199 /***********************************************************************
200  *           AtlAdvise         [ATL.@]
201  */
202 HRESULT WINAPI AtlAdvise(IUnknown *pUnkCP, IUnknown *pUnk, const IID *iid, LPDWORD pdw)
203 {
204     FIXME("%p %p %p %p\n", pUnkCP, pUnk, iid, pdw);
205     return E_FAIL;
206 }
207
208 /***********************************************************************
209  *           AtlUnadvise         [ATL.@]
210  */
211 HRESULT WINAPI AtlUnadvise(IUnknown *pUnkCP, const IID *iid, DWORD dw)
212 {
213     FIXME("%p %p %ld\n", pUnkCP, iid, dw);
214     return S_OK;
215 }
216
217 /***********************************************************************
218  *           AtlFreeMarshalStream         [ATL.@]
219  */
220 HRESULT WINAPI AtlFreeMarshalStream(IStream *stm)
221 {
222     FIXME("%p\n", stm);
223     return S_OK;
224 }
225
226 /***********************************************************************
227  *           AtlMarshalPtrInProc         [ATL.@]
228  */
229 HRESULT WINAPI AtlMarshalPtrInProc(IUnknown *pUnk, const IID *iid, IStream **pstm)
230 {
231     FIXME("%p %p %p\n", pUnk, iid, pstm);
232     return E_FAIL;
233 }
234
235 /***********************************************************************
236  *           AtlUnmarshalPtr              [ATL.@]
237  */
238 HRESULT WINAPI AtlUnmarshalPtr(IStream *stm, const IID *iid, IUnknown **ppUnk)
239 {
240     FIXME("%p %p %p\n", stm, iid, ppUnk);
241     return E_FAIL;
242 }
243
244 /***********************************************************************
245  *           AtlModuleGetClassObject              [ATL.@]
246  */
247 HRESULT WINAPI AtlModuleGetClassObject(_ATL_MODULEW *pm, REFCLSID rclsid,
248                                        REFIID riid, LPVOID *ppv)
249 {
250     FIXME("%p %p %p %p\n", pm, rclsid, riid, ppv);
251     return E_FAIL;
252 }
253
254 /***********************************************************************
255  *           AtlModuleGetClassObject              [ATL.@]
256  */
257 HRESULT WINAPI AtlModuleRegisterTypeLib(_ATL_MODULEW *pm, LPCOLESTR lpszIndex)
258 {
259     FIXME("%p %s\n", pm, debugstr_w(lpszIndex));
260     return E_FAIL;
261 }
262
263 /***********************************************************************
264  *           AtlModuleRevokeClassObjects          [ATL.@]
265  */
266 HRESULT WINAPI AtlModuleRevokeClassObjects(_ATL_MODULEW *pm)
267 {
268     FIXME("%p\n", pm);
269     return E_FAIL;
270 }
271
272 /***********************************************************************
273  *           AtlModuleUnregisterServer           [ATL.@]
274  */
275 HRESULT WINAPI AtlModuleUnregisterServer(_ATL_MODULEW *pm, const CLSID *clsid)
276 {
277     FIXME("%p %s\n", pm, debugstr_guid(clsid));
278     return E_FAIL;
279 }