Note that there are some explanatory texts on larger screens.

plurals
  1. POHosting CLR Runtime in C++
    primarykey
    data
    text
    <p>I am working on an extension for a project that will allow hosting the CLR inside the core application. With this I plan to allow this extension to manage managed extensions that it loads/unloads inside itself. That being said, I need to use separate AppDomains to ensure unloading is possible.</p> <p>Currently, I am able to get the domains setup and get the plugin file loaded but at that point I'm stuck. I'm not sure how to call functions inside the domains loaded assembly at will and so on.</p> <p>Here is my loading setup so far, minus error checking and such:</p> <pre class="lang-c prettyprint-override"><code>ICorRuntimeHost* lpRuntimeHost = NULL; CorBindToRuntimeEx( L"v4.0.30319", L"wks", 0, CLSID_CorRuntimeHost, IID_PPV_ARGS( &amp;lpRuntimeHost ) ); lpRuntimeHost-&gt;Start(); // File data read from disk. // Dll file just CreateFile/ReadFile and insert into pluginFileData. CComSafeArray&lt;BYTE&gt; pluginFileData; IUnknown* lpUnknown = NULL; lpRuntimeHost-&gt;CreateDomain( wstrPlugin.c_str(), NULL, &amp;lpUnknown ); CComPtr&lt;_AppDomain&gt; appDomain = NULL; lpUnknown-&gt;QueryInterface( &amp;appDomain.p ); CComPtr&lt;_Assembly&gt; appAssembly = NULL; hResult = appDomain-&gt;Load_3( pluginFileData, &amp;appAssembly ); </code></pre> <p>I have a class library that all plugins must reference and use in order to be considered a plugin. Which so far is nothing more than a base class to inherit:</p> <pre class="lang-csharp prettyprint-override"><code>namespace FrameworkAPI { public class IFrameworkPlugin { public override bool Initialize(IntPtr interfaceObj) { return false; } } } </code></pre> <p>And then an extension would reference that class library and use that as its base:</p> <pre class="lang-csharp prettyprint-override"><code>namespace ClassLibrary1 { public class Main : IFrameworkPlugin { public override bool Initialize(IntPtr interfaceObj) { // Return true to stay loaded. return true; } } } </code></pre> <p>What I am stuck at is how to do a few things:</p> <ul> <li>How can I obtain the main class but as the base to invoke methods in the base that allow the main class to still handle?</li> <li>How can I ensure that the main class inherits the base so I can ensure its a valid plugin file?</li> <li>How I can freely invoke methods from the C++ side to fire events in the C# plugin.</li> </ul> <p>For the firing events, the C++ plugin will call more things in the C# plugins once they are loaded, such as rendering events, command handling, etc.</p> <p>Most of the examples I find online are specific to requiring the entire C# side to be static which I don't want. Also most do not use separate AppDomains and rather all execute in the default. I don't want this since it limits being able to unload a specific plugin.</p> <p>If any other info is missing and needed feel free to let me know.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload