Is there any way to get ICLRMetaHost from c++ library

820 views Asked by At

Pretty much what the question states. I have a .net exe that runs, and then loads my library (in c++). Is there any way to get the ICLRMetaHost, or similar interface, that mscoree loads when it starts up the .net exe? I want to do this primarily so I can access the gc and memory related settings from my native library for debugging purposes.

Bonus points for point out a similar implementation using the mono hosting api.

1

There are 1 answers

0
Len Holgate On

I don't see why the normal way of obtaining ICLRMetaHost wouldn't work from within a DLL that's been loaded by the CLR...

  1. LoadLibrary on mscoree.dll
  2. Find the address of CLRCreateInstance.
  3. call CLRCreateInstance as shown here to get hold of ICLRMetaHost.
  4. call EnumerateLoadedRuntimes and hope that there's only one loaded...
  5. from your enumerated runtime info obtain ICLRRuntimeHost.
  6. from ICLRRuntimeHost obtain ICLRControl
  7. from ICLRControl obtain ICLRGCManager