Ich habe mit Hilfe des Internets nativen C++ - Code geschrieben, der .NET Runtime lädt und eine Methode mit der Signatur public static int MethodNameHere(String pwzArgument)
aus einer Klasse in einer verwalteten Assembly aufruft.Nicht aufgelöstes externes Symbol CLRCreateInstance
Aber ich kann nicht scheinen, den Code mit Visual Studio in einen native DLL (64-Bit) zu kompilieren, weil es scheint, mit CLRCreateInstance() ein verbindenden Thema zu sein, obwohl ich bin auch "MetaHost.h"
in der CPP-Quelle Datei. Hier
ist der gesamte 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*) &pMetaHost);
ICLRRuntimeInfo* pRuntimeInfo = nullptr;
pMetaHost->GetRuntime(L"v4.0.30319", IID_ICLRRuntimeInfo, (LPVOID*) &pRuntimeInfo);
ICLRRuntimeHost* pClrRuntimeHost = nullptr;
pRuntimeInfo->GetInterface(CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (LPVOID*) &pClrRuntimeHost);
pClrRuntimeHost->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->ExecuteInDefaultAppDomain(managedDLLPath, classPathInAssembly, methodName, parameter, &dwRet);
// Don't forget to clean up.
pClrRuntimeHost->Release();
pRuntimeInfo->Release();
pMetaHost->Release();
return dwRet;
}
}
Jede Hilfe?
"mscoree.lib" zu Linker-Abhängigkeiten hinzugefügt und es hat funktioniert! Danke: D –