I have unmanaged dll written in C, that will be injected into managed application (dotNet 4). I am going to enumerate _AppDomains, running in this app to load some module into domain. It is available to do this using ICorRuntimeHost interface. However, ICorRuntimeHost is deprecated, and (as described there http://msdn.microsoft.com/en-en/library/ms164320%28v=vs.100%29.aspx) replaced with ICLRRuntimeHost.
How can I perform _AppDomain enumeration using ICLRRuntimeHost? Is it possible?
Amongst the debugging interfaces there is
ICorPublish.You can use the
ICorPublish::GetProcess()method to retrieve aICorPublishProcessinstance for a .NET process (identified by passing the respective process ID, which can be the ID of the current process, of course).That interface provides the method
ICorPublishProcess::EnumAppDomains(), which you can use the get a list of the current application domains in the target process, via an enumerator toICorPublishAppDomaininstances. Each of which has theICorPublishAppDomain.GetName()method that gets you the name of the application domain.Update: I have not tried this, but how about:
Using the approach above to enumerate the app domains (including getting their unique ID via
ICorPublishAppDomain.GetID()).The use
ICLRRuntimeHost::ExecuteInAppDomainto actually execute code in that domain (including loading the module you need to). The (first) parameterAppDomainIdwould be the value you get fromICorPublishAppDomain.GetID().There seems to be an, at least related, example (CppHostCLR) about that in the Microsoft All-In-One Code Framework over on codeplex.com