/// <summary>
        /// Activate activation context according to the given manifest file,
        /// and the specified action.
        /// </summary>
        /// <param name="actoinToDo">
        /// The method that will be executed if the activation succeed.
        /// </param>
        /// <param name="manifestPath">
        /// The full path of manifest file.
        /// </param>
        static void ActivateActivationContext(Action actoinToDo, string manifestPath)
        {
            ACTCTX ac = new ACTCTX();

            ac.cbSize   = Marshal.SizeOf(typeof(ACTCTX));
            ac.lpSource = manifestPath;
            ac.dwFlags  = 0;

            IntPtr           cookie;
            SafeActCtxHandle hActCtx = NativeMethod.CreateActCtx(ref ac);

            if (!hActCtx.IsInvalid)
            {
                try
                {
                    // Activate the activation context.
                    if (NativeMethod.ActivateActCtx(hActCtx, out cookie))
                    {
                        try
                        {
                            actoinToDo();
                        }
                        finally
                        {
                            // Deactivate the activation context.
                            NativeMethod.DeactivateActCtx(0, cookie);
                        }
                    }
                    else
                    {
                        Console.WriteLine("The ActCtx failed to be activated w/err {0}",
                                          Marshal.GetLastWin32Error());
                    }
                }
                finally
                {
                    hActCtx.Dispose();
                }
            }
            else
            {
                Console.WriteLine("The ActCtx failed to be created w/err {0}",
                                  Marshal.GetLastWin32Error());
            }
        }
 public static extern SafeActCtxHandle CreateActCtx(ref ACTCTX pActCtx);
Пример #3
0
        /// <summary>
        /// Activate activation context according to the given manifest file, 
        /// and the specified action.
        /// </summary>
        /// <param name="actoinToDo">
        /// The method that will be executed if the activation succeed.
        /// </param>
        /// <param name="manifestPath">
        /// The full path of manifest file.
        /// </param>
        static void ActivateActivationContext(Action actoinToDo, string manifestPath)
        {
            ACTCTX ac = new ACTCTX();
            ac.cbSize = Marshal.SizeOf(typeof(ACTCTX));
            ac.lpSource = manifestPath;
            ac.dwFlags = 0;

            IntPtr cookie;
            SafeActCtxHandle hActCtx = NativeMethod.CreateActCtx(ref ac);
            if (!hActCtx.IsInvalid)
            {
                try
                {
                    // Activate the activation context.
                    if (NativeMethod.ActivateActCtx(hActCtx, out cookie))
                    {
                        try
                        {
                            actoinToDo();
                        }
                        finally
                        {
                            // Deactivate the activation context.
                            NativeMethod.DeactivateActCtx(0, cookie);
                        }
                    }
                    else
                    {
                        Console.WriteLine("The ActCtx failed to be activated w/err {0}",
                            Marshal.GetLastWin32Error());
                    }
                }
                finally
                {
                    hActCtx.Dispose();
                }
            }
            else
            {
                Console.WriteLine("The ActCtx failed to be created w/err {0}",
                    Marshal.GetLastWin32Error());
            }
        }
Пример #4
0
 public static extern SafeActCtxHandle CreateActCtx(ref ACTCTX pActCtx);