msvcrt: Use parameter validation macros for mcstowcs_s_l.
[wine] / dlls / mscoree / corruntimehost.c
1 /*
2  *
3  * Copyright 2008 Alistair Leslie-Hughes
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19
20 #define COBJMACROS
21
22 #include <stdarg.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "winreg.h"
28 #include "ole2.h"
29
30 #include "cor.h"
31 #include "mscoree.h"
32 #include "metahost.h"
33 #include "mscoree_private.h"
34
35 #include "wine/debug.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL( mscoree );
38
39 struct RuntimeHost
40 {
41     const struct ICorRuntimeHostVtbl *lpVtbl;
42     const CLRRuntimeInfo *version;
43     const loaded_mono *mono;
44     LONG ref;
45     BOOL legacy; /* if True, this was created by create_corruntimehost, and Release frees it */
46 };
47
48 static inline RuntimeHost *impl_from_ICorRuntimeHost( ICorRuntimeHost *iface )
49 {
50     return (RuntimeHost *)((char*)iface - FIELD_OFFSET(RuntimeHost, lpVtbl));
51 }
52
53 /*** IUnknown methods ***/
54 static HRESULT WINAPI corruntimehost_QueryInterface(ICorRuntimeHost* iface,
55         REFIID riid,
56         void **ppvObject)
57 {
58     RuntimeHost *This = impl_from_ICorRuntimeHost( iface );
59     TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
60
61     if ( IsEqualGUID( riid, &IID_ICorRuntimeHost ) ||
62          IsEqualGUID( riid, &IID_IUnknown ) )
63     {
64         *ppvObject = iface;
65     }
66     else
67     {
68         FIXME("Unsupported interface %s\n", debugstr_guid(riid));
69         return E_NOINTERFACE;
70     }
71
72     ICorRuntimeHost_AddRef( iface );
73
74     return S_OK;
75 }
76
77 static ULONG WINAPI corruntimehost_AddRef(ICorRuntimeHost* iface)
78 {
79     RuntimeHost *This = impl_from_ICorRuntimeHost( iface );
80     return InterlockedIncrement( &This->ref );
81 }
82
83 static ULONG WINAPI corruntimehost_Release(ICorRuntimeHost* iface)
84 {
85     RuntimeHost *This = impl_from_ICorRuntimeHost( iface );
86     ULONG ref;
87
88     ref = InterlockedDecrement( &This->ref );
89     if ( ref == 0 && This->legacy )
90     {
91         RuntimeHost_Destroy(This);
92     }
93
94     return ref;
95 }
96
97 /*** ICorRuntimeHost methods ***/
98 static HRESULT WINAPI corruntimehost_CreateLogicalThreadState(
99                     ICorRuntimeHost* iface)
100 {
101     FIXME("stub %p\n", iface);
102     return E_NOTIMPL;
103 }
104
105 static HRESULT WINAPI corruntimehost_DeleteLogicalThreadState(
106                     ICorRuntimeHost* iface)
107 {
108     FIXME("stub %p\n", iface);
109     return E_NOTIMPL;
110 }
111
112 static HRESULT WINAPI corruntimehost_SwitchInLogicalThreadState(
113                     ICorRuntimeHost* iface,
114                     DWORD *fiberCookie)
115 {
116     FIXME("stub %p\n", iface);
117     return E_NOTIMPL;
118 }
119
120 static HRESULT WINAPI corruntimehost_SwitchOutLogicalThreadState(
121                     ICorRuntimeHost* iface,
122                     DWORD **fiberCookie)
123 {
124     FIXME("stub %p\n", iface);
125     return E_NOTIMPL;
126 }
127
128 static HRESULT WINAPI corruntimehost_LocksHeldByLogicalThread(
129                     ICorRuntimeHost* iface,
130                     DWORD *pCount)
131 {
132     FIXME("stub %p\n", iface);
133     return E_NOTIMPL;
134 }
135
136 static HRESULT WINAPI corruntimehost_MapFile(
137     ICorRuntimeHost* iface,
138     HANDLE hFile,
139     HMODULE *mapAddress)
140 {
141     FIXME("stub %p\n", iface);
142     return E_NOTIMPL;
143 }
144
145 static HRESULT WINAPI corruntimehost_GetConfiguration(
146     ICorRuntimeHost* iface,
147     ICorConfiguration **pConfiguration)
148 {
149     FIXME("stub %p\n", iface);
150     return E_NOTIMPL;
151 }
152
153 static HRESULT WINAPI corruntimehost_Start(
154     ICorRuntimeHost* iface)
155 {
156     FIXME("stub %p\n", iface);
157     return E_NOTIMPL;
158 }
159
160 static HRESULT WINAPI corruntimehost_Stop(
161     ICorRuntimeHost* iface)
162 {
163     FIXME("stub %p\n", iface);
164     return E_NOTIMPL;
165 }
166
167 static HRESULT WINAPI corruntimehost_CreateDomain(
168     ICorRuntimeHost* iface,
169     LPCWSTR friendlyName,
170     IUnknown *identityArray,
171     IUnknown **appDomain)
172 {
173     FIXME("stub %p\n", iface);
174     return E_NOTIMPL;
175 }
176
177 static HRESULT WINAPI corruntimehost_GetDefaultDomain(
178     ICorRuntimeHost* iface,
179     IUnknown **pAppDomain)
180 {
181     FIXME("stub %p\n", iface);
182     return E_NOTIMPL;
183 }
184
185 static HRESULT WINAPI corruntimehost_EnumDomains(
186     ICorRuntimeHost* iface,
187     HDOMAINENUM *hEnum)
188 {
189     FIXME("stub %p\n", iface);
190     return E_NOTIMPL;
191 }
192
193 static HRESULT WINAPI corruntimehost_NextDomain(
194     ICorRuntimeHost* iface,
195     HDOMAINENUM hEnum,
196     IUnknown **appDomain)
197 {
198     FIXME("stub %p\n", iface);
199     return E_NOTIMPL;
200 }
201
202 static HRESULT WINAPI corruntimehost_CloseEnum(
203     ICorRuntimeHost* iface,
204     HDOMAINENUM hEnum)
205 {
206     FIXME("stub %p\n", iface);
207     return E_NOTIMPL;
208 }
209
210 static HRESULT WINAPI corruntimehost_CreateDomainEx(
211     ICorRuntimeHost* iface,
212     LPCWSTR friendlyName,
213     IUnknown *setup,
214     IUnknown *evidence,
215     IUnknown **appDomain)
216 {
217     FIXME("stub %p\n", iface);
218     return E_NOTIMPL;
219 }
220
221 static HRESULT WINAPI corruntimehost_CreateDomainSetup(
222     ICorRuntimeHost* iface,
223     IUnknown **appDomainSetup)
224 {
225     FIXME("stub %p\n", iface);
226     return E_NOTIMPL;
227 }
228
229 static HRESULT WINAPI corruntimehost_CreateEvidence(
230     ICorRuntimeHost* iface,
231     IUnknown **evidence)
232 {
233     FIXME("stub %p\n", iface);
234     return E_NOTIMPL;
235 }
236
237 static HRESULT WINAPI corruntimehost_UnloadDomain(
238     ICorRuntimeHost* iface,
239     IUnknown *appDomain)
240 {
241     FIXME("stub %p\n", iface);
242     return E_NOTIMPL;
243 }
244
245 static HRESULT WINAPI corruntimehost_CurrentDomain(
246     ICorRuntimeHost* iface,
247     IUnknown **appDomain)
248 {
249     FIXME("stub %p\n", iface);
250     return E_NOTIMPL;
251 }
252
253 static const struct ICorRuntimeHostVtbl corruntimehost_vtbl =
254 {
255     corruntimehost_QueryInterface,
256     corruntimehost_AddRef,
257     corruntimehost_Release,
258     corruntimehost_CreateLogicalThreadState,
259     corruntimehost_DeleteLogicalThreadState,
260     corruntimehost_SwitchInLogicalThreadState,
261     corruntimehost_SwitchOutLogicalThreadState,
262     corruntimehost_LocksHeldByLogicalThread,
263     corruntimehost_MapFile,
264     corruntimehost_GetConfiguration,
265     corruntimehost_Start,
266     corruntimehost_Stop,
267     corruntimehost_CreateDomain,
268     corruntimehost_GetDefaultDomain,
269     corruntimehost_EnumDomains,
270     corruntimehost_NextDomain,
271     corruntimehost_CloseEnum,
272     corruntimehost_CreateDomainEx,
273     corruntimehost_CreateDomainSetup,
274     corruntimehost_CreateEvidence,
275     corruntimehost_UnloadDomain,
276     corruntimehost_CurrentDomain
277 };
278
279 HRESULT RuntimeHost_Construct(const CLRRuntimeInfo *runtime_version,
280     const loaded_mono *loaded_mono, RuntimeHost** result)
281 {
282     RuntimeHost *This;
283
284     This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
285     if ( !This )
286         return E_OUTOFMEMORY;
287
288     This->lpVtbl = &corruntimehost_vtbl;
289     This->ref = 1;
290     This->version = runtime_version;
291     This->mono = loaded_mono;
292     This->legacy = FALSE;
293
294     *result = This;
295
296     return S_OK;
297 }
298
299 HRESULT RuntimeHost_GetInterface(RuntimeHost *This, REFCLSID clsid, REFIID riid, void **ppv)
300 {
301     IUnknown *unk;
302
303     if (IsEqualGUID(clsid, &CLSID_CorRuntimeHost))
304         unk = (IUnknown*)&This->lpVtbl;
305     else
306         unk = NULL;
307
308     if (unk)
309         return IUnknown_QueryInterface(unk, riid, ppv);
310     else
311         FIXME("not implemented for class %s\n", debugstr_guid(clsid));
312
313     return CLASS_E_CLASSNOTAVAILABLE;
314 }
315
316 HRESULT RuntimeHost_Destroy(RuntimeHost *This)
317 {
318     HeapFree( GetProcessHeap(), 0, This );
319     return S_OK;
320 }
321
322 IUnknown* create_corruntimehost(void)
323 {
324     RuntimeHost *This;
325     IUnknown *result;
326
327     if (FAILED(RuntimeHost_Construct(NULL, NULL, &This)))
328         return NULL;
329
330     This->legacy = TRUE;
331
332     if (FAILED(RuntimeHost_GetInterface(This, &CLSID_CorRuntimeHost, &IID_IUnknown, (void**)&result)))
333     {
334         RuntimeHost_Destroy(This);
335         return NULL;
336     }
337
338     FIXME("return iface %p\n", result);
339
340     return result;
341 }