Problem with C++ CLR \ HostAppDomain
Hey there,
I have a C++ dll which is calling my C# code after an injection:
This is my C# DLL:
So the problem is that this don't work on all programs. On notepad++ it works fine.
But in a few programs and games, it don't work. In GTA 5 it works fine, but in games like Outlast or Dishonored, it don't work.
Can someone tell my why?
I think the injected C++ dll can't start the runtimehost. But why?
I have a C++ dll which is calling my C# code after an injection:
Code:
#include "stdafx.h"
#include <metahost.h>
#pragma comment(lib, "mscoree.lib")
DWORD WINAPI ControlThread(LPVOID lpParam)
{
ICLRMetaHost* metaHost = NULL;
ICLRRuntimeInfo* runtimeInfo = NULL;
ICLRRuntimeHost* runtimeHost = NULL;
if (CLRCreateInstance(CLSID_CLRMetaHost, IID_ICLRMetaHost, (LPVOID*)&metaHost) == S_OK)
if (metaHost->GetRuntime(L"v4.0.30319", IID_ICLRRuntimeInfo, (LPVOID*)&runtimeInfo) == S_OK)
if (runtimeInfo->GetInterface(CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (LPVOID*)&runtimeHost) == S_OK)
if (runtimeHost->Start() == S_OK)
{
DWORD pReturnValue;
runtimeHost->ExecuteInDefaultAppDomain(L"C:\\Dev\\CalledDll.dll", L"CalledDll.InjectedCSharpCode", L"DllMain", L"C# DLL loaded.", &pReturnValue);
runtimeInfo->Release();
metaHost->Release();
runtimeHost->Release();
}
return 0;
}
BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)ControlThread, hModule, NULL, NULL);
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
Code:
using System.Windows.Forms;
namespace CalledDll
{
public class InjectedCSharpCode
{
public static int DllMain(string InjectStatus)
{
MessageBox.Show("Im successfully called from C++ DLL.");
Main();
return 0;
}
public static void Main()
{
var form = new TestForm();
form.Show();
}
}
}
But in a few programs and games, it don't work. In GTA 5 it works fine, but in games like Outlast or Dishonored, it don't work.
Can someone tell my why?
I think the injected C++ dll can't start the runtimehost. But why?