Unicodified fontdlg.
[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
36 WINE_DEFAULT_DEBUG_CHANNEL(atl);
37
38 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
39 {
40     TRACE("(0x%p, %ld, %p)\n",hinstDLL,fdwReason,lpvReserved);
41
42     if (fdwReason == DLL_PROCESS_ATTACH) DisableThreadLibraryCalls(hinstDLL);
43     return TRUE;
44 }
45
46 HRESULT WINAPI AtlModuleInit(_ATL_MODULEA* pM, _ATL_OBJMAP_ENTRYA* p, HINSTANCE h)
47 {
48     INT i;
49
50     FIXME("SEMI-STUB (%p %p %p)\n",pM,p,h);
51
52     memset(pM,0,sizeof(_ATL_MODULEA));
53     pM->cbSize = sizeof(_ATL_MODULEA);
54     pM->m_hInst = h;
55     pM->m_hInstResource = h;
56     pM->m_hInstTypeLib = h;
57     pM->m_pObjMap = p;
58     pM->m_hHeap = GetProcessHeap();
59
60     /* call mains */
61     i = 0;
62     while (pM->m_pObjMap[i].pclsid != NULL)
63     {
64         TRACE("Initializing object %i\n",i);
65         p[i].pfnObjectMain(TRUE);
66         i++;
67     }
68
69     return S_OK;
70 }
71
72 HRESULT WINAPI AtlModuleTerm(_ATL_MODULEA* pM)
73 {
74     HeapFree(GetProcessHeap(), 0, pM);
75     return S_OK;
76 }
77
78 HRESULT WINAPI AtlModuleRegisterClassObjects(_ATL_MODULEA *pM, DWORD dwClsContext,
79                                              DWORD dwFlags)
80 {
81     HRESULT hRes = S_OK;
82     int i=0;
83
84     TRACE("(%p %li %li)\n",pM, dwClsContext, dwFlags);
85
86     if (pM == NULL)
87         return E_INVALIDARG;
88
89     while(pM->m_pObjMap[i].pclsid != NULL)
90     {
91         IUnknown* pUnknown;
92         _ATL_OBJMAP_ENTRYA *obj = &(pM->m_pObjMap[i]);
93         HRESULT rc;
94
95         TRACE("Registering object %i\n",i);
96         if (obj->pfnGetClassObject)
97         {
98             rc = obj->pfnGetClassObject(obj->pfnCreateInstance, &IID_IUnknown,
99                                    (LPVOID*)&pUnknown);
100             if (SUCCEEDED (rc) )
101             {
102                 CoRegisterClassObject(obj->pclsid, pUnknown, dwClsContext,
103                                       dwFlags, &obj->dwRegister);
104                 if (pUnknown)
105                     IUnknown_Release(pUnknown);
106             }
107         }
108         i++;
109     }
110
111    return hRes;
112 }
113
114 HRESULT WINAPI AtlModuleUnregisterServerEx(_ATL_MODULEA* pM, BOOL bUnRegTypeLib, const CLSID* pCLSID)
115 {
116     FIXME("(%p, %i, %p) stub\n", pM, bUnRegTypeLib, pCLSID);
117     return S_OK;
118 }
119
120 HRESULT WINAPI AtlInternalQueryInterface(LPVOID this, const _ATL_INTMAP_ENTRY* pEntries,  REFIID iid, LPVOID* ppvObject)
121 {
122     int i = 0;
123     HRESULT rc = E_NOINTERFACE;
124     TRACE("(%p, %p, %p, %p)\n",this, pEntries, iid, ppvObject);
125
126     if (IsEqualGUID(iid,&IID_IUnknown))
127     {
128         TRACE("Returning IUnknown\n");
129         *ppvObject = this;
130         IUnknown_AddRef((IUnknown*)this);
131         return S_OK;
132     }
133
134     while (pEntries[i].pFunc != 0)
135     {
136         TRACE("Trying entry %i (%p %li %p)\n",i,pEntries[i].piid,
137               pEntries[i].dw, pEntries[i].pFunc);
138
139         if (pEntries[i].piid && IsEqualGUID(iid,pEntries[i].piid))
140         {
141             TRACE("MATCH\n");
142             if (pEntries[i].pFunc == (_ATL_CREATORARGFUNC*)1)
143             {
144                 TRACE("Offset\n");
145                 *ppvObject = ((LPSTR)this+pEntries[i].dw);
146                 IUnknown_AddRef((IUnknown*)this);
147                 rc = S_OK;
148             }
149             else
150             {
151                 TRACE("Function\n");
152                 rc = pEntries[i].pFunc(this, iid, ppvObject,0);
153             }
154             break;
155         }
156         i++;
157     }
158     TRACE("Done returning (0x%lx)\n",rc);
159     return rc;
160 }
161
162 /***********************************************************************
163  *           AtlModuleUpdateRegistryFromResourceD         [ATL.@]
164  *
165  */
166 HRESULT WINAPI AtlModuleUpdateRegistryFromResourceD(_ATL_MODULEW* pM, LPCOLESTR lpszRes,
167                 BOOL bRegister, /* struct _ATL_REGMAP_ENTRY* */ void* pMapEntries, /* IRegistrar* */ void* pReg)
168 {
169     HINSTANCE hInst = pM->m_hInst;
170     /* everything inside this function below this point
171      * should go into atl71.AtlUpdateRegistryFromResourceD
172      */
173     WCHAR module_name[MAX_PATH];
174
175     GetModuleFileNameW(hInst, module_name, MAX_PATH);
176
177     FIXME("stub %p (%s), %s, %d, %p, %p\n", hInst, debugstr_w(module_name),
178         debugstr_w(lpszRes), bRegister, pMapEntries, pReg);
179
180     return S_OK;
181 }