title: Unresolved external symbol CLRCreateInstance
body: <p>I wrote some native C++ code with the help of the Internet that loads the .NET Runtime and invokes a method that has the signature: <code>public static int MethodNameHere(String pwzArgument)</code> from a class in a managed assembly.</p>
  
  <p>However, I can't seem to compile the code using Visual Studio into a native DLL (64-bit), because there seems to be a linking issue with <a href="https://msdn.microsoft.com/en-us/library/dd537633%28v=vs.110%29.aspx" rel="nofollow">CLRCreateInstance()</a>, even though I am including <code>"MetaHost.h"</code> in the .cpp source file.</p>
  
  <p>Here is the entire code:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include "MetaHost.h"
  
  extern "C" {
      __declspec(dllexport) DWORD __stdcall CallManagedMethod(LPCWSTR managedDLLPath, LPCWSTR classPathInAssembly, LPCWSTR methodName, LPCWSTR parameter) {
          // Bind to the CLR runtime..
          ICLRMetaHost* pMetaHost = nullptr;
          CLRCreateInstance(CLSID_CLRMetaHost, IID_ICLRMetaHost, (LPVOID*) &amp;pMetaHost);
  
          ICLRRuntimeInfo* pRuntimeInfo = nullptr;
          pMetaHost-&gt;GetRuntime(L"v4.0.30319", IID_ICLRRuntimeInfo, (LPVOID*) &amp;pRuntimeInfo);
  
          ICLRRuntimeHost* pClrRuntimeHost = nullptr;
          pRuntimeInfo-&gt;GetInterface(CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (LPVOID*) &amp;pClrRuntimeHost);
  
          pClrRuntimeHost-&gt;Start();
  
          // Okay, the CLR is up and running in this (previously native) process.
          // Now call a method on our managed C# class library.
          DWORD dwRet = 0;
          pClrRuntimeHost-&gt;ExecuteInDefaultAppDomain(managedDLLPath, classPathInAssembly, methodName, parameter, &amp;dwRet);
  
          // Don't forget to clean up.
          pClrRuntimeHost-&gt;Release();
  
          pRuntimeInfo-&gt;Release();
          pMetaHost-&gt;Release();
          return dwRet;
      }
  }
  </code></pre>
  
  <p>Any help?</p>