Document wrong behaviour for IRunningObjectTable.
[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 #include "windef.h"
25 #include "winbase.h"
26 #include "winerror.h"
27 #include "winuser.h"
28 #include "wine/debug.h"
29 #include "objbase.h"
30 #include "objidl.h"
31 #include "ole2.h"
32 #include "atlbase.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(atl);
35
36 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
37 {
38     TRACE("(0x%p, %ld, %p)\n",hinstDLL,fdwReason,lpvReserved);
39
40     if (fdwReason == DLL_PROCESS_ATTACH) DisableThreadLibraryCalls(hinstDLL);
41     return TRUE;
42 }
43
44 HRESULT WINAPI AtlModuleInit(_ATL_MODULEA* pM, _ATL_OBJMAP_ENTRYA* p, HINSTANCE h)
45 {
46     INT i;
47
48     FIXME("SEMI-STUB (%p %p %p)\n",pM,p,h);
49
50     memset(pM,0,sizeof(_ATL_MODULEA));
51     pM->cbSize = sizeof(_ATL_MODULEA);
52     pM->m_hInst = h;
53     pM->m_hInstResource = h;
54     pM->m_hInstTypeLib = h;
55     pM->m_pObjMap = p;
56     pM->m_hHeap = GetProcessHeap();
57
58     /* call mains */
59     i = 0;
60     while (pM->m_pObjMap[i].pclsid != NULL)
61     {
62         TRACE("Initializing object %i\n",i);
63         p[i].pfnObjectMain(TRUE);
64         i++;
65     }
66
67     return S_OK;
68 }
69
70 HRESULT WINAPI AtlModuleRegisterClassObjects(_ATL_MODULEA *pM, DWORD dwClsContext,
71                                              DWORD dwFlags)
72 {
73     HRESULT hRes = S_OK;
74     int i=0;
75
76     TRACE("(%p %li %li)\n",pM, dwClsContext, dwFlags);
77
78     if (pM == NULL)
79         return E_INVALIDARG;
80
81     while(pM->m_pObjMap[i].pclsid != NULL)
82     {
83         IUnknown* pUnknown;
84         _ATL_OBJMAP_ENTRYA *obj = &(pM->m_pObjMap[i]);
85         HRESULT rc;
86
87         TRACE("Registering object %i\n",i);
88         if (obj->pfnGetClassObject)
89         {
90             rc = obj->pfnGetClassObject(obj->pfnCreateInstance, &IID_IUnknown,
91                                    (LPVOID*)&pUnknown);
92             if (SUCCEEDED (rc) )
93             {
94                 CoRegisterClassObject(obj->pclsid, pUnknown, dwClsContext,
95                                       dwFlags, &obj->dwRegister);
96                 if (pUnknown)
97                     IUnknown_Release(pUnknown);
98             }
99         }
100         i++;
101     }
102
103    return hRes;
104 }
105
106 HRESULT WINAPI AtlInternalQueryInterface(LPVOID this, const _ATL_INTMAP_ENTRY* pEntries,  REFIID iid, LPVOID* ppvObject)
107 {
108     int i = 0;
109     HRESULT rc = E_NOINTERFACE;
110     TRACE("(%p, %p, %p, %p)\n",this, pEntries, iid, ppvObject);
111
112     if (IsEqualGUID(iid,&IID_IUnknown))
113     {
114         TRACE("Returning IUnknown\n");
115         *ppvObject = this;
116         IUnknown_AddRef((IUnknown*)this);
117         return S_OK;
118     }
119
120     while (pEntries[i].pFunc != 0)
121     {
122         TRACE("Trying entry %i (%p %li %p)\n",i,pEntries[i].piid,
123               pEntries[i].dw, pEntries[i].pFunc);
124
125         if (IsEqualGUID(iid,pEntries[i].piid))
126         {
127             TRACE("MATCH\n");
128             if (pEntries[i].pFunc == (_ATL_CREATORARGFUNC*)1)
129             {
130                 TRACE("Offset\n");
131                 *ppvObject = ((LPSTR)this+pEntries[i].dw);
132                 IUnknown_AddRef((IUnknown*)this);
133                 rc = S_OK;
134             }
135             else
136             {
137                 TRACE("Function\n");
138                 rc = pEntries[i].pFunc(this, iid, ppvObject,0);
139             }
140             break;
141         }
142         i++;
143     }
144     TRACE("Done returning (0x%lx)\n",rc);
145     return rc;
146 }