I am running the following code for deadlock detection but always I find the error inforing that RunTime and shim failed to start. Why is this issue occurring to me and how to solve this problem? I will be glad if someone could help me in this regard.
int _tmain(int argc, _TCHAR* argv[])
{
ICLRRuntimeHost *pClrHost = NULL;
HRESULT hrCorBind = CorBindToRuntimeEx(
NULL, L"wks", 0, CLSID_CLRRuntimeHost,
IID_ICLRRuntimeHost,
(PVOID*)&pClrHost);
CheckFail(hrCorBind, "Bind to runtime failed (0x%x)");
DHHostControl *pHostControl = new DHHostControl(pClrHost);
if (!pHostControl)
Fail("Host control allocation failed");
pClrHost->SetHostControl(pHostControl);
HRESULT hrStart = pClrHost->Start();
if (hrStart == S_FALSE)
_ASSERTE(!L"Runtime already started; probably OK to proceed");
else
CheckFail(hrStart, "Runtime startup failed (0x%x)");
WCHAR wcShimPath[MAX_PATH];
if (!GetCurrentDirectoryW(MAX_PATH, wcShimPath))
CheckFail(HRESULT_FROM_WIN32(GetLastError()), "GetCurrentDirectory failed (0x%x)");
wcsncat_s(wcShimPath, sizeof(wcShimPath) / sizeof(WCHAR), L"\\shim.exe", MAX_PATH - wcslen(wcShimPath) - 1);
LPWSTR wcShimArgs = NULL;
if (argc > 1)
{
SIZE_T totalLength = 1; for(int i = 1; i < argc; i++)
{
if (i != 1)
totalLength++; totalLength += _tcslen(argv[i]) + 1;
}
wcShimArgs = new WCHAR[totalLength];
wcShimArgs[0] = '\0';
for(int i = 1; i < argc; i++)
{
if (i != 1)
wcscat_s(wcShimArgs, totalLength, L" ");
wcsncat_s(wcShimArgs, totalLength, argv[i], wcslen(argv[i]));
}
}
if (wcShimArgs == NULL)
Fail("Missing program path (host.exe <exePath>)\r\n");
DWORD retVal;
HRESULT hrExecute = pClrHost->ExecuteInDefaultAppDomain(
wcShimPath,
L"Shim",
L"Start",
wcShimArgs,
&retVal);
CheckFail(hrExecute, "Execution of shim failed (0x%x)\r\n");
if (wcShimArgs)
delete wcShimArgs;
pHostControl->ShuttingDown();
pClrHost->Stop();
pClrHost->Release();
_getch();
return retVal;
}