ClrRuntimeHost->开始无法按预期运行

时间:2016-01-31 02:32:05

标签: c++ clr

因此,我创建了一个使用CLRRunTimeHost的项目,以惊吓主机托管库。

但是我遇到了一个问题。当我运行它时,它工作得非常好,没有打嗝,但是在将它分发给少数人后,错误报告开始流入。在今天大约11个小时之后,我已经找到了源头。但是,在最后一次检查或

时,整个功能都会通过罚款
hr = pClrRuntimeHost->Start();

失败并且无法启动。我已经通过图书馆安装等方式对所有使用它的人进行了交谈和指导。没有人可以使用它,我甚至将源代码发送给安装了VS2015的好朋友,他也成了同样错误的牺牲品。 / p>

这是完整的功能:

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");

0 个答案:

没有答案