Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well this is possible, but not a small amount of work. It's generally easier to create the appdomain and set configuration from the managed world and then create a small 'thunking' layer in managed code to wrap it all up for unmanaged clients. But since that isn't what you asked for, here is how you could accomplish your goal: </p> <p>First you will need to import the mscorelib:</p> <pre><code>#include &lt;mscoree.h&gt; #import &lt;mscorlib.tlb&gt; raw_interfaces_only no_smart_pointers high_property_prefixes("_get","_put","_putref") </code></pre> <p>Then bind to the runtime:</p> <pre><code>ICorRuntimeHost runtimeHost; hr = CorBindToRuntimeEx( NULL, //Retrieve latest version by default L"wks", //Request a WorkStation build of the CLR STARTUP_LOADER_OPTIMIZATION_SINGLE_DOMAIN | STARTUP_CONCURRENT_GC, CLSID_CorRuntimeHost, IID_ICorRuntimeHost, (void**)&amp;runtimeHost ); </code></pre> <p>Now startup the CLR and create an AppDomainSetup instance.</p> <pre><code>hr = runtimeHost-&gt;Start(); IAppDomainSetup pSetup; hr = runtimeHost-&gt;CreateDomainSetup(&amp;pSetup); </code></pre> <p>Now fill in the setup information as appropriate:</p> <pre><code>hr = pSetup-&gt;put_ApplicationBase(_bstr_t(thisFile)); hr = pSetup-&gt;put_ConfigurationFile(_bstr_t(configFile)); </code></pre> <p>Finally create the domain:</p> <pre><code>hr = __gRuntimeHost-&gt;CreateDomainEx(L"ISAPI.Net", pSetup, NULL, &amp;pDomain); </code></pre> <p>Now you can optionally instantiate an object and call methods:</p> <pre><code>hr = pDomain-&gt;CreateInstanceFrom(_bstr_t(assemblyFile), _bstr_t("Namespace.ClassName"), &amp;pObjectHandle); VARIANT vtUnwrapped; hr = spObjectHandle-&gt;Unwrap(&amp;vtUnwrapped); IDispatch pDisp = vtUnwrapped.pdispVal; DISPID dispid; DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0}; hr = pDisp-&gt;GetIDsOfNames ( IID_NULL, szMemberName, 1, LOCALE_SYSTEM_DEFAULT, &amp;dispid ); hr = pDisp-&gt;Invoke ( dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD, &amp;dispparamsNoArgs, NULL, NULL, NULL ); </code></pre> <p>Obviously the code fragments above are incomplete; however, if your adept enough at C++ COM the above should provide you with enough information to work it out. You should note that this is the 'old' (1.x) hosting interfaces which I can attest continue to work through 3.5, I have no idea how/if these work on 4.0. As of <a href="http://msdn.microsoft.com/en-us/library/ms164336%28v=VS.80%29.aspx" rel="nofollow">.Net 2.0 new hosting interfaces</a> were introduced. I've never had need of anything beyond the 1.x versions, so I never bothered to upgrade any hosting code.</p> <p>see also: <a href="http://msdn.microsoft.com/en-us/library/dd380850.aspx" rel="nofollow">Hosting Overview</a></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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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