diff options
Diffstat (limited to 'src/utilcode/util.cpp')
-rw-r--r-- | src/utilcode/util.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/utilcode/util.cpp b/src/utilcode/util.cpp index 67e353b359..b9ca380212 100644 --- a/src/utilcode/util.cpp +++ b/src/utilcode/util.cpp @@ -28,7 +28,60 @@ UINT32 g_nClrInstanceId = 0; //********** Code. ************************************************************ +#if defined(FEATURE_COMINTEROP) && !defined(FEATURE_CORESYSTEM) +extern WinRTStatusEnum gWinRTStatus = WINRT_STATUS_UNINITED; +#endif // FEATURE_COMINTEROP && !FEATURE_CORESYSTEM +#if defined(FEATURE_COMINTEROP) && !defined(FEATURE_CORESYSTEM) +//------------------------------------------------------------------------------ +// +// Attempt to detect the presense of Windows Runtime support on the current OS. +// Our algorithm to do this is to ensure that: +// 1. combase.dll exists +// 2. combase.dll contains a RoInitialize export +// + +void InitWinRTStatus() +{ + STATIC_CONTRACT_NOTHROW; + STATIC_CONTRACT_GC_NOTRIGGER; + STATIC_CONTRACT_CANNOT_TAKE_LOCK; + STATIC_CONTRACT_SO_TOLERANT; + + WinRTStatusEnum winRTStatus = WINRT_STATUS_UNSUPPORTED; + + const WCHAR wszComBaseDll[] = W("\\combase.dll"); + const SIZE_T cchComBaseDll = _countof(wszComBaseDll); + + WCHAR wszComBasePath[MAX_LONGPATH + 1]; + const SIZE_T cchComBasePath = _countof(wszComBasePath); + + ZeroMemory(wszComBasePath, cchComBasePath * sizeof(wszComBasePath[0])); + + UINT cchSystemDirectory = WszGetSystemDirectory(wszComBasePath, MAX_LONGPATH); + + // Make sure that we're only probing in the system directory. If we can't find the system directory, or + // we find it but combase.dll doesn't fit into it, we'll fall back to a safe default of saying that WinRT + // is simply not present. + if (cchSystemDirectory > 0 && cchComBasePath - cchSystemDirectory >= cchComBaseDll) + { + if (wcscat_s(wszComBasePath, wszComBaseDll) == 0) + { + HModuleHolder hComBase(WszLoadLibrary(wszComBasePath)); + if (hComBase != NULL) + { + FARPROC activateInstace = GetProcAddress(hComBase, "RoInitialize"); + if (activateInstace != NULL) + { + winRTStatus = WINRT_STATUS_SUPPORTED; + } + } + } + } + + gWinRTStatus = winRTStatus; +} +#endif // FEATURE_COMINTEROP && !FEATURE_CORESYSTEM //***************************************************************************** // Convert a string of hex digits into a hex value of the specified # of bytes. //***************************************************************************** |