// Get the default directory from the system
// registry (if specified, otherwise it creates)
void FileNameHandler::GetDefaultDirectory(LPTSTR szOutBuffer)
{
	HKEY hRegKey;
	DWORD datatype, nResult;

	BOOL bNeedToSetKey = FALSE;

	// Initialize the directory name
	GetModuleDirectory(szOutBuffer);

	IO::Path::Append(szOutBuffer, m_szSectionName);

	// Don't save default path for unknown sections...
	if (lstrlen(m_szSectionName) == 0)
		return;

	// Try and get default dir from registry entry...
	if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Daedalus\\Default Directory\\",
				 0, m_szSectionName,
				 REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
				 NULL, &hRegKey, &nResult) != ERROR_SUCCESS)
	{
		// Couldn't open key - return
		return;
	}

	if (nResult == REG_CREATED_NEW_KEY)
	{
		// The key has just been created - no information is currently stored
		//  so we need to set the value
		bNeedToSetKey = TRUE;
	}
	else if (nResult == REG_OPENED_EXISTING_KEY)
	{
		// Key was already in registry - try to read value
		DWORD datasize = ARRAYSIZE(m_szSectionName);
		if (RegQueryValueEx(hRegKey, m_szSectionName, NULL,
			&datatype, (LPBYTE) szOutBuffer, &datasize) != ERROR_SUCCESS)
		{
			bNeedToSetKey = TRUE;
		}
	}
	else
	{
		// We don't know what happened. Just try to set
		bNeedToSetKey = TRUE;
	}

	if (bNeedToSetKey)
	{
		// Set to initial value...
		GetModuleDirectory(szOutBuffer);
		lstrcat(szOutBuffer, m_szSectionName);

		RegSetValueEx(hRegKey, m_szSectionName, 0, REG_SZ,
			(LPBYTE) szOutBuffer, lstrlen(szOutBuffer)+1);
	}

	RegCloseKey(hRegKey);
}
WindowsFileIOHub::WindowsFileIOHub(Platform::FileManagerPtr fileManager, const gs2d::str_type::string& bitmapFontSearchDirectory,
								   const gs2d::str_type::string& resourceDirectory) :
	FileIOHub(fileManager,
			  resourceDirectory, GetModuleDirectory(),
			  GetModuleDirectory(), GetModuleDirectory(), bitmapFontSearchDirectory)
{
}
Esempio n. 3
0
extern "C" HRESULT __stdcall CallApplicationMain(PCALL_APPLICATION_MAIN_DATA data)
{
    auto trace_writer = dnx::trace_writer{ IsTracingEnabled() };

    SetEnvironmentVariable(L"DNX_FRAMEWORK", L"dnxcore50");

    Win32KDisable(trace_writer);

    auto runtime_directory = data->runtimeDirectory ? data->runtimeDirectory : GetModuleDirectory(nullptr);

    auto coreclr_module = LoadCoreClr(runtime_directory, trace_writer);
    if (!coreclr_module)
    {
        trace_writer.write(L"Failed to locate or load coreclr.dll", false);
        return E_FAIL;
    }

    ICLRRuntimeHost2* pCLRRuntimeHost = nullptr;

    HRESULT hr = GetClrRuntimeHost(coreclr_module, &pCLRRuntimeHost, trace_writer);
    if (FAILED(hr))
    {
        trace_writer.write(L"Failed to get IID_ICLRRuntimeHost2", false);
        return hr;
    }

    hr = StartClrHost(pCLRRuntimeHost, trace_writer);
    if (FAILED(hr))
    {
        trace_writer.write(L"Failed to start CLR host", false);
        return hr;
    }

    hr = ExecuteMain(pCLRRuntimeHost, data, runtime_directory, GetModuleDirectory(coreclr_module), trace_writer);
    if (FAILED(hr))
    {
        trace_writer.write(L"Failed to start CLR host", false);
        return hr;
    }

    hr = StopClrHost(pCLRRuntimeHost);
    if (FAILED(hr))
    {
        trace_writer.write(L"Failed to stop CLR host", false);
        return hr;
    }

    return S_OK;
}
Esempio n. 4
0
void InitTypeLibrary()
{
	TCHAR szPath[MAX_PATH];
	char path[MAX_PATH];

	globalIdentifierList.clear();
	globalTagSymbolList.clear();
	globalTypeDeclList.clear();

	GetModuleDirectory(0, szPath, MAX_PATH);
	lstrcat(szPath, TEXT("\\..\\..\\typelib"));

	if(GetFileAttributes(szPath) == INVALID_FILE_ATTRIBUTES)
	{
		GetModuleDirectory(0, szPath, MAX_PATH);
		lstrcat(szPath, TEXT("\\typelib"));
	}

	size_t s = globalFileHistory.size();
	globalFileHistory.clear();
	globalIdentifierList.clear();
	globalTypeDeclList.clear();
	globalTagSymbolList.clear();
	s = globalFileHistory.size();

	//lstrcat(szPath, TEXT("\\typelib\\zip.txt"));
	//lstrcat(szPath, TEXT("\\test.txt"));

	WIN32_FIND_DATA w32fd;
	lstrcat(szPath, L"\\*.*");
	HANDLE hFind = FindFirstFile(szPath, &w32fd);

	if(hFind)
	{
		TCHAR *ptr = _tcsrchr(szPath, '\\'); *ptr = '\0';
		do 
		{
			if((w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
			{
				sprintf(path, "%ls\\%ls", szPath, w32fd.cFileName);
				Parser::Initialize();

				Parse(path);
			}
		} 
		while(FindNextFile(hFind, &w32fd));
	}
}
static void SetupVulkanEnvVariables()
{
#ifdef CODEXL_GRAPHICS
    gtASCIIString layerNameA = "CXLGraphicsServerVulkan" GDT_PROJECT_SUFFIX;
#else
    gtASCIIString layerNameA = "VulkanServer" GDT_PROJECT_SUFFIX;
#endif

    gtString layerName;
    layerName.fromASCIIString(layerNameA.asCharArray());

    gtASCIIString serverPath;
    GetModuleDirectory(serverPath);

    osEnvironmentVariable layerPath;
    layerPath._name = L"VK_LAYER_PATH";
    layerPath._value.fromASCIIString(serverPath.asCharArray());
    layerPath._value.append(L"Plugins");

    osEnvironmentVariable instanceLayerName;
    instanceLayerName._name =  L"VK_INSTANCE_LAYERS";
    instanceLayerName._value = layerName;

    osEnvironmentVariable deviceLayerName;
    deviceLayerName._name = L"VK_DEVICE_LAYERS";
    deviceLayerName._value = layerName;

    osSetCurrentProcessEnvVariable(layerPath);
    osSetCurrentProcessEnvVariable(instanceLayerName);
    osSetCurrentProcessEnvVariable(deviceLayerName);
}
Esempio n. 6
0
static const char* GetCurrentModuleDirectory()
{
    static char s_path[MAX_PATH] = {0};
    if(s_path[0]=='\0') {
        GetModuleDirectory(s_path, MAX_PATH);
    }
    return s_path;
}
Esempio n. 7
0
void TNotesResource1::CheckNotesManager(const TEndpointContext * AContext)
{
	if(const_cast<TEndpointContext*>(AContext)->User == NULL) {
		const_cast<TEndpointContext*>(AContext)->Response->RaiseUnauthorized("The operation is only permitted for logged in users");
	}
	if(FNotesStorage == NULL) {
		FNotesStorage = new TNotesStorage(GetModuleDirectory(), const_cast<TEndpointContext*>(AContext)->User->UserID);
    }
}
Esempio n. 8
0
IOSFileIOHub::IOSFileIOHub(const gs2d::str_type::string& bitmapFontSearchDirectory) :
	FileIOHub(
		Platform::StdAnsiFileManagerPtr(new Platform::StdAnsiFileManager(GS_L(""))),
		ResourceDirectory(),
		GetModuleDirectory(),
		ExternalStorageDirectory(),
		GlobalExternalStorageDirectory(),
		bitmapFontSearchDirectory)
{
	CreateDirectory(ExternalStorageDirectory());
	CreateDirectory(FileLogger::GetLogDirectory());
}
Esempio n. 9
0
//--------------------------------------------------------------------------
/// Setup Vulkan-specific environment variables.
/// This code needs to be called during tool initialization.
//--------------------------------------------------------------------------
void SetupVulkanEnvVariables()
{
#if ENABLE_VULKAN

    // Windows
#ifdef _WIN32

#ifdef _DEBUG
#ifdef X64
    gtString layerName = L"CXLGraphicsServerVulkan-x64-d";
#else
    gtString layerName = L"CXLGraphicsServerVulkan-d";
#endif
#else
#ifdef X64
    gtString layerName = L"CXLGraphicsServerVulkan-x64";
#else
    gtString layerName = L"CXLGraphicsServerVulkan";
#endif
#endif

    gtASCIIString serverPath;
    GetModuleDirectory(serverPath);

    // Set VK_LAYER_PATH equal to where our layer lives
    osEnvironmentVariable layerPath;
    layerPath._name = L"VK_LAYER_PATH";
    layerPath._value.fromASCIIString(serverPath.asCharArray());
    layerPath._value.append(L"Plugins");

    // Set VK_INSTANCE_LAYERS equal to our layer above
    osEnvironmentVariable instanceLayerName;
    instanceLayerName._name =  L"VK_INSTANCE_LAYERS";
    instanceLayerName._value = layerName;

    // Set VK_DEVICE_LAYERS equal to our layer above
    osEnvironmentVariable deviceLayerName;
    deviceLayerName._name = L"VK_DEVICE_LAYERS";
    deviceLayerName._value = layerName;

    // Setting these environment variables should register our server as a layer
    osSetCurrentProcessEnvVariable(layerPath);
    osSetCurrentProcessEnvVariable(instanceLayerName);
    osSetCurrentProcessEnvVariable(deviceLayerName);

    // Linux
#else

#endif

#endif
}
Esempio n. 10
0
DWORD CAutoUpdateDlg::DoDownLoadThread(void)
{
	CString csCurDir = GetModuleDirectory()+UPDATE_PACKAGE;
	DeleteFile(csCurDir.GetBuffer());
	if (m_csDownloadURL.GetLength() <= 0)
	{
		TCHAR szLastVer[16] = {0};
		TCHAR szUpdateURL[256] = {0};
		TCHAR szNote[1024] = {0};
		if(GetOnlineInfo(szLastVer,szUpdateURL,szNote))
			m_csDownloadURL = szUpdateURL;

	}
	if(DownloadFile(m_csDownloadURL,csCurDir))
	{
		m_bFileOK = TRUE;
	}
	return PostMessage(WM_ENDMESSAGE,0,0);
}
Esempio n. 11
0
extern "C" __declspec(dllexport) HRESULT __stdcall CallApplicationMain(PCALL_APPLICATION_MAIN_DATA data)
{
    HRESULT hr = S_OK;
    errno_t errno = 0;
    FnGetCLRRuntimeHost pfnGetCLRRuntimeHost = nullptr;
    ICLRRuntimeHost2* pCLRRuntimeHost = nullptr;
    TCHAR szCurrentDirectory[MAX_PATH];
    TCHAR szCoreClrDirectory[MAX_PATH];
    TCHAR lpCoreClrModulePath[MAX_PATH];
    size_t cchTrustedPlatformAssemblies = 0;
    LPWSTR pwszTrustedPlatformAssemblies = nullptr;

    Win32KDisable();

    if (data->runtimeDirectory) {
        errno = wcscpy_s(szCurrentDirectory, data->runtimeDirectory);
        CHECK_RETURN_VALUE_FAIL_EXIT_VIA_FINISHED(errno);
    }
    else {
        GetModuleDirectory(NULL, szCurrentDirectory);
    }

    HMODULE hCoreCLRModule = LoadCoreClr();
    if (!hCoreCLRModule)
    {
        printf_s("Failed to locate coreclr.dll.\n");
        return E_FAIL;
    }

    // Get the path to the module
    DWORD dwCoreClrModulePathSize = GetModuleFileName(hCoreCLRModule, lpCoreClrModulePath, MAX_PATH);
    lpCoreClrModulePath[dwCoreClrModulePathSize] = '\0';

    GetModuleDirectory(hCoreCLRModule, szCoreClrDirectory);

    HMODULE ignoreModule;
    // Pin the module - CoreCLR.dll does not support being unloaded.
    if (!::GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_PIN, lpCoreClrModulePath, &ignoreModule))
    {
        printf_s("Failed to pin coreclr.dll.\n");
        return E_FAIL;
    }

    pfnGetCLRRuntimeHost = (FnGetCLRRuntimeHost)::GetProcAddress(hCoreCLRModule, "GetCLRRuntimeHost");
    if (!pfnGetCLRRuntimeHost)
    {
        printf_s("Failed to find export GetCLRRuntimeHost.\n");
        return E_FAIL;
    }

    hr = pfnGetCLRRuntimeHost(IID_ICLRRuntimeHost2, (IUnknown**)&pCLRRuntimeHost);
    if (FAILED(hr))
    {
        printf_s("Failed to get IID_ICLRRuntimeHost2.\n");
        return hr;
    }

    STARTUP_FLAGS dwStartupFlags = (STARTUP_FLAGS)(
                                       STARTUP_FLAGS::STARTUP_LOADER_OPTIMIZATION_SINGLE_DOMAIN |
                                       STARTUP_FLAGS::STARTUP_SINGLE_APPDOMAIN |
                                       STARTUP_FLAGS::STARTUP_SERVER_GC
                                   );

    pCLRRuntimeHost->SetStartupFlags(dwStartupFlags);

    // Authenticate with either CORECLR_HOST_AUTHENTICATION_KEY or CORECLR_HOST_AUTHENTICATION_KEY_NONGEN
    hr = pCLRRuntimeHost->Authenticate(CORECLR_HOST_AUTHENTICATION_KEY);
    if (FAILED(hr))
    {
        printf_s("Failed to Authenticate().\n");
        return hr;
    }

    hr = pCLRRuntimeHost->Start();

    if (FAILED(hr))
    {
        printf_s("Failed to Start().\n");
        return hr;
    }

    const wchar_t* property_keys[] =
    {
        // Allowed property names:
        // APPBASE
        // - The base path of the application from which the exe and other assemblies will be loaded
        L"APPBASE",
        //
        // TRUSTED_PLATFORM_ASSEMBLIES
        // - The list of complete paths to each of the fully trusted assemblies
        L"TRUSTED_PLATFORM_ASSEMBLIES",
        //
        // APP_PATHS
        // - The list of paths which will be probed by the assembly loader
        L"APP_PATHS",
        //
        // APP_NI_PATHS
        // - The list of additional paths that the assembly loader will probe for ngen images
        //
        // NATIVE_DLL_SEARCH_DIRECTORIES
        // - The list of paths that will be probed for native DLLs called by PInvoke
        //
    };

    cchTrustedPlatformAssemblies = TRUSTED_PLATFORM_ASSEMBLIES_STRING_BUFFER_SIZE_CCH;
    pwszTrustedPlatformAssemblies = (LPWSTR)calloc(cchTrustedPlatformAssemblies+1, sizeof(WCHAR));
    if (pwszTrustedPlatformAssemblies == NULL)
    {
        goto Finished;
    }
    pwszTrustedPlatformAssemblies[0] = L'\0';

    // Try native images first
    if (!GetTrustedPlatformAssembliesList(szCoreClrDirectory, true, pwszTrustedPlatformAssemblies, cchTrustedPlatformAssemblies))
    {
        if (!GetTrustedPlatformAssembliesList(szCoreClrDirectory, false, pwszTrustedPlatformAssemblies, cchTrustedPlatformAssemblies))
        {
            printf_s("Failed to find files in the coreclr directory\n");
            return E_FAIL;
        }
    }

    // Add the assembly containing the app domain manager to the trusted list

    errno = wcscat_s(pwszTrustedPlatformAssemblies, cchTrustedPlatformAssemblies, szCurrentDirectory);
    CHECK_RETURN_VALUE_FAIL_EXIT_VIA_FINISHED(errno);

    errno = wcscat_s(pwszTrustedPlatformAssemblies, cchTrustedPlatformAssemblies, L"kre.coreclr.managed.dll");
    CHECK_RETURN_VALUE_FAIL_EXIT_VIA_FINISHED(errno);

    //wstring appPaths(szCurrentDirectory);
    WCHAR wszAppPaths[MAX_PATH];
    wszAppPaths[0] = L'\0';

    errno = wcscat_s(wszAppPaths, _countof(wszAppPaths), szCurrentDirectory);
    CHECK_RETURN_VALUE_FAIL_EXIT_VIA_FINISHED(errno);

    errno = wcscat_s(wszAppPaths, _countof(wszAppPaths), L";");
    CHECK_RETURN_VALUE_FAIL_EXIT_VIA_FINISHED(errno);

    errno = wcscat_s(wszAppPaths, _countof(wszAppPaths), szCoreClrDirectory);
    CHECK_RETURN_VALUE_FAIL_EXIT_VIA_FINISHED(errno);

    errno = wcscat_s(wszAppPaths, _countof(wszAppPaths), L";");
    CHECK_RETURN_VALUE_FAIL_EXIT_VIA_FINISHED(errno);

    const wchar_t* property_values[] = {
        // APPBASE
        data->applicationBase,
        // TRUSTED_PLATFORM_ASSEMBLIES
        pwszTrustedPlatformAssemblies,
        // APP_PATHS
        wszAppPaths,
    };

    DWORD domainId;
    DWORD dwFlagsAppDomain =
        APPDOMAIN_ENABLE_PLATFORM_SPECIFIC_APPS |
        APPDOMAIN_ENABLE_PINVOKE_AND_CLASSIC_COMINTEROP;

    LPCWSTR szAssemblyName = L"kre.coreclr.managed, Version=0.1.0.0";
    LPCWSTR szEntryPointTypeName = L"DomainManager";
    LPCWSTR szMainMethodName = L"Execute";

    int nprops = sizeof(property_keys) / sizeof(wchar_t*);

    hr = pCLRRuntimeHost->CreateAppDomainWithManager(
             L"kre.coreclr.managed",
             dwFlagsAppDomain,
             NULL,
             NULL,
             nprops,
             property_keys,
             property_values,
             &domainId);

    if (FAILED(hr))
    {
        wprintf_s(L"TPA      %d %S\n", wcslen(pwszTrustedPlatformAssemblies), pwszTrustedPlatformAssemblies);
        wprintf_s(L"AppPaths %S\n", wszAppPaths);
        printf_s("Failed to create app domain (%x).\n", hr);
        return hr;
    }

    HostMain pHostMain;

    hr = pCLRRuntimeHost->CreateDelegate(
             domainId,
             szAssemblyName,
             szEntryPointTypeName,
             szMainMethodName,
             (INT_PTR*)&pHostMain);

    if (FAILED(hr))
    {
        printf_s("Failed to create main delegate (%x).\n", hr);
        return hr;
    }

    SetEnvironmentVariable(L"KRE_FRAMEWORK", L"aspnetcore50");

    // Call main
    data->exitcode = pHostMain(data->argc, data->argv);

    pCLRRuntimeHost->UnloadAppDomain(domainId, true);

    pCLRRuntimeHost->Stop();

Finished:
    if (pwszTrustedPlatformAssemblies != NULL)
    {
        free(pwszTrustedPlatformAssemblies);
        pwszTrustedPlatformAssemblies = NULL;
    }

    if (FAILED(hr))
    {
        return hr;
    }
    else
    {
        return S_OK;
    }
}
Esempio n. 12
0
std::wstring GetCurrentModuleDirectory()
{
	return GetModuleDirectory(GetCurrentModuleHandle());
}
Esempio n. 13
0
extern "C" __declspec(dllexport) bool __stdcall CallApplicationMain(PCALL_APPLICATION_MAIN_DATA data)
{
    HRESULT hr = S_OK;
    FnGetCLRRuntimeHost pfnGetCLRRuntimeHost = nullptr;
    ICLRRuntimeHost2* pCLRRuntimeHost = nullptr;
    TCHAR szCurrentDirectory[MAX_PATH];
    TCHAR szCoreClrDirectory[MAX_PATH];
    TCHAR lpCoreClrModulePath[MAX_PATH];

    GetModuleDirectory(NULL, szCurrentDirectory);

    HMODULE hCoreCLRModule = LoadCoreClr();
    if (!hCoreCLRModule)
    {
        printf_s("Failed to locate coreclr.dll.\n");
        return false;
    }

    // Get the path to the module
    DWORD dwCoreClrModulePathSize = GetModuleFileName(hCoreCLRModule, lpCoreClrModulePath, MAX_PATH);
    lpCoreClrModulePath[dwCoreClrModulePathSize] = '\0';

    GetModuleDirectory(hCoreCLRModule, szCoreClrDirectory);

    HMODULE ignoreModule;
    // Pin the module - CoreCLR.dll does not support being unloaded.
    if (!::GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_PIN, lpCoreClrModulePath, &ignoreModule))
    {
        printf_s("Failed to pin coreclr.dll.\n");
        return false;
    }

    pfnGetCLRRuntimeHost = (FnGetCLRRuntimeHost)::GetProcAddress(hCoreCLRModule, "GetCLRRuntimeHost");
    if (!pfnGetCLRRuntimeHost)
    {
        printf_s("Failed to find export GetCLRRuntimeHost.\n");
        return false;
    }

    hr = pfnGetCLRRuntimeHost(IID_ICLRRuntimeHost2, (IUnknown**)&pCLRRuntimeHost);
    if (FAILED(hr))
    {
        printf_s("Failed to get IID_ICLRRuntimeHost2.\n");
        return false;
    }

    STARTUP_FLAGS dwStartupFlags = (STARTUP_FLAGS)(
        STARTUP_FLAGS::STARTUP_LOADER_OPTIMIZATION_SINGLE_DOMAIN |
        STARTUP_FLAGS::STARTUP_SINGLE_APPDOMAIN
        );

    pCLRRuntimeHost->SetStartupFlags(dwStartupFlags);

    // Authenticate with either CORECLR_HOST_AUTHENTICATION_KEY or CORECLR_HOST_AUTHENTICATION_KEY_NONGEN 
    hr = pCLRRuntimeHost->Authenticate(CORECLR_HOST_AUTHENTICATION_KEY);
    if (FAILED(hr))
    {
        printf_s("Failed to Authenticate().\n");
        return false;
    }

    hr = pCLRRuntimeHost->Start();

    if (FAILED(hr))
    {
        printf_s("Failed to Start().\n");
        return false;
    }

    const wchar_t* property_keys[] =
    {
        // Allowed property names:
        // APPBASE
        // - The base path of the application from which the exe and other assemblies will be loaded
        L"APPBASE",
        //
        // TRUSTED_PLATFORM_ASSEMBLIES
        // - The list of complete paths to each of the fully trusted assemblies
        L"TRUSTED_PLATFORM_ASSEMBLIES",
        //
        // APP_PATHS
        // - The list of paths which will be probed by the assembly loader
        L"APP_PATHS",
        //
        // APP_NI_PATHS
        // - The list of additional paths that the assembly loader will probe for ngen images
        //
        // NATIVE_DLL_SEARCH_DIRECTORIES
        // - The list of paths that will be probed for native DLLs called by PInvoke
        //
    };

    wstring trustedPlatformAssemblies(L"");

    // Enumerate the core clr directory and add each .dll or .ni.dll to the list of trusted assemblies
    wstring pattern(szCoreClrDirectory);
    pattern += L"*.dll";

    WIN32_FIND_DATA ffd;
    HANDLE findHandle = FindFirstFile(pattern.c_str(), &ffd);

    if (INVALID_HANDLE_VALUE == findHandle)
    {
        printf_s("Failed to find files in the coreclr directory\n");
        return -1;
    }

    do
    {
        if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
        {
            // Skip directories
        }
        else
        {
            trustedPlatformAssemblies += szCoreClrDirectory;
            trustedPlatformAssemblies += ffd.cFileName;
            trustedPlatformAssemblies += L";";
        }

    } while (FindNextFile(findHandle, &ffd) != 0);

    // Add the assembly containing the app domain manager to the trusted list
    trustedPlatformAssemblies += szCurrentDirectory;
    trustedPlatformAssemblies += L"klr.core45.managed.dll";

    wstring appPaths(szCurrentDirectory);

    appPaths += L";";
    appPaths += szCoreClrDirectory;

    const wchar_t* property_values[] = {
        // APPBASE
        szCurrentDirectory, // TODO: Allow overriding this
        // TRUSTED_PLATFORM_ASSEMBLIES
        trustedPlatformAssemblies.c_str(),
        // APP_PATHS
        appPaths.c_str(),
    };

    DWORD domainId;
    DWORD dwFlagsAppDomain =
        APPDOMAIN_ENABLE_PLATFORM_SPECIFIC_APPS |
        APPDOMAIN_ENABLE_PINVOKE_AND_CLASSIC_COMINTEROP |
        APPDOMAIN_ENABLE_ASSEMBLY_LOADFILE;

    LPCWSTR szAssemblyName = L"klr.core45.managed, Version=1.0.0.0";
    LPCWSTR szDomainManagerTypeName = L"DomainManager";
    LPCWSTR szMainMethodName = L"Main";

    int nprops = sizeof(property_keys) / sizeof(wchar_t*);

    hr = pCLRRuntimeHost->CreateAppDomainWithManager(
        L"klr.core45.managed",
        dwFlagsAppDomain,
        szAssemblyName,
        szDomainManagerTypeName,
        nprops,
        property_keys,
        property_values,
        &domainId);

    if (FAILED(hr))
    {
        printf_s("Failed to create app domain (%d).\n", hr);
        return false;
    }

    HostMain pHostMain;

    hr = pCLRRuntimeHost->CreateDelegate(
        domainId,
        szAssemblyName,
        szDomainManagerTypeName,
        szMainMethodName,
        (INT_PTR*)&pHostMain);

    if (FAILED(hr))
    {
        printf_s("Failed to create main delegate (%d).\n", hr);
        return false;
    }

    // Call main
    data->exitcode = pHostMain(szCurrentDirectory, data->argc, data->argv);

    pCLRRuntimeHost->UnloadAppDomain(domainId, true);

    pCLRRuntimeHost->Stop();

    return hr;
}