localspl: Remove a bunch of casts.
[wine.git] / dlls / mscoree / metahost.c
blob8417344920ef4f811de29feb0fec5aea7ff0dc46
1 /*
2 * ICLRMetaHost - discovery and management of available .NET runtimes
4 * Copyright 2010 Vincent Povirk 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdio.h>
22 #include <stdarg.h>
23 #include <assert.h>
25 #define COBJMACROS
27 #include "wine/unicode.h"
28 #include "wine/library.h"
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winreg.h"
32 #include "ole2.h"
34 #include "corerror.h"
35 #include "cor.h"
36 #include "mscoree.h"
37 #include "corhdr.h"
38 #include "cordebug.h"
39 #include "metahost.h"
40 #include "fusion.h"
41 #include "wine/list.h"
42 #include "mscoree_private.h"
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL( mscoree );
48 static const WCHAR net_20_subdir[] = {'2','.','0',0};
49 static const WCHAR net_40_subdir[] = {'4','.','0',0};
51 static const struct ICLRRuntimeInfoVtbl CLRRuntimeInfoVtbl;
53 #define NUM_RUNTIMES 3
55 static struct CLRRuntimeInfo runtimes[NUM_RUNTIMES] = {
56 {{&CLRRuntimeInfoVtbl}, net_20_subdir, 1, 1, 4322, 0},
57 {{&CLRRuntimeInfoVtbl}, net_20_subdir, 2, 0, 50727, 0},
58 {{&CLRRuntimeInfoVtbl}, net_40_subdir, 4, 0, 30319, 0}
61 static int runtimes_initialized;
63 static CRITICAL_SECTION runtime_list_cs;
64 static CRITICAL_SECTION_DEBUG runtime_list_cs_debug =
66 0, 0, &runtime_list_cs,
67 { &runtime_list_cs_debug.ProcessLocksList,
68 &runtime_list_cs_debug.ProcessLocksList },
69 0, 0, { (DWORD_PTR)(__FILE__ ": runtime_list_cs") }
71 static CRITICAL_SECTION runtime_list_cs = { &runtime_list_cs_debug, -1, 0, 0, 0, 0 };
73 #define NUM_ABI_VERSIONS 2
75 static loaded_mono loaded_monos[NUM_ABI_VERSIONS];
77 static BOOL find_mono_dll(LPCWSTR path, LPWSTR dll_path, int abi_version);
79 static MonoAssembly* mono_assembly_search_hook_fn(MonoAssemblyName *aname, char **assemblies_path, void *user_data);
81 static void mono_shutdown_callback_fn(MonoProfiler *prof);
83 static void set_environment(LPCWSTR bin_path)
85 WCHAR path_env[MAX_PATH];
86 int len;
88 static const WCHAR pathW[] = {'P','A','T','H',0};
90 /* We have to modify PATH as Mono loads other DLLs from this directory. */
91 GetEnvironmentVariableW(pathW, path_env, sizeof(path_env)/sizeof(WCHAR));
92 len = strlenW(path_env);
93 path_env[len++] = ';';
94 strcpyW(path_env+len, bin_path);
95 SetEnvironmentVariableW(pathW, path_env);
98 static void CDECL do_nothing(void)
102 static MonoImage* image_open_module_handle_dummy(HMODULE module_handle,
103 char* fname, UINT has_entry_point, MonoImageOpenStatus* status, int abi_version)
105 return loaded_monos[abi_version-1].mono_image_open(fname, status);
108 static CDECL MonoImage* image_open_module_handle_dummy_1(HMODULE module_handle,
109 char* fname, UINT has_entry_point, MonoImageOpenStatus* status)
111 return image_open_module_handle_dummy(module_handle, fname, has_entry_point, status, 1);
114 static CDECL MonoImage* image_open_module_handle_dummy_2(HMODULE module_handle,
115 char* fname, UINT has_entry_point, MonoImageOpenStatus* status)
117 return image_open_module_handle_dummy(module_handle, fname, has_entry_point, status, 2);
120 MonoImage* (CDECL * const image_from_handle_fn[NUM_ABI_VERSIONS])(HMODULE module_handle, char* fname, UINT has_entry_point, MonoImageOpenStatus* status) = {
121 image_open_module_handle_dummy_1,
122 image_open_module_handle_dummy_2
125 static void missing_runtime_message(void)
127 MESSAGE("wine: Install Mono for Windows to run .NET applications.\n");
130 static HRESULT load_mono(CLRRuntimeInfo *This, loaded_mono **result)
132 static const WCHAR bin[] = {'\\','b','i','n',0};
133 static const WCHAR lib[] = {'\\','l','i','b',0};
134 static const WCHAR etc[] = {'\\','e','t','c',0};
135 static const WCHAR glibdll[] = {'l','i','b','g','l','i','b','-','2','.','0','-','0','.','d','l','l',0};
136 WCHAR mono_dll_path[MAX_PATH+16], mono_bin_path[MAX_PATH+4];
137 WCHAR mono_lib_path[MAX_PATH+4], mono_etc_path[MAX_PATH+4];
138 char mono_lib_path_a[MAX_PATH], mono_etc_path_a[MAX_PATH];
139 int trace_size;
140 char trace_setting[256];
142 if (This->mono_abi_version <= 0 || This->mono_abi_version > NUM_ABI_VERSIONS)
144 missing_runtime_message();
145 return E_FAIL;
148 *result = &loaded_monos[This->mono_abi_version-1];
150 if ((*result)->is_shutdown)
152 ERR("Cannot load Mono after it has been shut down.\n");
153 *result = NULL;
154 return E_FAIL;
157 if (!(*result)->mono_handle)
159 strcpyW(mono_bin_path, This->mono_path);
160 strcatW(mono_bin_path, bin);
161 set_environment(mono_bin_path);
163 strcpyW(mono_lib_path, This->mono_path);
164 strcatW(mono_lib_path, lib);
165 WideCharToMultiByte(CP_UTF8, 0, mono_lib_path, -1, mono_lib_path_a, MAX_PATH, NULL, NULL);
167 strcpyW(mono_etc_path, This->mono_path);
168 strcatW(mono_etc_path, etc);
169 WideCharToMultiByte(CP_UTF8, 0, mono_etc_path, -1, mono_etc_path_a, MAX_PATH, NULL, NULL);
171 if (!find_mono_dll(This->mono_path, mono_dll_path, This->mono_abi_version)) goto fail;
173 (*result)->mono_handle = LoadLibraryW(mono_dll_path);
175 if (!(*result)->mono_handle) goto fail;
177 #define LOAD_MONO_FUNCTION(x) do { \
178 (*result)->x = (void*)GetProcAddress((*result)->mono_handle, #x); \
179 if (!(*result)->x) { \
180 goto fail; \
182 } while (0);
184 LOAD_MONO_FUNCTION(mono_assembly_get_image);
185 LOAD_MONO_FUNCTION(mono_assembly_load_from);
186 LOAD_MONO_FUNCTION(mono_assembly_open);
187 LOAD_MONO_FUNCTION(mono_config_parse);
188 LOAD_MONO_FUNCTION(mono_class_from_mono_type);
189 LOAD_MONO_FUNCTION(mono_class_from_name);
190 LOAD_MONO_FUNCTION(mono_class_get_method_from_name);
191 LOAD_MONO_FUNCTION(mono_domain_assembly_open);
192 LOAD_MONO_FUNCTION(mono_image_open);
193 LOAD_MONO_FUNCTION(mono_install_assembly_preload_hook);
194 LOAD_MONO_FUNCTION(mono_jit_exec);
195 LOAD_MONO_FUNCTION(mono_jit_init);
196 LOAD_MONO_FUNCTION(mono_jit_set_trace_options);
197 LOAD_MONO_FUNCTION(mono_marshal_get_vtfixup_ftnptr);
198 LOAD_MONO_FUNCTION(mono_object_get_domain);
199 LOAD_MONO_FUNCTION(mono_object_new);
200 LOAD_MONO_FUNCTION(mono_object_unbox);
201 LOAD_MONO_FUNCTION(mono_profiler_install);
202 LOAD_MONO_FUNCTION(mono_reflection_type_from_name);
203 LOAD_MONO_FUNCTION(mono_runtime_invoke);
204 LOAD_MONO_FUNCTION(mono_runtime_object_init);
205 LOAD_MONO_FUNCTION(mono_runtime_quit);
206 LOAD_MONO_FUNCTION(mono_set_dirs);
207 LOAD_MONO_FUNCTION(mono_stringify_assembly_name);
208 LOAD_MONO_FUNCTION(mono_string_new);
209 LOAD_MONO_FUNCTION(mono_thread_attach);
211 /* GLib imports obsoleted by the 2.0 ABI */
212 if (This->mono_abi_version == 1)
214 (*result)->glib_handle = LoadLibraryW(glibdll);
215 if (!(*result)->glib_handle) goto fail;
217 (*result)->mono_free = (void*)GetProcAddress((*result)->glib_handle, "g_free");
218 if (!(*result)->mono_free) goto fail;
220 else
222 LOAD_MONO_FUNCTION(mono_free);
225 #undef LOAD_MONO_FUNCTION
227 #define LOAD_OPT_MONO_FUNCTION(x, default) do { \
228 (*result)->x = (void*)GetProcAddress((*result)->mono_handle, #x); \
229 if (!(*result)->x) { \
230 (*result)->x = default; \
232 } while (0);
234 LOAD_OPT_MONO_FUNCTION(mono_image_open_from_module_handle, image_from_handle_fn[This->mono_abi_version-1]);
235 LOAD_OPT_MONO_FUNCTION(mono_runtime_set_shutting_down, do_nothing);
236 LOAD_OPT_MONO_FUNCTION(mono_thread_pool_cleanup, do_nothing);
237 LOAD_OPT_MONO_FUNCTION(mono_thread_suspend_all_other_threads, do_nothing);
238 LOAD_OPT_MONO_FUNCTION(mono_threads_set_shutting_down, do_nothing);
240 #undef LOAD_OPT_MONO_FUNCTION
242 (*result)->mono_profiler_install((MonoProfiler*)*result, mono_shutdown_callback_fn);
244 (*result)->mono_set_dirs(mono_lib_path_a, mono_etc_path_a);
246 (*result)->mono_config_parse(NULL);
248 (*result)->mono_install_assembly_preload_hook(mono_assembly_search_hook_fn, *result);
250 trace_size = GetEnvironmentVariableA("WINE_MONO_TRACE", trace_setting, sizeof(trace_setting));
252 if (trace_size)
254 (*result)->mono_jit_set_trace_options(trace_setting);
258 return S_OK;
260 fail:
261 ERR("Could not load Mono into this process\n");
262 FreeLibrary((*result)->mono_handle);
263 FreeLibrary((*result)->glib_handle);
264 (*result)->mono_handle = NULL;
265 (*result)->glib_handle = NULL;
266 return E_FAIL;
269 static void mono_shutdown_callback_fn(MonoProfiler *prof)
271 loaded_mono *mono = (loaded_mono*)prof;
273 mono->is_shutdown = TRUE;
276 static HRESULT CLRRuntimeInfo_GetRuntimeHost(CLRRuntimeInfo *This, RuntimeHost **result)
278 HRESULT hr = S_OK;
279 loaded_mono *ploaded_mono;
281 if (This->loaded_runtime)
283 *result = This->loaded_runtime;
284 return hr;
287 EnterCriticalSection(&runtime_list_cs);
289 hr = load_mono(This, &ploaded_mono);
291 if (SUCCEEDED(hr))
292 hr = RuntimeHost_Construct(This, ploaded_mono, &This->loaded_runtime);
294 LeaveCriticalSection(&runtime_list_cs);
296 if (SUCCEEDED(hr))
297 *result = This->loaded_runtime;
299 return hr;
302 void unload_all_runtimes(void)
304 int i;
306 for (i=0; i<NUM_ABI_VERSIONS; i++)
308 loaded_mono *mono = &loaded_monos[i];
309 if (mono->mono_handle && mono->is_started && !mono->is_shutdown)
311 /* Copied from Mono's ves_icall_System_Environment_Exit */
312 mono->mono_threads_set_shutting_down();
313 mono->mono_runtime_set_shutting_down();
314 mono->mono_thread_pool_cleanup();
315 mono->mono_thread_suspend_all_other_threads();
316 mono->mono_runtime_quit();
320 for (i=0; i<NUM_RUNTIMES; i++)
321 if (runtimes[i].loaded_runtime)
322 RuntimeHost_Destroy(runtimes[i].loaded_runtime);
325 void expect_no_runtimes(void)
327 int i;
329 for (i=0; i<NUM_ABI_VERSIONS; i++)
331 loaded_mono *mono = &loaded_monos[i];
332 if (mono->mono_handle && mono->is_started && !mono->is_shutdown)
334 ERR("Process exited with a Mono runtime loaded.\n");
335 return;
340 static inline CLRRuntimeInfo *impl_from_ICLRRuntimeInfo(ICLRRuntimeInfo *iface)
342 return CONTAINING_RECORD(iface, CLRRuntimeInfo, ICLRRuntimeInfo_iface);
345 static HRESULT WINAPI CLRRuntimeInfo_QueryInterface(ICLRRuntimeInfo* iface,
346 REFIID riid,
347 void **ppvObject)
349 TRACE("%p %s %p\n", iface, debugstr_guid(riid), ppvObject);
351 if ( IsEqualGUID( riid, &IID_ICLRRuntimeInfo ) ||
352 IsEqualGUID( riid, &IID_IUnknown ) )
354 *ppvObject = iface;
356 else
358 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
359 return E_NOINTERFACE;
362 ICLRRuntimeInfo_AddRef( iface );
364 return S_OK;
367 static ULONG WINAPI CLRRuntimeInfo_AddRef(ICLRRuntimeInfo* iface)
369 return 2;
372 static ULONG WINAPI CLRRuntimeInfo_Release(ICLRRuntimeInfo* iface)
374 return 1;
377 static HRESULT WINAPI CLRRuntimeInfo_GetVersionString(ICLRRuntimeInfo* iface,
378 LPWSTR pwzBuffer, DWORD *pcchBuffer)
380 struct CLRRuntimeInfo *This = impl_from_ICLRRuntimeInfo(iface);
381 DWORD buffer_size = *pcchBuffer;
382 HRESULT hr = S_OK;
383 char version[11];
384 DWORD size;
386 TRACE("%p %p %p\n", iface, pwzBuffer, pcchBuffer);
388 size = snprintf(version, sizeof(version), "v%u.%u.%u", This->major, This->minor, This->build);
390 assert(size <= sizeof(version));
392 *pcchBuffer = MultiByteToWideChar(CP_UTF8, 0, version, -1, NULL, 0);
394 if (pwzBuffer)
396 if (buffer_size >= *pcchBuffer)
397 MultiByteToWideChar(CP_UTF8, 0, version, -1, pwzBuffer, buffer_size);
398 else
399 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
402 return hr;
405 static BOOL get_install_root(LPWSTR install_dir)
407 const WCHAR dotnet_key[] = {'S','O','F','T','W','A','R','E','\\','M','i','c','r','o','s','o','f','t','\\','.','N','E','T','F','r','a','m','e','w','o','r','k','\\',0};
408 const WCHAR install_root[] = {'I','n','s','t','a','l','l','R','o','o','t',0};
410 DWORD len;
411 HKEY key;
413 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, dotnet_key, 0, KEY_READ, &key))
414 return FALSE;
416 len = MAX_PATH;
417 if (RegQueryValueExW(key, install_root, 0, NULL, (LPBYTE)install_dir, &len))
419 RegCloseKey(key);
420 return FALSE;
422 RegCloseKey(key);
424 return TRUE;
427 static HRESULT WINAPI CLRRuntimeInfo_GetRuntimeDirectory(ICLRRuntimeInfo* iface,
428 LPWSTR pwzBuffer, DWORD *pcchBuffer)
430 static const WCHAR slash[] = {'\\',0};
431 DWORD buffer_size = *pcchBuffer;
432 WCHAR system_dir[MAX_PATH];
433 WCHAR version[MAX_PATH];
434 DWORD version_size, size;
435 HRESULT hr = S_OK;
437 TRACE("%p %p %p\n", iface, pwzBuffer, pcchBuffer);
439 if (!get_install_root(system_dir))
441 ERR("error reading registry key for installroot\n");
442 return E_FAIL;
444 else
446 version_size = MAX_PATH;
447 ICLRRuntimeInfo_GetVersionString(iface, version, &version_size);
448 lstrcatW(system_dir, version);
449 lstrcatW(system_dir, slash);
450 size = lstrlenW(system_dir) + 1;
453 *pcchBuffer = size;
455 if (pwzBuffer)
457 if (buffer_size >= size)
458 strcpyW(pwzBuffer, system_dir);
459 else
460 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
463 return hr;
466 static HRESULT WINAPI CLRRuntimeInfo_IsLoaded(ICLRRuntimeInfo* iface,
467 HANDLE hndProcess, BOOL *pbLoaded)
469 FIXME("%p %p %p\n", iface, hndProcess, pbLoaded);
471 return E_NOTIMPL;
474 static HRESULT WINAPI CLRRuntimeInfo_LoadErrorString(ICLRRuntimeInfo* iface,
475 UINT iResourceID, LPWSTR pwzBuffer, DWORD *pcchBuffer, LONG iLocaleid)
477 FIXME("%p %u %p %p %x\n", iface, iResourceID, pwzBuffer, pcchBuffer, iLocaleid);
479 return E_NOTIMPL;
482 static HRESULT WINAPI CLRRuntimeInfo_LoadLibrary(ICLRRuntimeInfo* iface,
483 LPCWSTR pwzDllName, HMODULE *phndModule)
485 WCHAR version[MAX_PATH];
486 HRESULT hr;
487 DWORD cchBuffer;
489 TRACE("%p %s %p\n", iface, debugstr_w(pwzDllName), phndModule);
491 cchBuffer = MAX_PATH;
492 hr = ICLRRuntimeInfo_GetVersionString(iface, version, &cchBuffer);
493 if (FAILED(hr)) return hr;
495 return LoadLibraryShim(pwzDllName, version, NULL, phndModule);
498 static HRESULT WINAPI CLRRuntimeInfo_GetProcAddress(ICLRRuntimeInfo* iface,
499 LPCSTR pszProcName, LPVOID *ppProc)
501 FIXME("%p %s %p\n", iface, debugstr_a(pszProcName), ppProc);
503 return E_NOTIMPL;
506 static HRESULT WINAPI CLRRuntimeInfo_GetInterface(ICLRRuntimeInfo* iface,
507 REFCLSID rclsid, REFIID riid, LPVOID *ppUnk)
509 struct CLRRuntimeInfo *This = impl_from_ICLRRuntimeInfo(iface);
510 RuntimeHost *host;
511 HRESULT hr;
513 TRACE("%p %s %s %p\n", iface, debugstr_guid(rclsid), debugstr_guid(riid), ppUnk);
515 hr = CLRRuntimeInfo_GetRuntimeHost(This, &host);
517 if (SUCCEEDED(hr))
518 hr = RuntimeHost_GetInterface(host, rclsid, riid, ppUnk);
520 return hr;
523 static HRESULT WINAPI CLRRuntimeInfo_IsLoadable(ICLRRuntimeInfo* iface,
524 BOOL *pbLoadable)
526 FIXME("%p %p\n", iface, pbLoadable);
528 return E_NOTIMPL;
531 static HRESULT WINAPI CLRRuntimeInfo_SetDefaultStartupFlags(ICLRRuntimeInfo* iface,
532 DWORD dwStartupFlags, LPCWSTR pwzHostConfigFile)
534 FIXME("%p %x %s\n", iface, dwStartupFlags, debugstr_w(pwzHostConfigFile));
536 return E_NOTIMPL;
539 static HRESULT WINAPI CLRRuntimeInfo_GetDefaultStartupFlags(ICLRRuntimeInfo* iface,
540 DWORD *pdwStartupFlags, LPWSTR pwzHostConfigFile, DWORD *pcchHostConfigFile)
542 FIXME("%p %p %p %p\n", iface, pdwStartupFlags, pwzHostConfigFile, pcchHostConfigFile);
544 return E_NOTIMPL;
547 static HRESULT WINAPI CLRRuntimeInfo_BindAsLegacyV2Runtime(ICLRRuntimeInfo* iface)
549 FIXME("%p\n", iface);
551 return E_NOTIMPL;
554 static HRESULT WINAPI CLRRuntimeInfo_IsStarted(ICLRRuntimeInfo* iface,
555 BOOL *pbStarted, DWORD *pdwStartupFlags)
557 FIXME("%p %p %p\n", iface, pbStarted, pdwStartupFlags);
559 return E_NOTIMPL;
562 static const struct ICLRRuntimeInfoVtbl CLRRuntimeInfoVtbl = {
563 CLRRuntimeInfo_QueryInterface,
564 CLRRuntimeInfo_AddRef,
565 CLRRuntimeInfo_Release,
566 CLRRuntimeInfo_GetVersionString,
567 CLRRuntimeInfo_GetRuntimeDirectory,
568 CLRRuntimeInfo_IsLoaded,
569 CLRRuntimeInfo_LoadErrorString,
570 CLRRuntimeInfo_LoadLibrary,
571 CLRRuntimeInfo_GetProcAddress,
572 CLRRuntimeInfo_GetInterface,
573 CLRRuntimeInfo_IsLoadable,
574 CLRRuntimeInfo_SetDefaultStartupFlags,
575 CLRRuntimeInfo_GetDefaultStartupFlags,
576 CLRRuntimeInfo_BindAsLegacyV2Runtime,
577 CLRRuntimeInfo_IsStarted
580 HRESULT ICLRRuntimeInfo_GetRuntimeHost(ICLRRuntimeInfo *iface, RuntimeHost **result)
582 struct CLRRuntimeInfo *This = impl_from_ICLRRuntimeInfo(iface);
584 assert(This->ICLRRuntimeInfo_iface.lpVtbl == &CLRRuntimeInfoVtbl);
586 return CLRRuntimeInfo_GetRuntimeHost(This, result);
589 #ifdef __i386__
590 static const WCHAR libmono2_arch_dll[] = {'\\','b','i','n','\\','l','i','b','m','o','n','o','-','2','.','0','-','x','8','6','.','d','l','l',0};
591 #elif defined(__x86_64__)
592 static const WCHAR libmono2_arch_dll[] = {'\\','b','i','n','\\','l','i','b','m','o','n','o','-','2','.','0','-','x','8','6','_','6','4','.','d','l','l',0};
593 #else
594 static const WCHAR libmono2_arch_dll[] = {'\\','b','i','n','\\','l','i','b','m','o','n','o','-','2','.','0','.','d','l','l',0};
595 #endif
597 static BOOL find_mono_dll(LPCWSTR path, LPWSTR dll_path, int abi_version)
599 static const WCHAR mono_dll[] = {'\\','b','i','n','\\','m','o','n','o','.','d','l','l',0};
600 static const WCHAR libmono_dll[] = {'\\','b','i','n','\\','l','i','b','m','o','n','o','.','d','l','l',0};
601 static const WCHAR mono2_dll[] = {'\\','b','i','n','\\','m','o','n','o','-','2','.','0','.','d','l','l',0};
602 static const WCHAR libmono2_dll[] = {'\\','b','i','n','\\','l','i','b','m','o','n','o','-','2','.','0','.','d','l','l',0};
603 DWORD attributes=INVALID_FILE_ATTRIBUTES;
605 if (abi_version == 1)
607 strcpyW(dll_path, path);
608 strcatW(dll_path, mono_dll);
609 attributes = GetFileAttributesW(dll_path);
611 if (attributes == INVALID_FILE_ATTRIBUTES)
613 strcpyW(dll_path, path);
614 strcatW(dll_path, libmono_dll);
615 attributes = GetFileAttributesW(dll_path);
618 else if (abi_version == 2)
620 strcpyW(dll_path, path);
621 strcatW(dll_path, libmono2_arch_dll);
622 attributes = GetFileAttributesW(dll_path);
624 if (attributes == INVALID_FILE_ATTRIBUTES)
626 strcpyW(dll_path, path);
627 strcatW(dll_path, mono2_dll);
628 attributes = GetFileAttributesW(dll_path);
631 if (attributes == INVALID_FILE_ATTRIBUTES)
633 strcpyW(dll_path, path);
634 strcatW(dll_path, libmono2_dll);
635 attributes = GetFileAttributesW(dll_path);
639 return (attributes != INVALID_FILE_ATTRIBUTES);
642 static BOOL get_mono_path_from_registry(LPWSTR path, int abi_version)
644 static const WCHAR mono_key[] = {'S','o','f','t','w','a','r','e','\\','N','o','v','e','l','l','\\','M','o','n','o',0};
645 static const WCHAR defaul_clr[] = {'D','e','f','a','u','l','t','C','L','R',0};
646 static const WCHAR install_root[] = {'S','d','k','I','n','s','t','a','l','l','R','o','o','t',0};
647 static const WCHAR slash[] = {'\\',0};
649 WCHAR version[64], version_key[MAX_PATH];
650 DWORD len;
651 HKEY key;
652 WCHAR dll_path[MAX_PATH];
654 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, mono_key, 0, KEY_READ, &key))
655 return FALSE;
657 len = sizeof(version);
658 if (RegQueryValueExW(key, defaul_clr, 0, NULL, (LPBYTE)version, &len))
660 RegCloseKey(key);
661 return FALSE;
663 RegCloseKey(key);
665 lstrcpyW(version_key, mono_key);
666 lstrcatW(version_key, slash);
667 lstrcatW(version_key, version);
669 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, version_key, 0, KEY_READ, &key))
670 return FALSE;
672 len = sizeof(WCHAR) * MAX_PATH;
673 if (RegQueryValueExW(key, install_root, 0, NULL, (LPBYTE)path, &len))
675 RegCloseKey(key);
676 return FALSE;
678 RegCloseKey(key);
680 return find_mono_dll(path, dll_path, abi_version);
683 static BOOL get_mono_path_from_folder(LPCWSTR folder, LPWSTR mono_path, int abi_version)
685 static const WCHAR mono_one_dot_zero[] = {'\\','m','o','n','o','-','1','.','0', 0};
686 static const WCHAR mono_two_dot_zero[] = {'\\','m','o','n','o','-','2','.','0', 0};
687 WCHAR mono_dll_path[MAX_PATH];
688 BOOL found = FALSE;
690 strcpyW(mono_path, folder);
692 if (abi_version == 1)
693 strcatW(mono_path, mono_one_dot_zero);
694 else if (abi_version == 2)
695 strcatW(mono_path, mono_two_dot_zero);
697 found = find_mono_dll(mono_path, mono_dll_path, abi_version);
699 return found;
702 static BOOL get_mono_path(LPWSTR path, int abi_version)
704 static const WCHAR subdir_mono[] = {'\\','m','o','n','o',0};
705 static const WCHAR sibling_mono[] = {'\\','.','.','\\','m','o','n','o',0};
706 WCHAR base_path[MAX_PATH];
707 const char *unix_data_dir;
708 WCHAR *dos_data_dir;
709 int build_tree=0;
710 static WCHAR* (CDECL *wine_get_dos_file_name)(const char*);
712 /* First try c:\windows\mono */
713 GetWindowsDirectoryW(base_path, MAX_PATH);
714 strcatW(base_path, subdir_mono);
716 if (get_mono_path_from_folder(base_path, path, abi_version))
717 return TRUE;
719 /* Next: /usr/share/wine/mono */
720 unix_data_dir = wine_get_data_dir();
722 if (!unix_data_dir)
724 unix_data_dir = wine_get_build_dir();
725 build_tree = 1;
728 if (unix_data_dir)
730 if (!wine_get_dos_file_name)
731 wine_get_dos_file_name = (void*)GetProcAddress(GetModuleHandleA("kernel32"), "wine_get_dos_file_name");
733 if (wine_get_dos_file_name)
735 dos_data_dir = wine_get_dos_file_name(unix_data_dir);
737 if (dos_data_dir)
739 strcpyW(base_path, dos_data_dir);
740 strcatW(base_path, build_tree ? sibling_mono : subdir_mono);
742 HeapFree(GetProcessHeap(), 0, dos_data_dir);
744 if (get_mono_path_from_folder(base_path, path, abi_version))
745 return TRUE;
750 /* Last: the registry */
751 return get_mono_path_from_registry(path, abi_version);
754 static void find_runtimes(void)
756 int abi_version, i;
757 static const WCHAR libmono[] = {'\\','l','i','b','\\','m','o','n','o','\\',0};
758 static const WCHAR mscorlib[] = {'\\','m','s','c','o','r','l','i','b','.','d','l','l',0};
759 WCHAR mono_path[MAX_PATH], lib_path[MAX_PATH];
760 BOOL any_runtimes_found = FALSE;
762 if (runtimes_initialized) return;
764 EnterCriticalSection(&runtime_list_cs);
766 if (runtimes_initialized) goto end;
768 for (abi_version=NUM_ABI_VERSIONS; abi_version>0; abi_version--)
770 if (!get_mono_path(mono_path, abi_version))
771 continue;
773 for (i=0; i<NUM_RUNTIMES; i++)
775 if (runtimes[i].mono_abi_version == 0)
777 strcpyW(lib_path, mono_path);
778 strcatW(lib_path, libmono);
779 strcatW(lib_path, runtimes[i].mono_libdir);
780 strcatW(lib_path, mscorlib);
782 if (GetFileAttributesW(lib_path) != INVALID_FILE_ATTRIBUTES)
784 runtimes[i].mono_abi_version = abi_version;
786 strcpyW(runtimes[i].mono_path, mono_path);
787 strcpyW(runtimes[i].mscorlib_path, lib_path);
789 any_runtimes_found = TRUE;
795 if (!any_runtimes_found)
797 /* Report all runtimes are available if Mono isn't installed.
798 * FIXME: Remove this when Mono is properly packaged. */
799 for (i=0; i<NUM_RUNTIMES; i++)
800 runtimes[i].mono_abi_version = -1;
803 runtimes_initialized = 1;
805 end:
806 LeaveCriticalSection(&runtime_list_cs);
809 struct InstalledRuntimeEnum
811 IEnumUnknown IEnumUnknown_iface;
812 LONG ref;
813 ULONG pos;
816 static const struct IEnumUnknownVtbl InstalledRuntimeEnum_Vtbl;
818 static inline struct InstalledRuntimeEnum *impl_from_IEnumUnknown(IEnumUnknown *iface)
820 return CONTAINING_RECORD(iface, struct InstalledRuntimeEnum, IEnumUnknown_iface);
823 static HRESULT WINAPI InstalledRuntimeEnum_QueryInterface(IEnumUnknown* iface, REFIID riid,
824 void **ppvObject)
826 TRACE("%p %s %p\n", iface, debugstr_guid(riid), ppvObject);
828 if ( IsEqualGUID( riid, &IID_IEnumUnknown ) ||
829 IsEqualGUID( riid, &IID_IUnknown ) )
831 *ppvObject = iface;
833 else
835 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
836 return E_NOINTERFACE;
839 IEnumUnknown_AddRef( iface );
841 return S_OK;
844 static ULONG WINAPI InstalledRuntimeEnum_AddRef(IEnumUnknown* iface)
846 struct InstalledRuntimeEnum *This = impl_from_IEnumUnknown(iface);
847 ULONG ref = InterlockedIncrement(&This->ref);
849 TRACE("(%p) refcount=%u\n", iface, ref);
851 return ref;
854 static ULONG WINAPI InstalledRuntimeEnum_Release(IEnumUnknown* iface)
856 struct InstalledRuntimeEnum *This = impl_from_IEnumUnknown(iface);
857 ULONG ref = InterlockedDecrement(&This->ref);
859 TRACE("(%p) refcount=%u\n", iface, ref);
861 if (ref == 0)
863 HeapFree(GetProcessHeap(), 0, This);
866 return ref;
869 static HRESULT WINAPI InstalledRuntimeEnum_Next(IEnumUnknown *iface, ULONG celt,
870 IUnknown **rgelt, ULONG *pceltFetched)
872 struct InstalledRuntimeEnum *This = impl_from_IEnumUnknown(iface);
873 int num_fetched = 0;
874 HRESULT hr=S_OK;
875 IUnknown *item;
877 TRACE("(%p,%u,%p,%p)\n", iface, celt, rgelt, pceltFetched);
879 while (num_fetched < celt)
881 if (This->pos >= NUM_RUNTIMES)
883 hr = S_FALSE;
884 break;
886 if (runtimes[This->pos].mono_abi_version)
888 item = (IUnknown*)&runtimes[This->pos].ICLRRuntimeInfo_iface;
889 IUnknown_AddRef(item);
890 rgelt[num_fetched] = item;
891 num_fetched++;
893 This->pos++;
896 if (pceltFetched)
897 *pceltFetched = num_fetched;
899 return hr;
902 static HRESULT WINAPI InstalledRuntimeEnum_Skip(IEnumUnknown *iface, ULONG celt)
904 struct InstalledRuntimeEnum *This = impl_from_IEnumUnknown(iface);
905 int num_fetched = 0;
906 HRESULT hr=S_OK;
908 TRACE("(%p,%u)\n", iface, celt);
910 while (num_fetched < celt)
912 if (This->pos >= NUM_RUNTIMES)
914 hr = S_FALSE;
915 break;
917 if (runtimes[This->pos].mono_abi_version)
919 num_fetched++;
921 This->pos++;
924 return hr;
927 static HRESULT WINAPI InstalledRuntimeEnum_Reset(IEnumUnknown *iface)
929 struct InstalledRuntimeEnum *This = impl_from_IEnumUnknown(iface);
931 TRACE("(%p)\n", iface);
933 This->pos = 0;
935 return S_OK;
938 static HRESULT WINAPI InstalledRuntimeEnum_Clone(IEnumUnknown *iface, IEnumUnknown **ppenum)
940 struct InstalledRuntimeEnum *This = impl_from_IEnumUnknown(iface);
941 struct InstalledRuntimeEnum *new_enum;
943 TRACE("(%p)\n", iface);
945 new_enum = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_enum));
946 if (!new_enum)
947 return E_OUTOFMEMORY;
949 new_enum->IEnumUnknown_iface.lpVtbl = &InstalledRuntimeEnum_Vtbl;
950 new_enum->ref = 1;
951 new_enum->pos = This->pos;
953 *ppenum = &new_enum->IEnumUnknown_iface;
955 return S_OK;
958 static const struct IEnumUnknownVtbl InstalledRuntimeEnum_Vtbl = {
959 InstalledRuntimeEnum_QueryInterface,
960 InstalledRuntimeEnum_AddRef,
961 InstalledRuntimeEnum_Release,
962 InstalledRuntimeEnum_Next,
963 InstalledRuntimeEnum_Skip,
964 InstalledRuntimeEnum_Reset,
965 InstalledRuntimeEnum_Clone
968 struct CLRMetaHost
970 ICLRMetaHost ICLRMetaHost_iface;
973 static struct CLRMetaHost GlobalCLRMetaHost;
975 static HRESULT WINAPI CLRMetaHost_QueryInterface(ICLRMetaHost* iface,
976 REFIID riid,
977 void **ppvObject)
979 TRACE("%s %p\n", debugstr_guid(riid), ppvObject);
981 if ( IsEqualGUID( riid, &IID_ICLRMetaHost ) ||
982 IsEqualGUID( riid, &IID_IUnknown ) )
984 *ppvObject = iface;
986 else
988 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
989 return E_NOINTERFACE;
992 ICLRMetaHost_AddRef( iface );
994 return S_OK;
997 static ULONG WINAPI CLRMetaHost_AddRef(ICLRMetaHost* iface)
999 return 2;
1002 static ULONG WINAPI CLRMetaHost_Release(ICLRMetaHost* iface)
1004 return 1;
1007 static BOOL parse_runtime_version(LPCWSTR version, DWORD *major, DWORD *minor, DWORD *build)
1009 *major = 0;
1010 *minor = 0;
1011 *build = 0;
1013 if (version[0] == 'v' || version[0] == 'V')
1015 version++;
1016 if (!isdigit(*version))
1017 return FALSE;
1019 while (isdigit(*version))
1020 *major = *major * 10 + (*version++ - '0');
1022 if (*version == 0)
1023 return TRUE;
1025 if (*version++ != '.' || !isdigit(*version))
1026 return FALSE;
1028 while (isdigit(*version))
1029 *minor = *minor * 10 + (*version++ - '0');
1031 if (*version == 0)
1032 return TRUE;
1034 if (*version++ != '.' || !isdigit(*version))
1035 return FALSE;
1037 while (isdigit(*version))
1038 *build = *build * 10 + (*version++ - '0');
1040 return *version == 0;
1042 else
1043 return FALSE;
1046 HRESULT WINAPI CLRMetaHost_GetRuntime(ICLRMetaHost* iface,
1047 LPCWSTR pwzVersion, REFIID iid, LPVOID *ppRuntime)
1049 int i;
1050 DWORD major, minor, build;
1052 TRACE("%s %s %p\n", debugstr_w(pwzVersion), debugstr_guid(iid), ppRuntime);
1054 if (!pwzVersion)
1055 return E_POINTER;
1057 if (!parse_runtime_version(pwzVersion, &major, &minor, &build))
1059 ERR("Cannot parse %s\n", debugstr_w(pwzVersion));
1060 return CLR_E_SHIM_RUNTIME;
1063 find_runtimes();
1065 for (i=0; i<NUM_RUNTIMES; i++)
1067 if (runtimes[i].major == major && runtimes[i].minor == minor &&
1068 runtimes[i].build == build)
1070 if (runtimes[i].mono_abi_version)
1071 return ICLRRuntimeInfo_QueryInterface(&runtimes[i].ICLRRuntimeInfo_iface, iid,
1072 ppRuntime);
1073 else
1075 missing_runtime_message();
1076 return CLR_E_SHIM_RUNTIME;
1081 FIXME("Unrecognized version %s\n", debugstr_w(pwzVersion));
1082 return CLR_E_SHIM_RUNTIME;
1085 HRESULT WINAPI CLRMetaHost_GetVersionFromFile(ICLRMetaHost* iface,
1086 LPCWSTR pwzFilePath, LPWSTR pwzBuffer, DWORD *pcchBuffer)
1088 ASSEMBLY *assembly;
1089 HRESULT hr;
1090 LPSTR version;
1091 ULONG buffer_size=*pcchBuffer;
1093 TRACE("%s %p %p\n", debugstr_w(pwzFilePath), pwzBuffer, pcchBuffer);
1095 hr = assembly_create(&assembly, pwzFilePath);
1097 if (SUCCEEDED(hr))
1099 hr = assembly_get_runtime_version(assembly, &version);
1101 if (SUCCEEDED(hr))
1103 *pcchBuffer = MultiByteToWideChar(CP_UTF8, 0, version, -1, NULL, 0);
1105 if (pwzBuffer)
1107 if (buffer_size >= *pcchBuffer)
1108 MultiByteToWideChar(CP_UTF8, 0, version, -1, pwzBuffer, buffer_size);
1109 else
1110 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
1114 assembly_release(assembly);
1117 return hr;
1120 static HRESULT WINAPI CLRMetaHost_EnumerateInstalledRuntimes(ICLRMetaHost* iface,
1121 IEnumUnknown **ppEnumerator)
1123 struct InstalledRuntimeEnum *new_enum;
1125 TRACE("%p\n", ppEnumerator);
1127 find_runtimes();
1129 new_enum = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_enum));
1130 if (!new_enum)
1131 return E_OUTOFMEMORY;
1133 new_enum->IEnumUnknown_iface.lpVtbl = &InstalledRuntimeEnum_Vtbl;
1134 new_enum->ref = 1;
1135 new_enum->pos = 0;
1137 *ppEnumerator = &new_enum->IEnumUnknown_iface;
1139 return S_OK;
1142 static HRESULT WINAPI CLRMetaHost_EnumerateLoadedRuntimes(ICLRMetaHost* iface,
1143 HANDLE hndProcess, IEnumUnknown **ppEnumerator)
1145 FIXME("%p %p\n", hndProcess, ppEnumerator);
1147 return E_NOTIMPL;
1150 static HRESULT WINAPI CLRMetaHost_RequestRuntimeLoadedNotification(ICLRMetaHost* iface,
1151 RuntimeLoadedCallbackFnPtr pCallbackFunction)
1153 FIXME("%p\n", pCallbackFunction);
1155 return E_NOTIMPL;
1158 static HRESULT WINAPI CLRMetaHost_QueryLegacyV2RuntimeBinding(ICLRMetaHost* iface,
1159 REFIID riid, LPVOID *ppUnk)
1161 FIXME("%s %p\n", debugstr_guid(riid), ppUnk);
1163 return E_NOTIMPL;
1166 static HRESULT WINAPI CLRMetaHost_ExitProcess(ICLRMetaHost* iface, INT32 iExitCode)
1168 FIXME("%i: stub\n", iExitCode);
1170 ExitProcess(iExitCode);
1173 static const struct ICLRMetaHostVtbl CLRMetaHost_vtbl =
1175 CLRMetaHost_QueryInterface,
1176 CLRMetaHost_AddRef,
1177 CLRMetaHost_Release,
1178 CLRMetaHost_GetRuntime,
1179 CLRMetaHost_GetVersionFromFile,
1180 CLRMetaHost_EnumerateInstalledRuntimes,
1181 CLRMetaHost_EnumerateLoadedRuntimes,
1182 CLRMetaHost_RequestRuntimeLoadedNotification,
1183 CLRMetaHost_QueryLegacyV2RuntimeBinding,
1184 CLRMetaHost_ExitProcess
1187 static struct CLRMetaHost GlobalCLRMetaHost = {
1188 { &CLRMetaHost_vtbl }
1191 HRESULT CLRMetaHost_CreateInstance(REFIID riid, void **ppobj)
1193 return ICLRMetaHost_QueryInterface(&GlobalCLRMetaHost.ICLRMetaHost_iface, riid, ppobj);
1196 static MonoAssembly* mono_assembly_search_hook_fn(MonoAssemblyName *aname, char **assemblies_path, void *user_data)
1198 loaded_mono *mono = user_data;
1199 HRESULT hr=S_OK;
1200 MonoAssembly *result=NULL;
1201 char *stringname=NULL;
1202 LPWSTR stringnameW;
1203 int stringnameW_size;
1204 IAssemblyCache *asmcache;
1205 ASSEMBLY_INFO info;
1206 WCHAR path[MAX_PATH];
1207 char *pathA;
1208 MonoImageOpenStatus stat;
1209 static WCHAR fusiondll[] = {'f','u','s','i','o','n',0};
1210 HMODULE hfusion=NULL;
1211 static HRESULT (WINAPI *pCreateAssemblyCache)(IAssemblyCache**,DWORD);
1213 stringname = mono->mono_stringify_assembly_name(aname);
1215 TRACE("%s\n", debugstr_a(stringname));
1217 if (!stringname) return NULL;
1219 /* FIXME: We should search the given paths before the GAC. */
1221 if (!pCreateAssemblyCache)
1223 hr = LoadLibraryShim(fusiondll, NULL, NULL, &hfusion);
1225 if (SUCCEEDED(hr))
1227 pCreateAssemblyCache = (void*)GetProcAddress(hfusion, "CreateAssemblyCache");
1228 if (!pCreateAssemblyCache)
1229 hr = E_FAIL;
1233 if (SUCCEEDED(hr))
1234 hr = pCreateAssemblyCache(&asmcache, 0);
1236 if (SUCCEEDED(hr))
1238 stringnameW_size = MultiByteToWideChar(CP_UTF8, 0, stringname, -1, NULL, 0);
1240 stringnameW = HeapAlloc(GetProcessHeap(), 0, stringnameW_size * sizeof(WCHAR));
1241 if (stringnameW)
1242 MultiByteToWideChar(CP_UTF8, 0, stringname, -1, stringnameW, stringnameW_size);
1243 else
1244 hr = E_OUTOFMEMORY;
1246 if (SUCCEEDED(hr))
1248 info.cbAssemblyInfo = sizeof(info);
1249 info.pszCurrentAssemblyPathBuf = path;
1250 info.cchBuf = MAX_PATH;
1251 path[0] = 0;
1253 hr = IAssemblyCache_QueryAssemblyInfo(asmcache, 0, stringnameW, &info);
1256 HeapFree(GetProcessHeap(), 0, stringnameW);
1258 IAssemblyCache_Release(asmcache);
1261 if (SUCCEEDED(hr))
1263 TRACE("found: %s\n", debugstr_w(path));
1265 pathA = WtoA(path);
1267 if (pathA)
1269 result = mono->mono_assembly_open(pathA, &stat);
1271 if (!result)
1272 ERR("Failed to load %s, status=%u\n", debugstr_w(path), stat);
1274 HeapFree(GetProcessHeap(), 0, pathA);
1278 mono->mono_free(stringname);
1280 return result;
1283 HRESULT get_runtime_info(LPCWSTR exefile, LPCWSTR version, LPCWSTR config_file,
1284 DWORD startup_flags, DWORD runtimeinfo_flags, BOOL legacy, ICLRRuntimeInfo **result)
1286 static const WCHAR dotconfig[] = {'.','c','o','n','f','i','g',0};
1287 static const DWORD supported_startup_flags = 0;
1288 static const DWORD supported_runtime_flags = RUNTIME_INFO_UPGRADE_VERSION;
1289 int i;
1290 WCHAR local_version[MAX_PATH];
1291 ULONG local_version_size = MAX_PATH;
1292 WCHAR local_config_file[MAX_PATH];
1293 HRESULT hr;
1294 parsed_config_file parsed_config;
1296 if (startup_flags & ~supported_startup_flags)
1297 FIXME("unsupported startup flags %x\n", startup_flags & ~supported_startup_flags);
1299 if (runtimeinfo_flags & ~supported_runtime_flags)
1300 FIXME("unsupported runtimeinfo flags %x\n", runtimeinfo_flags & ~supported_runtime_flags);
1302 if (exefile && !config_file)
1304 strcpyW(local_config_file, exefile);
1305 strcatW(local_config_file, dotconfig);
1307 config_file = local_config_file;
1310 if (config_file)
1312 int found=0;
1313 hr = parse_config_file(config_file, &parsed_config);
1315 if (SUCCEEDED(hr))
1317 supported_runtime *entry;
1318 LIST_FOR_EACH_ENTRY(entry, &parsed_config.supported_runtimes, supported_runtime, entry)
1320 hr = CLRMetaHost_GetRuntime(0, entry->version, &IID_ICLRRuntimeInfo, (void**)result);
1321 if (SUCCEEDED(hr))
1323 found = 1;
1324 break;
1328 else
1330 WARN("failed to parse config file %s, hr=%x\n", debugstr_w(config_file), hr);
1333 free_parsed_config_file(&parsed_config);
1335 if (found)
1336 return S_OK;
1339 if (exefile && !version)
1341 hr = CLRMetaHost_GetVersionFromFile(0, exefile, local_version, &local_version_size);
1343 version = local_version;
1345 if (FAILED(hr)) return hr;
1348 if (version)
1350 hr = CLRMetaHost_GetRuntime(0, version, &IID_ICLRRuntimeInfo, (void**)result);
1351 if(SUCCEEDED(hr))
1352 return hr;
1355 if (runtimeinfo_flags & RUNTIME_INFO_UPGRADE_VERSION)
1357 DWORD major, minor, build;
1359 if (version && !parse_runtime_version(version, &major, &minor, &build))
1361 ERR("Cannot parse %s\n", debugstr_w(version));
1362 return CLR_E_SHIM_RUNTIME;
1365 find_runtimes();
1367 if (legacy)
1368 i = 2;
1369 else
1370 i = NUM_RUNTIMES;
1372 while (i--)
1374 if (runtimes[i].mono_abi_version)
1376 /* Must be greater or equal to the version passed in. */
1377 if (!version || ((runtimes[i].major >= major && runtimes[i].minor >= minor && runtimes[i].build >= build) ||
1378 (runtimes[i].major >= major && runtimes[i].minor > minor) ||
1379 (runtimes[i].major > major)))
1381 return ICLRRuntimeInfo_QueryInterface(&runtimes[i].ICLRRuntimeInfo_iface,
1382 &IID_ICLRRuntimeInfo, (void **)result);
1387 missing_runtime_message();
1389 return CLR_E_SHIM_RUNTIME;
1392 return CLR_E_SHIM_RUNTIME;