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 static HRESULT
load_mono(CLRRuntimeInfo
*This
, loaded_mono
**result
)
77 static HRESULT
CLRRuntimeInfo_GetRuntimeHost(CLRRuntimeInfo
*This
, RuntimeHost
**result
)
80 loaded_mono
*ploaded_mono
;
82 if (This
->loaded_runtime
)
84 *result
= This
->loaded_runtime
;
88 EnterCriticalSection(&runtime_list_cs
);
90 hr
= load_mono(This
, &ploaded_mono
);
93 hr
= RuntimeHost_Construct(This
, ploaded_mono
, &This
->loaded_runtime
);
95 LeaveCriticalSection(&runtime_list_cs
);
98 *result
= This
->loaded_runtime
;
103 void unload_all_runtimes(void)
107 for (i
=0; i
<NUM_RUNTIMES
; i
++)
108 if (runtimes
[i
].loaded_runtime
)
109 RuntimeHost_Destroy(runtimes
[i
].loaded_runtime
);
112 static HRESULT WINAPI
CLRRuntimeInfo_QueryInterface(ICLRRuntimeInfo
* iface
,
116 TRACE("%p %s %p\n", iface
, debugstr_guid(riid
), ppvObject
);
118 if ( IsEqualGUID( riid
, &IID_ICLRRuntimeInfo
) ||
119 IsEqualGUID( riid
, &IID_IUnknown
) )
125 FIXME("Unsupported interface %s\n", debugstr_guid(riid
));
126 return E_NOINTERFACE
;
129 ICLRRuntimeInfo_AddRef( iface
);
134 static ULONG WINAPI
CLRRuntimeInfo_AddRef(ICLRRuntimeInfo
* iface
)
139 static ULONG WINAPI
CLRRuntimeInfo_Release(ICLRRuntimeInfo
* iface
)
144 static HRESULT WINAPI
CLRRuntimeInfo_GetVersionString(ICLRRuntimeInfo
* iface
,
145 LPWSTR pwzBuffer
, DWORD
*pcchBuffer
)
147 struct CLRRuntimeInfo
*This
= (struct CLRRuntimeInfo
*)iface
;
148 DWORD buffer_size
= *pcchBuffer
;
153 TRACE("%p %p %p\n", iface
, pwzBuffer
, pcchBuffer
);
155 size
= snprintf(version
, sizeof(version
), "v%u.%u.%u", This
->major
, This
->minor
, This
->build
);
157 assert(size
<= sizeof(version
));
159 *pcchBuffer
= MultiByteToWideChar(CP_UTF8
, 0, version
, -1, NULL
, 0);
163 if (buffer_size
>= *pcchBuffer
)
164 MultiByteToWideChar(CP_UTF8
, 0, version
, -1, pwzBuffer
, buffer_size
);
166 hr
= HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
172 static BOOL
get_install_root(LPWSTR install_dir
)
174 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};
175 const WCHAR install_root
[] = {'I','n','s','t','a','l','l','R','o','o','t',0};
180 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, dotnet_key
, 0, KEY_READ
, &key
))
184 if (RegQueryValueExW(key
, install_root
, 0, NULL
, (LPBYTE
)install_dir
, &len
))
194 static HRESULT WINAPI
CLRRuntimeInfo_GetRuntimeDirectory(ICLRRuntimeInfo
* iface
,
195 LPWSTR pwzBuffer
, DWORD
*pcchBuffer
)
197 static const WCHAR slash
[] = {'\\',0};
198 DWORD buffer_size
= *pcchBuffer
;
199 WCHAR system_dir
[MAX_PATH
];
200 WCHAR version
[MAX_PATH
];
201 DWORD version_size
, size
;
204 TRACE("%p %p %p\n", iface
, pwzBuffer
, pcchBuffer
);
206 if (!get_install_root(system_dir
))
208 ERR("error reading registry key for installroot\n");
213 version_size
= MAX_PATH
;
214 ICLRRuntimeInfo_GetVersionString(iface
, version
, &version_size
);
215 lstrcatW(system_dir
, version
);
216 lstrcatW(system_dir
, slash
);
217 size
= lstrlenW(system_dir
) + 1;
224 if (buffer_size
>= size
)
225 strcpyW(pwzBuffer
, system_dir
);
227 hr
= HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
233 static HRESULT WINAPI
CLRRuntimeInfo_IsLoaded(ICLRRuntimeInfo
* iface
,
234 HANDLE hndProcess
, BOOL
*pbLoaded
)
236 FIXME("%p %p %p\n", iface
, hndProcess
, pbLoaded
);
241 static HRESULT WINAPI
CLRRuntimeInfo_LoadErrorString(ICLRRuntimeInfo
* iface
,
242 UINT iResourceID
, LPWSTR pwzBuffer
, DWORD
*pcchBuffer
, LONG iLocaleid
)
244 FIXME("%p %u %p %p %x\n", iface
, iResourceID
, pwzBuffer
, pcchBuffer
, iLocaleid
);
249 static HRESULT WINAPI
CLRRuntimeInfo_LoadLibrary(ICLRRuntimeInfo
* iface
,
250 LPCWSTR pwzDllName
, HMODULE
*phndModule
)
252 WCHAR version
[MAX_PATH
];
256 TRACE("%p %s %p\n", iface
, debugstr_w(pwzDllName
), phndModule
);
258 cchBuffer
= MAX_PATH
;
259 hr
= ICLRRuntimeInfo_GetVersionString(iface
, version
, &cchBuffer
);
260 if (FAILED(hr
)) return hr
;
262 return LoadLibraryShim(pwzDllName
, version
, NULL
, phndModule
);
265 static HRESULT WINAPI
CLRRuntimeInfo_GetProcAddress(ICLRRuntimeInfo
* iface
,
266 LPCSTR pszProcName
, LPVOID
*ppProc
)
268 FIXME("%p %s %p\n", iface
, debugstr_a(pszProcName
), ppProc
);
273 static HRESULT WINAPI
CLRRuntimeInfo_GetInterface(ICLRRuntimeInfo
* iface
,
274 REFCLSID rclsid
, REFIID riid
, LPVOID
*ppUnk
)
276 struct CLRRuntimeInfo
*This
= (struct CLRRuntimeInfo
*)iface
;
280 TRACE("%p %s %s %p\n", iface
, debugstr_guid(rclsid
), debugstr_guid(riid
), ppUnk
);
282 hr
= CLRRuntimeInfo_GetRuntimeHost(This
, &host
);
285 hr
= RuntimeHost_GetInterface(host
, rclsid
, riid
, ppUnk
);
290 static HRESULT WINAPI
CLRRuntimeInfo_IsLoadable(ICLRRuntimeInfo
* iface
,
293 FIXME("%p %p\n", iface
, pbLoadable
);
298 static HRESULT WINAPI
CLRRuntimeInfo_SetDefaultStartupFlags(ICLRRuntimeInfo
* iface
,
299 DWORD dwStartupFlags
, LPCWSTR pwzHostConfigFile
)
301 FIXME("%p %x %s\n", iface
, dwStartupFlags
, debugstr_w(pwzHostConfigFile
));
306 static HRESULT WINAPI
CLRRuntimeInfo_GetDefaultStartupFlags(ICLRRuntimeInfo
* iface
,
307 DWORD
*pdwStartupFlags
, LPWSTR pwzHostConfigFile
, DWORD
*pcchHostConfigFile
)
309 FIXME("%p %p %p %p\n", iface
, pdwStartupFlags
, pwzHostConfigFile
, pcchHostConfigFile
);
314 static HRESULT WINAPI
CLRRuntimeInfo_BindAsLegacyV2Runtime(ICLRRuntimeInfo
* iface
)
316 FIXME("%p\n", iface
);
321 static HRESULT WINAPI
CLRRuntimeInfo_IsStarted(ICLRRuntimeInfo
* iface
,
322 BOOL
*pbStarted
, DWORD
*pdwStartupFlags
)
324 FIXME("%p %p %p\n", iface
, pbStarted
, pdwStartupFlags
);
329 const struct ICLRRuntimeInfoVtbl CLRRuntimeInfoVtbl
= {
330 CLRRuntimeInfo_QueryInterface
,
331 CLRRuntimeInfo_AddRef
,
332 CLRRuntimeInfo_Release
,
333 CLRRuntimeInfo_GetVersionString
,
334 CLRRuntimeInfo_GetRuntimeDirectory
,
335 CLRRuntimeInfo_IsLoaded
,
336 CLRRuntimeInfo_LoadErrorString
,
337 CLRRuntimeInfo_LoadLibrary
,
338 CLRRuntimeInfo_GetProcAddress
,
339 CLRRuntimeInfo_GetInterface
,
340 CLRRuntimeInfo_IsLoadable
,
341 CLRRuntimeInfo_SetDefaultStartupFlags
,
342 CLRRuntimeInfo_GetDefaultStartupFlags
,
343 CLRRuntimeInfo_BindAsLegacyV2Runtime
,
344 CLRRuntimeInfo_IsStarted
347 static BOOL
find_mono_dll(LPCWSTR path
, LPWSTR dll_path
, int abi_version
)
349 static const WCHAR mono_dll
[] = {'\\','b','i','n','\\','m','o','n','o','.','d','l','l',0};
350 static const WCHAR libmono_dll
[] = {'\\','b','i','n','\\','l','i','b','m','o','n','o','.','d','l','l',0};
351 DWORD attributes
=INVALID_FILE_ATTRIBUTES
;
353 if (abi_version
== 1)
355 strcpyW(dll_path
, path
);
356 strcatW(dll_path
, mono_dll
);
357 attributes
= GetFileAttributesW(dll_path
);
359 if (attributes
== INVALID_FILE_ATTRIBUTES
)
361 strcpyW(dll_path
, path
);
362 strcatW(dll_path
, libmono_dll
);
363 attributes
= GetFileAttributesW(dll_path
);
367 return (attributes
!= INVALID_FILE_ATTRIBUTES
);
370 static BOOL
get_mono_path_from_registry(LPWSTR path
, int abi_version
)
372 static const WCHAR mono_key
[] = {'S','o','f','t','w','a','r','e','\\','N','o','v','e','l','l','\\','M','o','n','o',0};
373 static const WCHAR defaul_clr
[] = {'D','e','f','a','u','l','t','C','L','R',0};
374 static const WCHAR install_root
[] = {'S','d','k','I','n','s','t','a','l','l','R','o','o','t',0};
375 static const WCHAR slash
[] = {'\\',0};
377 WCHAR version
[64], version_key
[MAX_PATH
];
380 WCHAR dll_path
[MAX_PATH
];
382 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, mono_key
, 0, KEY_READ
, &key
))
385 len
= sizeof(version
);
386 if (RegQueryValueExW(key
, defaul_clr
, 0, NULL
, (LPBYTE
)version
, &len
))
393 lstrcpyW(version_key
, mono_key
);
394 lstrcatW(version_key
, slash
);
395 lstrcatW(version_key
, version
);
397 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, version_key
, 0, KEY_READ
, &key
))
400 len
= sizeof(WCHAR
) * MAX_PATH
;
401 if (RegQueryValueExW(key
, install_root
, 0, NULL
, (LPBYTE
)path
, &len
))
408 return find_mono_dll(path
, dll_path
, abi_version
);
411 static BOOL
get_mono_path_from_folder(LPCWSTR folder
, LPWSTR mono_path
, int abi_version
)
413 static const WCHAR mono_one_dot_zero
[] = {'\\','m','o','n','o','-','1','.','0', 0};
414 WCHAR mono_dll_path
[MAX_PATH
];
417 strcpyW(mono_path
, folder
);
419 if (abi_version
== 1)
420 strcatW(mono_path
, mono_one_dot_zero
);
422 found
= find_mono_dll(mono_path
, mono_dll_path
, abi_version
);
427 static BOOL
get_mono_path(LPWSTR path
, int abi_version
)
429 static const WCHAR subdir_mono
[] = {'\\','m','o','n','o',0};
430 static const WCHAR sibling_mono
[] = {'\\','.','.','\\','m','o','n','o',0};
431 WCHAR base_path
[MAX_PATH
];
432 const char *unix_data_dir
;
435 static WCHAR
* (CDECL
*wine_get_dos_file_name
)(const char*);
437 /* First try c:\windows\mono */
438 GetWindowsDirectoryW(base_path
, MAX_PATH
);
439 strcatW(base_path
, subdir_mono
);
441 if (get_mono_path_from_folder(base_path
, path
, abi_version
))
444 /* Next: /usr/share/wine/mono */
445 unix_data_dir
= wine_get_data_dir();
449 unix_data_dir
= wine_get_build_dir();
455 if (!wine_get_dos_file_name
)
456 wine_get_dos_file_name
= (void*)GetProcAddress(GetModuleHandleA("kernel32"), "wine_get_dos_file_name");
458 if (wine_get_dos_file_name
)
460 dos_data_dir
= wine_get_dos_file_name(unix_data_dir
);
464 strcpyW(base_path
, dos_data_dir
);
465 strcatW(base_path
, build_tree
? sibling_mono
: subdir_mono
);
467 HeapFree(GetProcessHeap(), 0, dos_data_dir
);
469 if (get_mono_path_from_folder(base_path
, path
, abi_version
))
475 /* Last: the registry */
476 return get_mono_path_from_registry(path
, abi_version
);
479 static void find_runtimes(void)
482 static const WCHAR libmono
[] = {'\\','l','i','b','\\','m','o','n','o','\\',0};
483 static const WCHAR mscorlib
[] = {'\\','m','s','c','o','r','l','i','b','.','d','l','l',0};
484 WCHAR mono_path
[MAX_PATH
], lib_path
[MAX_PATH
];
485 BOOL any_runtimes_found
= FALSE
;
487 if (runtimes_initialized
) return;
489 EnterCriticalSection(&runtime_list_cs
);
491 if (runtimes_initialized
) goto end
;
493 for (abi_version
=1; abi_version
>0; abi_version
--)
495 if (!get_mono_path(mono_path
, abi_version
))
498 for (i
=0; i
<NUM_RUNTIMES
; i
++)
500 if (runtimes
[i
].mono_abi_version
== 0)
502 strcpyW(lib_path
, mono_path
);
503 strcatW(lib_path
, libmono
);
504 strcatW(lib_path
, runtimes
[i
].mono_libdir
);
505 strcatW(lib_path
, mscorlib
);
507 if (GetFileAttributesW(lib_path
) != INVALID_FILE_ATTRIBUTES
)
509 runtimes
[i
].mono_abi_version
= abi_version
;
511 strcpyW(runtimes
[i
].mono_path
, mono_path
);
512 strcpyW(runtimes
[i
].mscorlib_path
, lib_path
);
514 any_runtimes_found
= TRUE
;
520 runtimes_initialized
= 1;
522 if (!any_runtimes_found
)
523 MESSAGE("wine: Install the Windows version of Mono to run .NET executables\n");
526 LeaveCriticalSection(&runtime_list_cs
);
529 struct InstalledRuntimeEnum
531 const struct IEnumUnknownVtbl
*Vtbl
;
536 const struct IEnumUnknownVtbl InstalledRuntimeEnum_Vtbl
;
538 static HRESULT WINAPI
InstalledRuntimeEnum_QueryInterface(IEnumUnknown
* iface
,
542 TRACE("%p %s %p\n", iface
, debugstr_guid(riid
), ppvObject
);
544 if ( IsEqualGUID( riid
, &IID_IEnumUnknown
) ||
545 IsEqualGUID( riid
, &IID_IUnknown
) )
551 FIXME("Unsupported interface %s\n", debugstr_guid(riid
));
552 return E_NOINTERFACE
;
555 IEnumUnknown_AddRef( iface
);
560 static ULONG WINAPI
InstalledRuntimeEnum_AddRef(IEnumUnknown
* iface
)
562 struct InstalledRuntimeEnum
*This
= (struct InstalledRuntimeEnum
*)iface
;
563 ULONG ref
= InterlockedIncrement(&This
->ref
);
565 TRACE("(%p) refcount=%u\n", iface
, ref
);
570 static ULONG WINAPI
InstalledRuntimeEnum_Release(IEnumUnknown
* iface
)
572 struct InstalledRuntimeEnum
*This
= (struct InstalledRuntimeEnum
*)iface
;
573 ULONG ref
= InterlockedDecrement(&This
->ref
);
575 TRACE("(%p) refcount=%u\n", iface
, ref
);
579 HeapFree(GetProcessHeap(), 0, This
);
585 static HRESULT WINAPI
InstalledRuntimeEnum_Next(IEnumUnknown
*iface
, ULONG celt
,
586 IUnknown
**rgelt
, ULONG
*pceltFetched
)
588 struct InstalledRuntimeEnum
*This
= (struct InstalledRuntimeEnum
*)iface
;
593 TRACE("(%p,%u,%p,%p)\n", iface
, celt
, rgelt
, pceltFetched
);
595 while (num_fetched
< celt
)
597 if (This
->pos
>= NUM_RUNTIMES
)
602 if (runtimes
[This
->pos
].mono_abi_version
)
604 item
= (IUnknown
*)&runtimes
[This
->pos
];
605 IUnknown_AddRef(item
);
606 rgelt
[num_fetched
] = item
;
613 *pceltFetched
= num_fetched
;
618 static HRESULT WINAPI
InstalledRuntimeEnum_Skip(IEnumUnknown
*iface
, ULONG celt
)
620 struct InstalledRuntimeEnum
*This
= (struct InstalledRuntimeEnum
*)iface
;
624 TRACE("(%p,%u)\n", iface
, celt
);
626 while (num_fetched
< celt
)
628 if (This
->pos
>= NUM_RUNTIMES
)
633 if (runtimes
[This
->pos
].mono_abi_version
)
643 static HRESULT WINAPI
InstalledRuntimeEnum_Reset(IEnumUnknown
*iface
)
645 struct InstalledRuntimeEnum
*This
= (struct InstalledRuntimeEnum
*)iface
;
647 TRACE("(%p)\n", iface
);
654 static HRESULT WINAPI
InstalledRuntimeEnum_Clone(IEnumUnknown
*iface
, IEnumUnknown
**ppenum
)
656 struct InstalledRuntimeEnum
*This
= (struct InstalledRuntimeEnum
*)iface
;
657 struct InstalledRuntimeEnum
*new_enum
;
659 TRACE("(%p)\n", iface
);
661 new_enum
= HeapAlloc(GetProcessHeap(), 0, sizeof(*new_enum
));
663 return E_OUTOFMEMORY
;
665 new_enum
->Vtbl
= &InstalledRuntimeEnum_Vtbl
;
667 new_enum
->pos
= This
->pos
;
669 *ppenum
= (IEnumUnknown
*)new_enum
;
674 const struct IEnumUnknownVtbl InstalledRuntimeEnum_Vtbl
= {
675 InstalledRuntimeEnum_QueryInterface
,
676 InstalledRuntimeEnum_AddRef
,
677 InstalledRuntimeEnum_Release
,
678 InstalledRuntimeEnum_Next
,
679 InstalledRuntimeEnum_Skip
,
680 InstalledRuntimeEnum_Reset
,
681 InstalledRuntimeEnum_Clone
686 const struct ICLRMetaHostVtbl
*CLRMetaHost_vtbl
;
689 static const struct CLRMetaHost GlobalCLRMetaHost
;
691 static HRESULT WINAPI
CLRMetaHost_QueryInterface(ICLRMetaHost
* iface
,
695 TRACE("%s %p\n", debugstr_guid(riid
), ppvObject
);
697 if ( IsEqualGUID( riid
, &IID_ICLRMetaHost
) ||
698 IsEqualGUID( riid
, &IID_IUnknown
) )
704 FIXME("Unsupported interface %s\n", debugstr_guid(riid
));
705 return E_NOINTERFACE
;
708 ICLRMetaHost_AddRef( iface
);
713 static ULONG WINAPI
CLRMetaHost_AddRef(ICLRMetaHost
* iface
)
718 static ULONG WINAPI
CLRMetaHost_Release(ICLRMetaHost
* iface
)
723 static BOOL
parse_runtime_version(LPCWSTR version
, DWORD
*major
, DWORD
*minor
, DWORD
*build
)
729 if (version
[0] == 'v')
732 if (!isdigit(*version
))
735 while (isdigit(*version
))
736 *major
= *major
* 10 + (*version
++ - '0');
741 if (*version
++ != '.' || !isdigit(*version
))
744 while (isdigit(*version
))
745 *minor
= *minor
* 10 + (*version
++ - '0');
750 if (*version
++ != '.' || !isdigit(*version
))
753 while (isdigit(*version
))
754 *build
= *build
* 10 + (*version
++ - '0');
756 return *version
== 0;
762 static HRESULT WINAPI
CLRMetaHost_GetRuntime(ICLRMetaHost
* iface
,
763 LPCWSTR pwzVersion
, REFIID iid
, LPVOID
*ppRuntime
)
766 DWORD major
, minor
, build
;
768 TRACE("%s %s %p\n", debugstr_w(pwzVersion
), debugstr_guid(iid
), ppRuntime
);
773 if (!parse_runtime_version(pwzVersion
, &major
, &minor
, &build
))
775 ERR("Cannot parse %s\n", debugstr_w(pwzVersion
));
776 return CLR_E_SHIM_RUNTIME
;
781 for (i
=0; i
<NUM_RUNTIMES
; i
++)
783 if (runtimes
[i
].major
== major
&& runtimes
[i
].minor
== minor
&&
784 runtimes
[i
].build
== build
)
786 if (runtimes
[i
].mono_abi_version
)
787 return IUnknown_QueryInterface((IUnknown
*)&runtimes
[i
], iid
, ppRuntime
);
790 ERR("Mono is missing %s runtime\n", debugstr_w(pwzVersion
));
791 return CLR_E_SHIM_RUNTIME
;
796 FIXME("Unrecognized version %s\n", debugstr_w(pwzVersion
));
797 return CLR_E_SHIM_RUNTIME
;
800 static HRESULT WINAPI
CLRMetaHost_GetVersionFromFile(ICLRMetaHost
* iface
,
801 LPCWSTR pwzFilePath
, LPWSTR pwzBuffer
, DWORD
*pcchBuffer
)
806 ULONG buffer_size
=*pcchBuffer
;
808 TRACE("%s %p %p\n", debugstr_w(pwzFilePath
), pwzBuffer
, pcchBuffer
);
810 hr
= assembly_create(&assembly
, pwzFilePath
);
814 hr
= assembly_get_runtime_version(assembly
, &version
);
818 *pcchBuffer
= MultiByteToWideChar(CP_UTF8
, 0, version
, -1, NULL
, 0);
822 if (buffer_size
>= *pcchBuffer
)
823 MultiByteToWideChar(CP_UTF8
, 0, version
, -1, pwzBuffer
, buffer_size
);
825 hr
= HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
829 assembly_release(assembly
);
835 static HRESULT WINAPI
CLRMetaHost_EnumerateInstalledRuntimes(ICLRMetaHost
* iface
,
836 IEnumUnknown
**ppEnumerator
)
838 struct InstalledRuntimeEnum
*new_enum
;
840 TRACE("%p\n", ppEnumerator
);
844 new_enum
= HeapAlloc(GetProcessHeap(), 0, sizeof(*new_enum
));
846 return E_OUTOFMEMORY
;
848 new_enum
->Vtbl
= &InstalledRuntimeEnum_Vtbl
;
852 *ppEnumerator
= (IEnumUnknown
*)new_enum
;
857 static HRESULT WINAPI
CLRMetaHost_EnumerateLoadedRuntimes(ICLRMetaHost
* iface
,
858 HANDLE hndProcess
, IEnumUnknown
**ppEnumerator
)
860 FIXME("%p %p\n", hndProcess
, ppEnumerator
);
865 static HRESULT WINAPI
CLRMetaHost_RequestRuntimeLoadedNotification(ICLRMetaHost
* iface
,
866 RuntimeLoadedCallbackFnPtr pCallbackFunction
)
868 FIXME("%p\n", pCallbackFunction
);
873 static HRESULT WINAPI
CLRMetaHost_QueryLegacyV2RuntimeBinding(ICLRMetaHost
* iface
,
874 REFIID riid
, LPVOID
*ppUnk
)
876 FIXME("%s %p\n", debugstr_guid(riid
), ppUnk
);
881 static HRESULT WINAPI
CLRMetaHost_ExitProcess(ICLRMetaHost
* iface
, INT32 iExitCode
)
883 FIXME("%i: stub\n", iExitCode
);
885 ExitProcess(iExitCode
);
888 static const struct ICLRMetaHostVtbl CLRMetaHost_vtbl
=
890 CLRMetaHost_QueryInterface
,
893 CLRMetaHost_GetRuntime
,
894 CLRMetaHost_GetVersionFromFile
,
895 CLRMetaHost_EnumerateInstalledRuntimes
,
896 CLRMetaHost_EnumerateLoadedRuntimes
,
897 CLRMetaHost_RequestRuntimeLoadedNotification
,
898 CLRMetaHost_QueryLegacyV2RuntimeBinding
,
899 CLRMetaHost_ExitProcess
902 static const struct CLRMetaHost GlobalCLRMetaHost
= {
906 extern HRESULT
CLRMetaHost_CreateInstance(REFIID riid
, void **ppobj
)
908 return ICLRMetaHost_QueryInterface((ICLRMetaHost
*)&GlobalCLRMetaHost
, riid
, ppobj
);
911 HRESULT
get_runtime_info(LPCWSTR exefile
, LPCWSTR version
, LPCWSTR config_file
,
912 DWORD startup_flags
, DWORD runtimeinfo_flags
, BOOL legacy
, ICLRRuntimeInfo
**result
)
914 static const DWORD supported_startup_flags
= 0;
915 static const DWORD supported_runtime_flags
= RUNTIME_INFO_UPGRADE_VERSION
;
919 FIXME("ignoring exe filename %s\n", debugstr_w(exefile
));
922 FIXME("ignoring config filename %s\n", debugstr_w(config_file
));
924 if (startup_flags
& ~supported_startup_flags
)
925 FIXME("unsupported startup flags %x\n", startup_flags
& ~supported_startup_flags
);
927 if (runtimeinfo_flags
& ~supported_runtime_flags
)
928 FIXME("unsupported runtimeinfo flags %x\n", runtimeinfo_flags
& ~supported_runtime_flags
);
932 return CLRMetaHost_GetRuntime(0, version
, &IID_ICLRRuntimeInfo
, (void**)result
);
935 if (runtimeinfo_flags
& RUNTIME_INFO_UPGRADE_VERSION
)
946 if (runtimes
[i
].mono_abi_version
)
947 return IUnknown_QueryInterface((IUnknown
*)&runtimes
[i
],
948 &IID_ICLRRuntimeInfo
, (void**)result
);
951 ERR("No %s.NET runtime installed\n", legacy
? "legacy " : "");
953 return CLR_E_SHIM_RUNTIME
;
956 return CLR_E_SHIM_RUNTIME
;
959 HRESULT
force_get_runtime_info(ICLRRuntimeInfo
**result
)
961 return IUnknown_QueryInterface((IUnknown
*)&runtimes
[0], &IID_ICLRRuntimeInfo
, (void**)result
);