From 0fdee51dcfd0aa76e352fe41836cb9d367e8ee9a Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Thu, 19 May 2011 14:08:12 -0500 Subject: [PATCH 3/3] mscoree: Implement ICorRuntimeHost_GetDefaultDomain. --- dlls/mscoree/corruntimehost.c | 79 +++++++++++++++++++++++++++++++++++++++- 1 files changed, 77 insertions(+), 2 deletions(-) diff --git a/dlls/mscoree/corruntimehost.c b/dlls/mscoree/corruntimehost.c index 231295d..607537c 100644 --- a/dlls/mscoree/corruntimehost.c +++ b/dlls/mscoree/corruntimehost.c @@ -39,6 +39,10 @@ WINE_DEFAULT_DEBUG_CHANNEL( mscoree ); +#include "initguid.h" + +DEFINE_GUID(IID__AppDomain, 0x05f696dc,0x2b29,0x3663,0xad,0x8b,0xc4,0x38,0x9c,0xf2,0xa7,0x13); + struct RuntimeHost { const struct ICorRuntimeHostVtbl *lpVtbl; @@ -142,6 +146,65 @@ static void RuntimeHost_DeleteDomain(RuntimeHost *This, MonoDomain *domain) LeaveCriticalSection(&This->lock); } +static HRESULT RuntimeHost_GetIUnknownForDomain(RuntimeHost *This, MonoDomain *domain, IUnknown **punk) +{ + HRESULT hr; + void *args[0]; + MonoAssembly *assembly; + MonoImage *image; + MonoClass *klass; + MonoMethod *method; + MonoObject *appdomain_object; + IUnknown *unk; + + assembly = This->mono->mono_domain_assembly_open(domain, "mscorlib"); + if (!assembly) + { + ERR("Cannot load mscorlib\n"); + return E_FAIL; + } + + image = This->mono->mono_assembly_get_image(assembly); + if (!image) + { + ERR("Couldn't get assembly image\n"); + return E_FAIL; + } + + klass = This->mono->mono_class_from_name(image, "System", "AppDomain"); + if (!klass) + { + ERR("Couldn't get class from image\n"); + return E_FAIL; + } + + method = This->mono->mono_class_get_method_from_name(klass, "get_CurrentDomain", 0); + if (!method) + { + ERR("Couldn't get method from class\n"); + return E_FAIL; + } + + args[0] = NULL; + appdomain_object = This->mono->mono_runtime_invoke(method, NULL, args, NULL); + if (!appdomain_object) + { + ERR("Couldn't get result pointer\n"); + return E_FAIL; + } + + hr = RuntimeHost_GetIUnknownForObject(This, appdomain_object, &unk); + + if (SUCCEEDED(hr)) + { + hr = IUnknown_QueryInterface(unk, &IID__AppDomain, (void**)punk); + + IUnknown_Release(unk); + } + + return hr; +} + static inline RuntimeHost *impl_from_ICLRRuntimeHost( ICLRRuntimeHost *iface ) { return (RuntimeHost *)((char*)iface - FIELD_OFFSET(RuntimeHost, lpCLRHostVtbl)); @@ -277,8 +340,20 @@ static HRESULT WINAPI corruntimehost_GetDefaultDomain( ICorRuntimeHost* iface, IUnknown **pAppDomain) { - FIXME("stub %p\n", iface); - return E_NOTIMPL; + RuntimeHost *This = impl_from_ICorRuntimeHost( iface ); + HRESULT hr; + MonoDomain *domain; + + TRACE("(%p)\n", iface); + + hr = RuntimeHost_GetDefaultDomain(This, &domain); + + if (SUCCEEDED(hr)) + { + hr = RuntimeHost_GetIUnknownForDomain(This, domain, pAppDomain); + } + + return hr; } static HRESULT WINAPI corruntimehost_EnumDomains( -- 1.7.1