C++ ClrRuntimeHost->;开始不按预期运行
因此,我创建了一个项目,它使用CLRRunTimeHost作为托管库的超级主机 然而,我遇到了一个问题。当我运行这个程序时,它工作得非常好,没有打嗝,但是在将它分发给一些人之后,错误报告开始源源不断地出现。就在今天大约11个小时后,我已经找到了这个来源。但是,在最后一次检查或C++ ClrRuntimeHost->;开始不按预期运行,c++,clr,C++,Clr,因此,我创建了一个项目,它使用CLRRunTimeHost作为托管库的超级主机 然而,我遇到了一个问题。当我运行这个程序时,它工作得非常好,没有打嗝,但是在将它分发给一些人之后,错误报告开始源源不断地出现。就在今天大约11个小时后,我已经找到了这个来源。但是,在最后一次检查或 hr = pClrRuntimeHost->Start(); 它失败了,无法启动。我已经通过库安装等方式与所有使用它的人进行了交谈和指导,但没有人能够让它正常工作,我甚至将源代码提供给了一位安装了VS2015的亲密
hr = pClrRuntimeHost->Start();
它失败了,无法启动。我已经通过库安装等方式与所有使用它的人进行了交谈和指导,但没有人能够让它正常工作,我甚至将源代码提供给了一位安装了VS2015的亲密朋友,他也成为了同样错误的受害者
以下是完整的功能:
ICLRRuntimeHost* StartCLR(LPCWSTR dotNetVersion)
{
HRESULT hr;
ICLRMetaHost* pClrMetaHost = NULL;
ICLRRuntimeInfo* pClrRuntimeInfo = NULL;
ICLRRuntimeHost* pClrRuntimeHost = NULL;
// Get the CLRMetaHost that tells us about .NET on this machine
hr = CLRCreateInstance(CLSID_CLRMetaHost, IID_ICLRMetaHost, (LPVOID*)&pClrMetaHost);
if (hr == S_OK)
{
// Get the runtime information for the particular version of .NET
hr = pClrMetaHost->GetRuntime(dotNetVersion, IID_PPV_ARGS(&pClrRuntimeInfo));
if (hr == S_OK)
{
// Check if the specified runtime can be loaded into the process. This
// method will take into account other runtimes that may already be
// loaded into the process and set pbLoadable to TRUE if this runtime can
// be loaded in an in-process side-by-side fashion.
BOOL fLoadable;
hr = pClrRuntimeInfo->IsLoadable(&fLoadable);
if ((hr == S_OK) && fLoadable)
{
// Load the CLR into the current process and return a runtime interface
// pointer.
hr = pClrRuntimeInfo->GetInterface(CLSID_CLRRuntimeHost,
IID_PPV_ARGS(&pClrRuntimeHost));
if (hr == S_OK)
{
// Start it. This is okay to call even if the CLR is already running
hr = pClrRuntimeHost->Start();
if (hr == S_OK)
{
// Success!
return pClrRuntimeHost;
}
}
}
}
}
// Cleanup if failed
if (pClrRuntimeHost)
{
pClrRuntimeHost->Release();
pClrRuntimeHost = NULL;
}
if (pClrRuntimeInfo)
{
pClrRuntimeInfo->Release();
pClrRuntimeInfo = NULL;
}
if (pClrMetaHost)
{
pClrMetaHost->Release();
pClrMetaHost = NULL;
}
return NULL;
}
我这样称呼它:
ICLRRuntimeHost* pClr = StartCLR(L"v4.0.30319");
当它失败时,你会得到什么结果?.NET运行时是否在windows事件日志中记录了任何内容?另一方面,您的代码在成功时泄漏了
ICLRRuntimeInfo
和ICLRMetaHost
COM对象。@Brian Reichle我得到了一个0小时的代码。