This evening was a WPDUG meeting on CLR hosting and CLR profiling. Thank you all for coming! It was a pleasure to see so many of you there. My session was on CLR hosting, using the new CLR 4 hosting API. This is done using native code (C++) that uses COM for communication between the CLR and the host, both ways.
I showed how to enumerate the installed runtimes, how to load a specific CLR (a new feature of CLR 4 – the ability to host multiple CLRs in a single process), how to create an application domain (all from native code, of course). The interesting parts are the interfaces used to call on the CLR and the host implementations for CLR usage.
After a ICLRRuntimeInfo interface is obtained, a call to GetInterface allows getting some functionality aspect from the CLR. The most interesting interfaces are ICLRRuntimeHost (new in CLR 4) and ICorRuntimeHost (the old one, but has functionality not available in the new one).
From the ICLRRuntimeHost, you can call GetCLRControl and from there get a management aspect object from the CLR. You can browse the presentation attached to the end of this post and the source code examples. In the other direction, calling ICLRRuntimeHost::SetHostControl allows the host to supply its objects for controlling various aspects of the execution, such as notifications for GC, memory management and more.
In the code sample, one can choose a CLR to work with, and execute some managed executable in some app domain, while at the same time get indications on GC and memory related activities. This is, of course, just the tip of the iceberg.
Comments List