/// <summary> /// Initializes a new instance of the <see cref="ActivationContextHelper"/> class. /// </summary> /// <param name="manifestFile">The manifest file.</param> public ActivationContextHelper(string manifestFile) { if (!Platform.IsWindows) { return; } // Specifying a full path to the manifest file like this allows our unit tests to work even with a // test runner like Resharper 8 which does not set the current directory to the one containing the DLLs. // Note that we have to use CodeBase here because NUnit runs the tests from a shadow copy directory // that doesn't contain the manifest file. string path = new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath; string location = Path.GetDirectoryName(path); var context = new ActCtx { cbSize = Marshal.SizeOf(typeof(ActCtx)), lpSource = Path.Combine(location, manifestFile) }; IntPtr handle = CreateActCtx(ref context); if (handle == (IntPtr)(-1)) { throw new Win32Exception(Marshal.GetLastWin32Error(), "Error creating activation context"); } m_activationContext = handle; }
private static bool EnsureActivateContextCreated() { lock (_contextCreationLock) { if (!_contextCreationSucceeded) { // Pull manifest from the .NET Framework install // directory var assemblyLoc = typeof(object).Assembly.Location; string manifestLoc = null; var installDir = string.Empty; if (!string.IsNullOrWhiteSpace(assemblyLoc)) { installDir = Path.GetDirectoryName(assemblyLoc) ?? string.Empty; const string manifestName = "XPThemes.manifest"; manifestLoc = Path.Combine(installDir, manifestName); } if (!string.IsNullOrWhiteSpace(manifestLoc) && !string.IsNullOrWhiteSpace(installDir)) { _enableThemingActivationContext = new ActCtx { cbSize = Marshal.SizeOf(typeof(ActCtx)), lpSource = manifestLoc, lpAssemblyDirectory = installDir, dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID, }; // Set the lpAssemblyDirectory to the install // directory to prevent Win32 Side by Side from // looking for comctl32 in the application // directory, which could cause a bogus dll to be // placed there and open a security hole. // Note this will fail gracefully if file specified // by manifestLoc doesn't exist. _activationContext = CreateActCtx(ref _enableThemingActivationContext); _contextCreationSucceeded = !_activationContext.IsInvalid; } } // If we return false, we'll try again on the next call into // EnsureActivateContextCreated(), which is fine. return(_contextCreationSucceeded); } }
/// <summary> /// Initializes a new instance of the <see cref="ActivationContextHelper"/> class. /// </summary> /// <param name="manifestFile">The manifest file.</param> public ActivationContextHelper(string manifestFile) { #if !__MonoCS__ // Specifying a full path to the manifest file like this allows our unit tests to work even with a // test runner like Resharper 8 which does not set the current directory to the one containing the DLLs. // Note that we have to use CodeBase here because NUnit runs the tests from a shadow copy directory // that doesn't contain the manifest file. string path = new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath; string location = Path.GetDirectoryName(path); var context = new ActCtx { cbSize = Marshal.SizeOf(typeof(ActCtx)), lpSource = Path.Combine(location, manifestFile) }; IntPtr handle = CreateActCtx(ref context); if (handle == (IntPtr)(-1)) throw new Win32Exception(Marshal.GetLastWin32Error(), "Error creating activation context"); m_activationContext = handle; #endif }
private static extern IntPtr CreateActCtx(ref ActCtx actCtx);
private static extern ActivationContextSafeHandle CreateActCtx(ref ActCtx actCtx);