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
27 #include "wine/unicode.h"
28 #include "wine/library.h"
37 #include "mscoree_private.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL( mscoree
);
43 static const WCHAR net_11_subdir
[] = {'1','.','0',0};
44 static const WCHAR net_20_subdir
[] = {'2','.','0',0};
45 static const WCHAR net_40_subdir
[] = {'4','.','0',0};
47 const struct ICLRRuntimeInfoVtbl CLRRuntimeInfoVtbl
;
49 #define NUM_RUNTIMES 3
51 static struct CLRRuntimeInfo runtimes
[NUM_RUNTIMES
] = {
52 {&CLRRuntimeInfoVtbl
, net_11_subdir
, 1, 1, 4322, 0},
53 {&CLRRuntimeInfoVtbl
, net_20_subdir
, 2, 0, 50727, 0},
54 {&CLRRuntimeInfoVtbl
, net_40_subdir
, 4, 0, 30319, 0}
57 static int runtimes_initialized
;
59 static CRITICAL_SECTION runtime_list_cs
;
60 static CRITICAL_SECTION_DEBUG runtime_list_cs_debug
=
62 0, 0, &runtime_list_cs
,
63 { &runtime_list_cs_debug
.ProcessLocksList
,
64 &runtime_list_cs_debug
.ProcessLocksList
},
65 0, 0, { (DWORD_PTR
)(__FILE__
": runtime_list_cs") }
67 static CRITICAL_SECTION runtime_list_cs
= { &runtime_list_cs_debug
, -1, 0, 0, 0, 0 };
69 #define NUM_ABI_VERSIONS 1
71 static loaded_mono loaded_monos
[NUM_ABI_VERSIONS
];
73 static BOOL
find_mono_dll(LPCWSTR path
, LPWSTR dll_path
, int abi_version
);
75 static void set_environment(LPCWSTR bin_path
)
77 WCHAR path_env
[MAX_PATH
];
80 static const WCHAR pathW
[] = {'P','A','T','H',0};
82 /* We have to modify PATH as Mono loads other DLLs from this directory. */
83 GetEnvironmentVariableW(pathW
, path_env
, sizeof(path_env
)/sizeof(WCHAR
));
84 len
= strlenW(path_env
);
85 path_env
[len
++] = ';';
86 strcpyW(path_env
+len
, bin_path
);
87 SetEnvironmentVariableW(pathW
, path_env
);
90 static HRESULT
load_mono(CLRRuntimeInfo
*This
, loaded_mono
**result
)
92 static const WCHAR bin
[] = {'\\','b','i','n',0};
93 static const WCHAR lib
[] = {'\\','l','i','b',0};
94 static const WCHAR etc
[] = {'\\','e','t','c',0};
95 WCHAR mono_dll_path
[MAX_PATH
+16], mono_bin_path
[MAX_PATH
+4];
96 WCHAR mono_lib_path
[MAX_PATH
+4], mono_etc_path
[MAX_PATH
+4];
97 char mono_lib_path_a
[MAX_PATH
], mono_etc_path_a
[MAX_PATH
];
99 char trace_setting
[256];
101 if (This
->mono_abi_version
== -1)
102 MESSAGE("wine: Install the Windows version of Mono to run .NET executables\n");
104 if (This
->mono_abi_version
<= 0 || This
->mono_abi_version
> NUM_ABI_VERSIONS
)
107 *result
= &loaded_monos
[This
->mono_abi_version
-1];
109 if (!(*result
)->mono_handle
)
111 strcpyW(mono_bin_path
, This
->mono_path
);
112 strcatW(mono_bin_path
, bin
);
113 set_environment(mono_bin_path
);
115 strcpyW(mono_lib_path
, This
->mono_path
);
116 strcatW(mono_lib_path
, lib
);
117 WideCharToMultiByte(CP_UTF8
, 0, mono_lib_path
, -1, mono_lib_path_a
, MAX_PATH
, NULL
, NULL
);
119 strcpyW(mono_etc_path
, This
->mono_path
);
120 strcatW(mono_etc_path
, etc
);
121 WideCharToMultiByte(CP_UTF8
, 0, mono_etc_path
, -1, mono_etc_path_a
, MAX_PATH
, NULL
, NULL
);
123 if (!find_mono_dll(This
->mono_path
, mono_dll_path
, This
->mono_abi_version
)) goto fail
;
125 if (This
->mono_abi_version
!= 1) goto fail
;
127 (*result
)->mono_handle
= LoadLibraryW(mono_dll_path
);
129 if (!(*result
)->mono_handle
) goto fail
;
131 #define LOAD_MONO_FUNCTION(x) do { \
132 (*result)->x = (void*)GetProcAddress((*result)->mono_handle, #x); \
133 if (!(*result)->x) { \
138 LOAD_MONO_FUNCTION(mono_config_parse
);
139 LOAD_MONO_FUNCTION(mono_domain_assembly_open
);
140 LOAD_MONO_FUNCTION(mono_jit_cleanup
);
141 LOAD_MONO_FUNCTION(mono_jit_exec
);
142 LOAD_MONO_FUNCTION(mono_jit_init
);
143 LOAD_MONO_FUNCTION(mono_jit_set_trace_options
);
144 LOAD_MONO_FUNCTION(mono_set_dirs
);
146 #undef LOAD_MONO_FUNCTION
148 (*result
)->mono_set_dirs(mono_lib_path_a
, mono_etc_path_a
);
150 (*result
)->mono_config_parse(NULL
);
152 trace_size
= GetEnvironmentVariableA("WINE_MONO_TRACE", trace_setting
, sizeof(trace_setting
));
156 (*result
)->mono_jit_set_trace_options(trace_setting
);
163 ERR("Could not load Mono into this process\n");
164 FreeLibrary((*result
)->mono_handle
);
165 (*result
)->mono_handle
= NULL
;
169 static HRESULT
CLRRuntimeInfo_GetRuntimeHost(CLRRuntimeInfo
*This
, RuntimeHost
**result
)
172 loaded_mono
*ploaded_mono
;
174 if (This
->loaded_runtime
)
176 *result
= This
->loaded_runtime
;
180 EnterCriticalSection(&runtime_list_cs
);
182 hr
= load_mono(This
, &ploaded_mono
);
185 hr
= RuntimeHost_Construct(This
, ploaded_mono
, &This
->loaded_runtime
);
187 LeaveCriticalSection(&runtime_list_cs
);
190 *result
= This
->loaded_runtime
;
195 void unload_all_runtimes(void)
199 for (i
=0; i
<NUM_RUNTIMES
; i
++)
200 if (runtimes
[i
].loaded_runtime
)
201 RuntimeHost_Destroy(runtimes
[i
].loaded_runtime
);
204 static HRESULT WINAPI
CLRRuntimeInfo_QueryInterface(ICLRRuntimeInfo
* iface
,
208 TRACE("%p %s %p\n", iface
, debugstr_guid(riid
), ppvObject
);
210 if ( IsEqualGUID( riid
, &IID_ICLRRuntimeInfo
) ||
211 IsEqualGUID( riid
, &IID_IUnknown
) )
217 FIXME("Unsupported interface %s\n", debugstr_guid(riid
));
218 return E_NOINTERFACE
;
221 ICLRRuntimeInfo_AddRef( iface
);
226 static ULONG WINAPI
CLRRuntimeInfo_AddRef(ICLRRuntimeInfo
* iface
)
231 static ULONG WINAPI
CLRRuntimeInfo_Release(ICLRRuntimeInfo
* iface
)
236 static HRESULT WINAPI
CLRRuntimeInfo_GetVersionString(ICLRRuntimeInfo
* iface
,
237 LPWSTR pwzBuffer
, DWORD
*pcchBuffer
)
239 struct CLRRuntimeInfo
*This
= (struct CLRRuntimeInfo
*)iface
;
240 DWORD buffer_size
= *pcchBuffer
;
245 TRACE("%p %p %p\n", iface
, pwzBuffer
, pcchBuffer
);
247 size
= snprintf(version
, sizeof(version
), "v%u.%u.%u", This
->major
, This
->minor
, This
->build
);
249 assert(size
<= sizeof(version
));
251 *pcchBuffer
= MultiByteToWideChar(CP_UTF8
, 0, version
, -1, NULL
, 0);
255 if (buffer_size
>= *pcchBuffer
)
256 MultiByteToWideChar(CP_UTF8
, 0, version
, -1, pwzBuffer
, buffer_size
);
258 hr
= HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
264 static BOOL
get_install_root(LPWSTR install_dir
)
266 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};
267 const WCHAR install_root
[] = {'I','n','s','t','a','l','l','R','o','o','t',0};
272 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, dotnet_key
, 0, KEY_READ
, &key
))
276 if (RegQueryValueExW(key
, install_root
, 0, NULL
, (LPBYTE
)install_dir
, &len
))
286 static HRESULT WINAPI
CLRRuntimeInfo_GetRuntimeDirectory(ICLRRuntimeInfo
* iface
,
287 LPWSTR pwzBuffer
, DWORD
*pcchBuffer
)
289 static const WCHAR slash
[] = {'\\',0};
290 DWORD buffer_size
= *pcchBuffer
;
291 WCHAR system_dir
[MAX_PATH
];
292 WCHAR version
[MAX_PATH
];
293 DWORD version_size
, size
;
296 TRACE("%p %p %p\n", iface
, pwzBuffer
, pcchBuffer
);
298 if (!get_install_root(system_dir
))
300 ERR("error reading registry key for installroot\n");
305 version_size
= MAX_PATH
;
306 ICLRRuntimeInfo_GetVersionString(iface
, version
, &version_size
);
307 lstrcatW(system_dir
, version
);
308 lstrcatW(system_dir
, slash
);
309 size
= lstrlenW(system_dir
) + 1;
316 if (buffer_size
>= size
)
317 strcpyW(pwzBuffer
, system_dir
);
319 hr
= HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
325 static HRESULT WINAPI
CLRRuntimeInfo_IsLoaded(ICLRRuntimeInfo
* iface
,
326 HANDLE hndProcess
, BOOL
*pbLoaded
)
328 FIXME("%p %p %p\n", iface
, hndProcess
, pbLoaded
);
333 static HRESULT WINAPI
CLRRuntimeInfo_LoadErrorString(ICLRRuntimeInfo
* iface
,
334 UINT iResourceID
, LPWSTR pwzBuffer
, DWORD
*pcchBuffer
, LONG iLocaleid
)
336 FIXME("%p %u %p %p %x\n", iface
, iResourceID
, pwzBuffer
, pcchBuffer
, iLocaleid
);
341 static HRESULT WINAPI
CLRRuntimeInfo_LoadLibrary(ICLRRuntimeInfo
* iface
,
342 LPCWSTR pwzDllName
, HMODULE
*phndModule
)
344 WCHAR version
[MAX_PATH
];
348 TRACE("%p %s %p\n", iface
, debugstr_w(pwzDllName
), phndModule
);
350 cchBuffer
= MAX_PATH
;
351 hr
= ICLRRuntimeInfo_GetVersionString(iface
, version
, &cchBuffer
);
352 if (FAILED(hr
)) return hr
;
354 return LoadLibraryShim(pwzDllName
, version
, NULL
, phndModule
);
357 static HRESULT WINAPI
CLRRuntimeInfo_GetProcAddress(ICLRRuntimeInfo
* iface
,
358 LPCSTR pszProcName
, LPVOID
*ppProc
)
360 FIXME("%p %s %p\n", iface
, debugstr_a(pszProcName
), ppProc
);
365 static HRESULT WINAPI
CLRRuntimeInfo_GetInterface(ICLRRuntimeInfo
* iface
,
366 REFCLSID rclsid
, REFIID riid
, LPVOID
*ppUnk
)
368 struct CLRRuntimeInfo
*This
= (struct CLRRuntimeInfo
*)iface
;
372 TRACE("%p %s %s %p\n", iface
, debugstr_guid(rclsid
), debugstr_guid(riid
), ppUnk
);
374 hr
= CLRRuntimeInfo_GetRuntimeHost(This
, &host
);
377 hr
= RuntimeHost_GetInterface(host
, rclsid
, riid
, ppUnk
);
382 static HRESULT WINAPI
CLRRuntimeInfo_IsLoadable(ICLRRuntimeInfo
* iface
,
385 FIXME("%p %p\n", iface
, pbLoadable
);
390 static HRESULT WINAPI
CLRRuntimeInfo_SetDefaultStartupFlags(ICLRRuntimeInfo
* iface
,
391 DWORD dwStartupFlags
, LPCWSTR pwzHostConfigFile
)
393 FIXME("%p %x %s\n", iface
, dwStartupFlags
, debugstr_w(pwzHostConfigFile
));
398 static HRESULT WINAPI
CLRRuntimeInfo_GetDefaultStartupFlags(ICLRRuntimeInfo
* iface
,
399 DWORD
*pdwStartupFlags
, LPWSTR pwzHostConfigFile
, DWORD
*pcchHostConfigFile
)
401 FIXME("%p %p %p %p\n", iface
, pdwStartupFlags
, pwzHostConfigFile
, pcchHostConfigFile
);
406 static HRESULT WINAPI
CLRRuntimeInfo_BindAsLegacyV2Runtime(ICLRRuntimeInfo
* iface
)
408 FIXME("%p\n", iface
);
413 static HRESULT WINAPI
CLRRuntimeInfo_IsStarted(ICLRRuntimeInfo
* iface
,
414 BOOL
*pbStarted
, DWORD
*pdwStartupFlags
)
416 FIXME("%p %p %p\n", iface
, pbStarted
, pdwStartupFlags
);
421 const struct ICLRRuntimeInfoVtbl CLRRuntimeInfoVtbl
= {
422 CLRRuntimeInfo_QueryInterface
,
423 CLRRuntimeInfo_AddRef
,
424 CLRRuntimeInfo_Release
,
425 CLRRuntimeInfo_GetVersionString
,
426 CLRRuntimeInfo_GetRuntimeDirectory
,
427 CLRRuntimeInfo_IsLoaded
,
428 CLRRuntimeInfo_LoadErrorString
,
429 CLRRuntimeInfo_LoadLibrary
,
430 CLRRuntimeInfo_GetProcAddress
,
431 CLRRuntimeInfo_GetInterface
,
432 CLRRuntimeInfo_IsLoadable
,
433 CLRRuntimeInfo_SetDefaultStartupFlags
,
434 CLRRuntimeInfo_GetDefaultStartupFlags
,
435 CLRRuntimeInfo_BindAsLegacyV2Runtime
,
436 CLRRuntimeInfo_IsStarted
439 static BOOL
find_mono_dll(LPCWSTR path
, LPWSTR dll_path
, int abi_version
)
441 static const WCHAR mono_dll
[] = {'\\','b','i','n','\\','m','o','n','o','.','d','l','l',0};
442 static const WCHAR libmono_dll
[] = {'\\','b','i','n','\\','l','i','b','m','o','n','o','.','d','l','l',0};
443 DWORD attributes
=INVALID_FILE_ATTRIBUTES
;
445 if (abi_version
== 1)
447 strcpyW(dll_path
, path
);
448 strcatW(dll_path
, mono_dll
);
449 attributes
= GetFileAttributesW(dll_path
);
451 if (attributes
== INVALID_FILE_ATTRIBUTES
)
453 strcpyW(dll_path
, path
);
454 strcatW(dll_path
, libmono_dll
);
455 attributes
= GetFileAttributesW(dll_path
);
459 return (attributes
!= INVALID_FILE_ATTRIBUTES
);
462 static BOOL
get_mono_path_from_registry(LPWSTR path
, int abi_version
)
464 static const WCHAR mono_key
[] = {'S','o','f','t','w','a','r','e','\\','N','o','v','e','l','l','\\','M','o','n','o',0};
465 static const WCHAR defaul_clr
[] = {'D','e','f','a','u','l','t','C','L','R',0};
466 static const WCHAR install_root
[] = {'S','d','k','I','n','s','t','a','l','l','R','o','o','t',0};
467 static const WCHAR slash
[] = {'\\',0};
469 WCHAR version
[64], version_key
[MAX_PATH
];
472 WCHAR dll_path
[MAX_PATH
];
474 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, mono_key
, 0, KEY_READ
, &key
))
477 len
= sizeof(version
);
478 if (RegQueryValueExW(key
, defaul_clr
, 0, NULL
, (LPBYTE
)version
, &len
))
485 lstrcpyW(version_key
, mono_key
);
486 lstrcatW(version_key
, slash
);
487 lstrcatW(version_key
, version
);
489 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, version_key
, 0, KEY_READ
, &key
))
492 len
= sizeof(WCHAR
) * MAX_PATH
;
493 if (RegQueryValueExW(key
, install_root
, 0, NULL
, (LPBYTE
)path
, &len
))
500 return find_mono_dll(path
, dll_path
, abi_version
);
503 static BOOL
get_mono_path_from_folder(LPCWSTR folder
, LPWSTR mono_path
, int abi_version
)
505 static const WCHAR mono_one_dot_zero
[] = {'\\','m','o','n','o','-','1','.','0', 0};
506 WCHAR mono_dll_path
[MAX_PATH
];
509 strcpyW(mono_path
, folder
);
511 if (abi_version
== 1)
512 strcatW(mono_path
, mono_one_dot_zero
);
514 found
= find_mono_dll(mono_path
, mono_dll_path
, abi_version
);
519 static BOOL
get_mono_path(LPWSTR path
, int abi_version
)
521 static const WCHAR subdir_mono
[] = {'\\','m','o','n','o',0};
522 static const WCHAR sibling_mono
[] = {'\\','.','.','\\','m','o','n','o',0};
523 WCHAR base_path
[MAX_PATH
];
524 const char *unix_data_dir
;
527 static WCHAR
* (CDECL
*wine_get_dos_file_name
)(const char*);
529 /* First try c:\windows\mono */
530 GetWindowsDirectoryW(base_path
, MAX_PATH
);
531 strcatW(base_path
, subdir_mono
);
533 if (get_mono_path_from_folder(base_path
, path
, abi_version
))
536 /* Next: /usr/share/wine/mono */
537 unix_data_dir
= wine_get_data_dir();
541 unix_data_dir
= wine_get_build_dir();
547 if (!wine_get_dos_file_name
)
548 wine_get_dos_file_name
= (void*)GetProcAddress(GetModuleHandleA("kernel32"), "wine_get_dos_file_name");
550 if (wine_get_dos_file_name
)
552 dos_data_dir
= wine_get_dos_file_name(unix_data_dir
);
556 strcpyW(base_path
, dos_data_dir
);
557 strcatW(base_path
, build_tree
? sibling_mono
: subdir_mono
);
559 HeapFree(GetProcessHeap(), 0, dos_data_dir
);
561 if (get_mono_path_from_folder(base_path
, path
, abi_version
))
567 /* Last: the registry */
568 return get_mono_path_from_registry(path
, abi_version
);
571 static void find_runtimes(void)
574 static const WCHAR libmono
[] = {'\\','l','i','b','\\','m','o','n','o','\\',0};
575 static const WCHAR mscorlib
[] = {'\\','m','s','c','o','r','l','i','b','.','d','l','l',0};
576 WCHAR mono_path
[MAX_PATH
], lib_path
[MAX_PATH
];
577 BOOL any_runtimes_found
= FALSE
;
579 if (runtimes_initialized
) return;
581 EnterCriticalSection(&runtime_list_cs
);
583 if (runtimes_initialized
) goto end
;
585 for (abi_version
=1; abi_version
>0; abi_version
--)
587 if (!get_mono_path(mono_path
, abi_version
))
590 for (i
=0; i
<NUM_RUNTIMES
; i
++)
592 if (runtimes
[i
].mono_abi_version
== 0)
594 strcpyW(lib_path
, mono_path
);
595 strcatW(lib_path
, libmono
);
596 strcatW(lib_path
, runtimes
[i
].mono_libdir
);
597 strcatW(lib_path
, mscorlib
);
599 if (GetFileAttributesW(lib_path
) != INVALID_FILE_ATTRIBUTES
)
601 runtimes
[i
].mono_abi_version
= abi_version
;
603 strcpyW(runtimes
[i
].mono_path
, mono_path
);
604 strcpyW(runtimes
[i
].mscorlib_path
, lib_path
);
606 any_runtimes_found
= TRUE
;
612 if (!any_runtimes_found
)
614 /* Report all runtimes are available if Mono isn't installed.
615 * FIXME: Remove this when Mono is properly packaged. */
616 for (i
=0; i
<NUM_RUNTIMES
; i
++)
617 runtimes
[i
].mono_abi_version
= -1;
620 runtimes_initialized
= 1;
623 LeaveCriticalSection(&runtime_list_cs
);
626 struct InstalledRuntimeEnum
628 const struct IEnumUnknownVtbl
*Vtbl
;
633 const struct IEnumUnknownVtbl InstalledRuntimeEnum_Vtbl
;
635 static HRESULT WINAPI
InstalledRuntimeEnum_QueryInterface(IEnumUnknown
* iface
,
639 TRACE("%p %s %p\n", iface
, debugstr_guid(riid
), ppvObject
);
641 if ( IsEqualGUID( riid
, &IID_IEnumUnknown
) ||
642 IsEqualGUID( riid
, &IID_IUnknown
) )
648 FIXME("Unsupported interface %s\n", debugstr_guid(riid
));
649 return E_NOINTERFACE
;
652 IEnumUnknown_AddRef( iface
);
657 static ULONG WINAPI
InstalledRuntimeEnum_AddRef(IEnumUnknown
* iface
)
659 struct InstalledRuntimeEnum
*This
= (struct InstalledRuntimeEnum
*)iface
;
660 ULONG ref
= InterlockedIncrement(&This
->ref
);
662 TRACE("(%p) refcount=%u\n", iface
, ref
);
667 static ULONG WINAPI
InstalledRuntimeEnum_Release(IEnumUnknown
* iface
)
669 struct InstalledRuntimeEnum
*This
= (struct InstalledRuntimeEnum
*)iface
;
670 ULONG ref
= InterlockedDecrement(&This
->ref
);
672 TRACE("(%p) refcount=%u\n", iface
, ref
);
676 HeapFree(GetProcessHeap(), 0, This
);
682 static HRESULT WINAPI
InstalledRuntimeEnum_Next(IEnumUnknown
*iface
, ULONG celt
,
683 IUnknown
**rgelt
, ULONG
*pceltFetched
)
685 struct InstalledRuntimeEnum
*This
= (struct InstalledRuntimeEnum
*)iface
;
690 TRACE("(%p,%u,%p,%p)\n", iface
, celt
, rgelt
, pceltFetched
);
692 while (num_fetched
< celt
)
694 if (This
->pos
>= NUM_RUNTIMES
)
699 if (runtimes
[This
->pos
].mono_abi_version
)
701 item
= (IUnknown
*)&runtimes
[This
->pos
];
702 IUnknown_AddRef(item
);
703 rgelt
[num_fetched
] = item
;
710 *pceltFetched
= num_fetched
;
715 static HRESULT WINAPI
InstalledRuntimeEnum_Skip(IEnumUnknown
*iface
, ULONG celt
)
717 struct InstalledRuntimeEnum
*This
= (struct InstalledRuntimeEnum
*)iface
;
721 TRACE("(%p,%u)\n", iface
, celt
);
723 while (num_fetched
< celt
)
725 if (This
->pos
>= NUM_RUNTIMES
)
730 if (runtimes
[This
->pos
].mono_abi_version
)
740 static HRESULT WINAPI
InstalledRuntimeEnum_Reset(IEnumUnknown
*iface
)
742 struct InstalledRuntimeEnum
*This
= (struct InstalledRuntimeEnum
*)iface
;
744 TRACE("(%p)\n", iface
);
751 static HRESULT WINAPI
InstalledRuntimeEnum_Clone(IEnumUnknown
*iface
, IEnumUnknown
**ppenum
)
753 struct InstalledRuntimeEnum
*This
= (struct InstalledRuntimeEnum
*)iface
;
754 struct InstalledRuntimeEnum
*new_enum
;
756 TRACE("(%p)\n", iface
);
758 new_enum
= HeapAlloc(GetProcessHeap(), 0, sizeof(*new_enum
));
760 return E_OUTOFMEMORY
;
762 new_enum
->Vtbl
= &InstalledRuntimeEnum_Vtbl
;
764 new_enum
->pos
= This
->pos
;
766 *ppenum
= (IEnumUnknown
*)new_enum
;
771 const struct IEnumUnknownVtbl InstalledRuntimeEnum_Vtbl
= {
772 InstalledRuntimeEnum_QueryInterface
,
773 InstalledRuntimeEnum_AddRef
,
774 InstalledRuntimeEnum_Release
,
775 InstalledRuntimeEnum_Next
,
776 InstalledRuntimeEnum_Skip
,
777 InstalledRuntimeEnum_Reset
,
778 InstalledRuntimeEnum_Clone
783 const struct ICLRMetaHostVtbl
*CLRMetaHost_vtbl
;
786 static const struct CLRMetaHost GlobalCLRMetaHost
;
788 static HRESULT WINAPI
CLRMetaHost_QueryInterface(ICLRMetaHost
* iface
,
792 TRACE("%s %p\n", debugstr_guid(riid
), ppvObject
);
794 if ( IsEqualGUID( riid
, &IID_ICLRMetaHost
) ||
795 IsEqualGUID( riid
, &IID_IUnknown
) )
801 FIXME("Unsupported interface %s\n", debugstr_guid(riid
));
802 return E_NOINTERFACE
;
805 ICLRMetaHost_AddRef( iface
);
810 static ULONG WINAPI
CLRMetaHost_AddRef(ICLRMetaHost
* iface
)
815 static ULONG WINAPI
CLRMetaHost_Release(ICLRMetaHost
* iface
)
820 static BOOL
parse_runtime_version(LPCWSTR version
, DWORD
*major
, DWORD
*minor
, DWORD
*build
)
826 if (version
[0] == 'v')
829 if (!isdigit(*version
))
832 while (isdigit(*version
))
833 *major
= *major
* 10 + (*version
++ - '0');
838 if (*version
++ != '.' || !isdigit(*version
))
841 while (isdigit(*version
))
842 *minor
= *minor
* 10 + (*version
++ - '0');
847 if (*version
++ != '.' || !isdigit(*version
))
850 while (isdigit(*version
))
851 *build
= *build
* 10 + (*version
++ - '0');
853 return *version
== 0;
859 static HRESULT WINAPI
CLRMetaHost_GetRuntime(ICLRMetaHost
* iface
,
860 LPCWSTR pwzVersion
, REFIID iid
, LPVOID
*ppRuntime
)
863 DWORD major
, minor
, build
;
865 TRACE("%s %s %p\n", debugstr_w(pwzVersion
), debugstr_guid(iid
), ppRuntime
);
870 if (!parse_runtime_version(pwzVersion
, &major
, &minor
, &build
))
872 ERR("Cannot parse %s\n", debugstr_w(pwzVersion
));
873 return CLR_E_SHIM_RUNTIME
;
878 for (i
=0; i
<NUM_RUNTIMES
; i
++)
880 if (runtimes
[i
].major
== major
&& runtimes
[i
].minor
== minor
&&
881 runtimes
[i
].build
== build
)
883 if (runtimes
[i
].mono_abi_version
)
884 return IUnknown_QueryInterface((IUnknown
*)&runtimes
[i
], iid
, ppRuntime
);
887 ERR("Mono is missing %s runtime\n", debugstr_w(pwzVersion
));
888 return CLR_E_SHIM_RUNTIME
;
893 FIXME("Unrecognized version %s\n", debugstr_w(pwzVersion
));
894 return CLR_E_SHIM_RUNTIME
;
897 static HRESULT WINAPI
CLRMetaHost_GetVersionFromFile(ICLRMetaHost
* iface
,
898 LPCWSTR pwzFilePath
, LPWSTR pwzBuffer
, DWORD
*pcchBuffer
)
903 ULONG buffer_size
=*pcchBuffer
;
905 TRACE("%s %p %p\n", debugstr_w(pwzFilePath
), pwzBuffer
, pcchBuffer
);
907 hr
= assembly_create(&assembly
, pwzFilePath
);
911 hr
= assembly_get_runtime_version(assembly
, &version
);
915 *pcchBuffer
= MultiByteToWideChar(CP_UTF8
, 0, version
, -1, NULL
, 0);
919 if (buffer_size
>= *pcchBuffer
)
920 MultiByteToWideChar(CP_UTF8
, 0, version
, -1, pwzBuffer
, buffer_size
);
922 hr
= HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
926 assembly_release(assembly
);
932 static HRESULT WINAPI
CLRMetaHost_EnumerateInstalledRuntimes(ICLRMetaHost
* iface
,
933 IEnumUnknown
**ppEnumerator
)
935 struct InstalledRuntimeEnum
*new_enum
;
937 TRACE("%p\n", ppEnumerator
);
941 new_enum
= HeapAlloc(GetProcessHeap(), 0, sizeof(*new_enum
));
943 return E_OUTOFMEMORY
;
945 new_enum
->Vtbl
= &InstalledRuntimeEnum_Vtbl
;
949 *ppEnumerator
= (IEnumUnknown
*)new_enum
;
954 static HRESULT WINAPI
CLRMetaHost_EnumerateLoadedRuntimes(ICLRMetaHost
* iface
,
955 HANDLE hndProcess
, IEnumUnknown
**ppEnumerator
)
957 FIXME("%p %p\n", hndProcess
, ppEnumerator
);
962 static HRESULT WINAPI
CLRMetaHost_RequestRuntimeLoadedNotification(ICLRMetaHost
* iface
,
963 RuntimeLoadedCallbackFnPtr pCallbackFunction
)
965 FIXME("%p\n", pCallbackFunction
);
970 static HRESULT WINAPI
CLRMetaHost_QueryLegacyV2RuntimeBinding(ICLRMetaHost
* iface
,
971 REFIID riid
, LPVOID
*ppUnk
)
973 FIXME("%s %p\n", debugstr_guid(riid
), ppUnk
);
978 static HRESULT WINAPI
CLRMetaHost_ExitProcess(ICLRMetaHost
* iface
, INT32 iExitCode
)
980 FIXME("%i: stub\n", iExitCode
);
982 ExitProcess(iExitCode
);
985 static const struct ICLRMetaHostVtbl CLRMetaHost_vtbl
=
987 CLRMetaHost_QueryInterface
,
990 CLRMetaHost_GetRuntime
,
991 CLRMetaHost_GetVersionFromFile
,
992 CLRMetaHost_EnumerateInstalledRuntimes
,
993 CLRMetaHost_EnumerateLoadedRuntimes
,
994 CLRMetaHost_RequestRuntimeLoadedNotification
,
995 CLRMetaHost_QueryLegacyV2RuntimeBinding
,
996 CLRMetaHost_ExitProcess
999 static const struct CLRMetaHost GlobalCLRMetaHost
= {
1003 extern HRESULT
CLRMetaHost_CreateInstance(REFIID riid
, void **ppobj
)
1005 return ICLRMetaHost_QueryInterface((ICLRMetaHost
*)&GlobalCLRMetaHost
, riid
, ppobj
);
1008 HRESULT
get_runtime_info(LPCWSTR exefile
, LPCWSTR version
, LPCWSTR config_file
,
1009 DWORD startup_flags
, DWORD runtimeinfo_flags
, BOOL legacy
, ICLRRuntimeInfo
**result
)
1011 static const DWORD supported_startup_flags
= 0;
1012 static const DWORD supported_runtime_flags
= RUNTIME_INFO_UPGRADE_VERSION
;
1014 WCHAR local_version
[MAX_PATH
];
1015 ULONG local_version_size
= MAX_PATH
;
1019 FIXME("ignoring config filename %s\n", debugstr_w(config_file
));
1021 if (startup_flags
& ~supported_startup_flags
)
1022 FIXME("unsupported startup flags %x\n", startup_flags
& ~supported_startup_flags
);
1024 if (runtimeinfo_flags
& ~supported_runtime_flags
)
1025 FIXME("unsupported runtimeinfo flags %x\n", runtimeinfo_flags
& ~supported_runtime_flags
);
1027 if (exefile
&& !version
)
1029 hr
= CLRMetaHost_GetVersionFromFile(0, exefile
, local_version
, &local_version_size
);
1031 version
= local_version
;
1033 if (FAILED(hr
)) return hr
;
1038 return CLRMetaHost_GetRuntime(0, version
, &IID_ICLRRuntimeInfo
, (void**)result
);
1041 if (runtimeinfo_flags
& RUNTIME_INFO_UPGRADE_VERSION
)
1052 if (runtimes
[i
].mono_abi_version
)
1053 return IUnknown_QueryInterface((IUnknown
*)&runtimes
[i
],
1054 &IID_ICLRRuntimeInfo
, (void**)result
);
1057 ERR("No %s.NET runtime installed\n", legacy
? "legacy " : "");
1059 return CLR_E_SHIM_RUNTIME
;
1062 return CLR_E_SHIM_RUNTIME
;
1065 HRESULT
force_get_runtime_info(ICLRRuntimeInfo
**result
)
1067 return IUnknown_QueryInterface((IUnknown
*)&runtimes
[0], &IID_ICLRRuntimeInfo
, (void**)result
);