HRESULT ExecuteAssembly( LPCSTR exePath, LPCSTR coreClrPath, LPCSTR appDomainFriendlyName, int propertyCount, LPCSTR* propertyKeys, LPCSTR* propertyValues, int argc, LPCSTR* argv, LPCSTR managedAssemblyPath, LPCSTR entryPointAssemblyName, LPCSTR entryPointTypeName, LPCSTR entryPointMethodName, DWORD* exitCode) { if (exitCode == NULL) { return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER); } *exitCode = -1; DWORD error = PAL_InitializeCoreCLR(exePath); HRESULT hr = HRESULT_FROM_WIN32(error); // If PAL initialization failed, then we should return right away and avoid // calling any other APIs because they can end up calling into the PAL layer again. if (FAILED(hr)) { return hr; } ReleaseHolder<ICLRRuntimeHost2> host; hr = CorHost2::CreateObject(IID_ICLRRuntimeHost2, (void**)&host); IfFailRet(hr); hr = host->SetStartupFlags((STARTUP_FLAGS) (STARTUP_FLAGS::STARTUP_LOADER_OPTIMIZATION_SINGLE_DOMAIN | STARTUP_FLAGS::STARTUP_SINGLE_APPDOMAIN)); IfFailRet(hr); hr = host->Start(); IfFailRet(hr); ConstWStringHolder appDomainFriendlyNameW = StringToUnicode(appDomainFriendlyName); ConstWStringArrayHolder propertyKeysW; propertyKeysW.Set(StringArrayToUnicode(propertyCount, propertyKeys), propertyCount); ConstWStringArrayHolder propertyValuesW; propertyValuesW.Set(StringArrayToUnicode(propertyCount, propertyValues), propertyCount); DWORD domainId; hr = host->CreateAppDomainWithManager( appDomainFriendlyNameW, // Flags: // APPDOMAIN_ENABLE_PLATFORM_SPECIFIC_APPS // - By default CoreCLR only allows platform neutral assembly to be run. To allow // assemblies marked as platform specific, include this flag // // APPDOMAIN_ENABLE_PINVOKE_AND_CLASSIC_COMINTEROP // - Allows sandboxed applications to make P/Invoke calls and use COM interop // // APPDOMAIN_SECURITY_SANDBOXED // - Enables sandboxing. If not set, the app is considered full trust // // APPDOMAIN_IGNORE_UNHANDLED_EXCEPTION // - Prevents the application from being torn down if a managed exception is unhandled // APPDOMAIN_ENABLE_PLATFORM_SPECIFIC_APPS | APPDOMAIN_ENABLE_PINVOKE_AND_CLASSIC_COMINTEROP | APPDOMAIN_DISABLE_TRANSPARENCY_ENFORCEMENT, NULL, // Name of the assembly that contains the AppDomainManager implementation NULL, // The AppDomainManager implementation type name propertyCount, propertyKeysW, propertyValuesW, &domainId); IfFailRet(hr); ConstWStringArrayHolder argvW; argvW.Set(StringArrayToUnicode(argc, argv), argc); if (entryPointAssemblyName == NULL || entryPointTypeName == NULL || entryPointMethodName == NULL) { ConstWStringHolder managedAssemblyPathW = StringToUnicode(managedAssemblyPath); hr = host->ExecuteAssembly(domainId, managedAssemblyPathW, argc, argvW, exitCode); IfFailRet(hr); } else { ConstWStringHolder entryPointAssemblyNameW = StringToUnicode(entryPointAssemblyName); ConstWStringHolder entryPointTypeNameW = StringToUnicode(entryPointTypeName); ConstWStringHolder entryPointMethodNameW = StringToUnicode(entryPointMethodName); HostMain pHostMain; hr = host->CreateDelegate( domainId, entryPointAssemblyNameW, entryPointTypeNameW, entryPointMethodNameW, (INT_PTR*)&pHostMain); IfFailRet(hr); *exitCode = pHostMain(argc, argvW); } hr = host->UnloadAppDomain(domainId, true); // Wait until done IfFailRet(hr); hr = host->Stop(); // The PAL_Terminate is not called here since it would terminate the current process. return hr; }
int coreclr_initialize( const char* exePath, const char* appDomainFriendlyName, int propertyCount, const char** propertyKeys, const char** propertyValues, void** hostHandle, unsigned int* domainId) { HRESULT hr; #ifdef FEATURE_PAL DWORD error = PAL_InitializeCoreCLR(exePath); hr = HRESULT_FROM_WIN32(error); // If PAL initialization failed, then we should return right away and avoid // calling any other APIs because they can end up calling into the PAL layer again. if (FAILED(hr)) { return hr; } #endif ReleaseHolder<ICLRRuntimeHost2> host; hr = CorHost2::CreateObject(IID_ICLRRuntimeHost2, (void**)&host); IfFailRet(hr); ConstWStringHolder appDomainFriendlyNameW = StringToUnicode(appDomainFriendlyName); STARTUP_FLAGS startupFlags; LPCWSTR* propertyKeysWTemp; LPCWSTR* propertyValuesWTemp; ExtractStartupFlagsAndConvertToUnicode( propertyKeys, propertyValues, &propertyCount, &startupFlags, &propertyKeysWTemp, &propertyValuesWTemp); ConstWStringArrayHolder propertyKeysW; propertyKeysW.Set(propertyKeysWTemp, propertyCount); ConstWStringArrayHolder propertyValuesW; propertyValuesW.Set(propertyValuesWTemp, propertyCount); hr = host->SetStartupFlags(startupFlags); IfFailRet(hr); hr = host->Start(); IfFailRet(hr); hr = host->CreateAppDomainWithManager( appDomainFriendlyNameW, // Flags: // APPDOMAIN_ENABLE_PLATFORM_SPECIFIC_APPS // - By default CoreCLR only allows platform neutral assembly to be run. To allow // assemblies marked as platform specific, include this flag // // APPDOMAIN_ENABLE_PINVOKE_AND_CLASSIC_COMINTEROP // - Allows sandboxed applications to make P/Invoke calls and use COM interop // // APPDOMAIN_SECURITY_SANDBOXED // - Enables sandboxing. If not set, the app is considered full trust // // APPDOMAIN_IGNORE_UNHANDLED_EXCEPTION // - Prevents the application from being torn down if a managed exception is unhandled // APPDOMAIN_ENABLE_PLATFORM_SPECIFIC_APPS | APPDOMAIN_ENABLE_PINVOKE_AND_CLASSIC_COMINTEROP | APPDOMAIN_DISABLE_TRANSPARENCY_ENFORCEMENT, NULL, // Name of the assembly that contains the AppDomainManager implementation NULL, // The AppDomainManager implementation type name propertyCount, propertyKeysW, propertyValuesW, (DWORD *)domainId); if (SUCCEEDED(hr)) { host.SuppressRelease(); *hostHandle = host; } return hr; }
BOOL URLParser::FindTitle(std::vector<KEY_VAL_PAIR>& v_pairKeyVal) { BOOL bRetVal = FALSE; WCHAR* pwch = NULL; WCHAR* pwcurr = NULL; int iRawTitleLen = 0; std::string strTitleHeading = "Title"; std::string strTitleStart = "<TITLE"; // <Title>, <Title > etc std::string strTitleStartEnd = ">"; std::string strTitleEnd = "</"; // </Title>, </ Title> etc std::string strMatchAnyOfThese = "\'\"\\"; std::string strRawTitle; std::string strTitle; KEY_VAL_PAIR pairTitle; if(TRUE == m_objFileHelper.FindPattern(strTitleStart, TRUE)) { if(TRUE == m_objFileHelper.FindPattern(strTitleStartEnd, FALSE)) { if(S_OK == m_objFileHelper.ReadBeforeTillMatchThisPattern(strTitleEnd, strRawTitle)) { WCHAR* wpszTitle = StringToUnicode(strTitleHeading); if(NULL != wpszTitle) { pairTitle.first.assign(wpszTitle); delete[] wpszTitle; wpszTitle = NULL; } wpszTitle = StringToUnicode(strRawTitle); if(NULL != wpszTitle) { pwch = wpszTitle; iRawTitleLen = (int)strRawTitle.length(); for(int i = 0; i < iRawTitleLen; i++) { if(!((*pwch >= L'a' && *pwch <= L'z') || (*pwch >= L'A' && *pwch <= L'Z') || (*pwch >= L'0' && *pwch <= L'9')) ) { (*pwch) = L'_'; } pwch++; } pwch = wpszTitle; pwcurr = pwch; int iCurr = iRawTitleLen; // Remove extra '_' while(TRUE) { while((*pwch == L'_') && (*pwch != 0)) { pwch++; } if(*pwch == 0) { *pwcurr = *pwch; break; } *pwcurr++ = *pwch++; while((*pwch != L'_') && (*pwch != 0)) { *pwcurr++ = *pwch++; } *pwcurr++ = *pwch++; } pairTitle.second.assign(wpszTitle); //Clean the URL delete[] wpszTitle; wpszTitle = NULL; } bRetVal = TRUE; v_pairKeyVal.push_back(pairTitle); } } } return bRetVal; }