using System; using System.Runtime.InteropServices; //Detects the presence of the Microsoft Visual C++ Runtime in C# by attempting to use a function from it. //#REF:https://redd.it/a58pka namespace CppRuntime { public static class NativeMethods { [DllImport("vcruntime140.dll", EntryPoint = "memcmp")] private static extern int memcmp140(byte[] A, byte[] B, int C); [DllImport("msvcr120.dll", EntryPoint = "memcmp")] private static extern int memcmp120(byte[] A, byte[] B, int C); [DllImport("msvcr110.dll", EntryPoint = "memcmp")] private static extern int memcmp110(byte[] A, byte[] B, int C); [DllImport("msvcr100.dll", EntryPoint = "memcmp")] private static extern int memcmp100(byte[] A, byte[] B, int C); [DllImport("msvcrt.dll", EntryPoint = "memcmp")] private static extern int memcmp(byte[] A, byte[] B, int C); public static bool HasCppRuntime140() { try { memcmp140(new byte[1], new byte[1], 1); return true; } catch (DllNotFoundException) { return false; } } public static bool HasCppRuntime120() { try { memcmp120(new byte[1], new byte[1], 1); return true; } catch (DllNotFoundException) { return false; } } public static bool HasCppRuntime110() { try { memcmp110(new byte[1], new byte[1], 1); return true; } catch (DllNotFoundException) { return false; } } public static bool HasCppRuntime100() { try { memcmp100(new byte[1], new byte[1], 1); return true; } catch (DllNotFoundException) { return false; } } public static bool HasCppRuntime() { try { memcmp(new byte[1], new byte[1], 1); return true; } catch (DllNotFoundException) { return false; } } } }