none
PowerPoint: "PowerPoint found an error that it can't correct. You should save presentations, quit, and then restart Powerpoint." RRS feed

  • Question

  • Hello,

    I develop an C# application which should access to PowerPoint application object, when PowerPoint is the top window. And I get the following error message:

    "PowerPoint found an error that it can't correct. You should save presentations, quit, and then restart Powerpoint."

    when my application tries to access a PowerPoint instance that is opened in [Protected View] mode. Of course, it occurs only in PowerPoint 2010.

    I know that internet is full of advices how to avoid this message, but I have not found something that would help me.

    I will try to describe the application's workflow:

    1. to get the PowerPoint application object I use

    [DllImport("Oleacc.dll", EntryPoint = "AccessibleObjectFromWindow")]
    public static extern int AccessibleObjectFromWindow(IntPtr hwnd, uint dwObjectId, byte[] riid, ref IDispatch ptr);

    If the operation works fine, IDispatch ptr will be an Microsoft.Office.Interop.PowerPoint.DocumentWindow object (I use PIA version 12).

    To call this method I need IntPtr hwnd. To get this IntPtr hwnd, I use

    1. [DllImport("User32")]
    public static extern IntPtr FindWindowEx(int hwndParent, int hwndChildAfter, string lpszClass, int missing); - to get the handler of the PowerPoint main window (lpszClass = "PPTFrameClass")

    and

    2. [DllImport("user32.Dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool EnumChildWindows(IntPtr parentHandle, EnumerateChildWindowsDelegate enumerateChildWindowsFunc, IntPtr lParam); - to get the pointer of the window which contains application object (where EnumerateChildWindowsDelegate enumerateChildWindowsFunc - just enumerates all child windows and gets the one (its handler) which has "paneClassDC" class).

    The error message appears when AccessibleObjectFromWindow is called.

    Please note that everything works fine when PowerPoint is opened in normal mode (not a [Protected View])  and it does not matter what type of file is opened: .ppt, .pptx or even .ppsx.

    And please note that the Marshal.GetActiveObject("PowerPoint.Application") is not a solution because there are the problems with registration of the Com objects in ROT. I also use new Microsoft.Office.Interop.PowerPoint.Application(), when the methods described above return null, but I need to suppress the dialog box with the error message from topic.

    So, my question is:

    How to avoid throwing of the dialog box with the error message?

    But I will appreciate every suggestion that may help.

    Thank you in advance and have a nice coding!

    Thursday, August 16, 2012 5:22 PM

All replies

  • Hi Sorin,

    Thanks for posting in the MSDN Forum.

    Would you please provide more snippet for troubleshooting? I tried reproduce your issue in a PowerPoint add-in, however it works fine.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Friday, August 17, 2012 6:10 AM
    Moderator
  • Hi Tom,

    Thank you for answer.

    I have just written a console application which should help to reproduce the error message.

    At first, a PowerPoint .pptx file should be opened in Protected View mode, and then run the console application - error message should appear.

    using PowerPoint = Microsoft.Office.Interop.PowerPoint;
    
    namespace PowerPointTroubleshouting
    {
        public class Program
        {
            public const string PPointMainWindow = "PPTFrameClass";
            public const string PPointObjectWindow = "paneClassDC";
    
            public readonly static byte[] IDispatchId = new Guid("{00020400-0000-0000-C000-000000000046}").ToByteArray();
            public const uint PointerToNativeObjectModel = 0xFFFFFFF0;
    
            [DllImport("Oleacc.dll", EntryPoint = "AccessibleObjectFromWindow")]
            public static extern int AccessibleObjectFromWindow(IntPtr hwnd, uint dwObjectId, byte[] riid, ref PowerPoint.DocumentWindow ptr);
    
            [DllImport("User32")]
            public static extern IntPtr FindWindowEx(int hwndParent, int hwndChildAfter, string lpszClass, int missing);
    
            [DllImport("user32.Dll")]
            [return: MarshalAs(UnmanagedType.Bool)]
            public static extern bool EnumChildWindows(IntPtr parentHandle, EnumerateChildWindowsDelegate enumerateChildWindowsFunc, IntPtr lParam);
            public delegate bool EnumerateChildWindowsDelegate(IntPtr hWnd, IntPtr lParam);
    
            [DllImport("user32.dll", CharSet = CharSet.Auto)]
            public static extern int GetClassName(IntPtr hWnd, StringBuilder sb, int nMaxCount);
    
            static void Main(string[] args)
            {
                PowerPoint.Application applicationObj = null;
                IntPtr objectWindowHandler = IntPtr.Zero;
    
                try
                {
                    // Walk the children of the desktop to find Office app’s main window.
                    var hMainWnd = FindWindowEx(0, 0, PPointMainWindow, 0);
    
                    if (hMainWnd != IntPtr.Zero)
                    {
                        // Walk the children of this window to see if any are IAccessible.
                        IntPtr hWndChild = IntPtr.Zero;
    
                        EnumerateChildWindowsDelegate enumerateChildWindows = (hWnd, lParam) =>
                        {
                            var sb = new StringBuilder(128);
                            GetClassName(hWnd, sb, 128);
    
                            if (sb.ToString() == PPointObjectWindow)
                            {
                                hWndChild = hWnd;
                                return false;
                            }
    
                            return true;
                        };
                        EnumChildWindows(hMainWnd, enumerateChildWindows, hMainWnd);
    
                        objectWindowHandler = hWndChild;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Failed to get accessible object.", ex);
                }
    
                PowerPoint.DocumentWindow ptr = null;
                // error message dialog box should appear after stepping the line below
                int hr = AccessibleObjectFromWindow(objectWindowHandler, PointerToNativeObjectModel, IDispatchId, ref ptr);
    
                if (ptr != null) // I don't use "hr != 0", because sometimes ptr exists but hr does equal with 0
                {
                    if (ptr is PowerPoint.DocumentWindow)
                    {
                        Console.WriteLine("PowerPoint application object was accessed from DocumentWindow object.");
    
                        applicationObj = (ptr as PowerPoint.DocumentWindow).Application;
    
                        // just for testing
                        Console.WriteLine("Active Presentation: {0}.", applicationObj.ActivePresentation.Name);
                    }
                }
                else
                {
                    Console.WriteLine("Can't access PowerPoint application object.");
                }
    
                // finalization
                if (applicationObj != null)
                {
                    Marshal.ReleaseComObject(applicationObj);
                    applicationObj = null;
                }
    
                Console.ReadLine();
            }
        }
    }

    I hope this will help.

    Have a nice day!


    Friday, August 17, 2012 8:25 AM
  • Hi Sorin,

    I think the only way is close protectedViewWindow. I will involve some experts into your issue to see whether they can help you. There might be some time delay, appreciate for your patience.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, August 21, 2012 7:11 AM
    Moderator
  • Hi Sorin,

    The particular dialog is part of the security of Microsoft Office. You may be able to avoid it by considering the information in the following content sources:

    What is Protected View? - PowerPoint - Office.com
    http://office.microsoft.com/en-us/powerpoint-help/what-is-protected-view-HA010355931.aspx

    The article lists several different possible dialogs based on the reason for the file being opened in Protected View mode.

    Security policies and settings in Office 2010
    http://technet.microsoft.com/en-us/library/cc178946.aspx

    The Protected Views mechanism is explained in the following:
    Protected View in Office 2010 - Microsoft Office 2010 Engineering ...
    http://blogs.technet.com/b/office2010/archive/2009/08/13/protected-view-in-office-2010.aspx

    Pre-emptive concepts are in the following:
    Plan Trusted Locations settings for Office 2010
    http://technet.microsoft.com/en-us/library/cc179039.aspx
    and
    Plan Protected View settings for Office 2010
    http://technet.microsoft.com/en-us/library/ee857087.aspx

    This Forum thread has some perspective:

    PowerPoint 2007, files load only first image, then the system hangs?
    http://social.technet.microsoft.com/Forums/en-US/itprovistaapps/thread/5b8a4e8f-d97b-4443-8ca8-debd5657d2b9


    Please remember to mark the replies as answer if they help and unmark them if they provide no help. and click "Vote as Helpful" this and other helpful posts, so other users will see your thread as useful. Best Regards, Chris Jensen

    Wednesday, August 22, 2012 9:37 PM
    Moderator