none
Shape.Copy() not closing Clipboard on Windows 7 systems??? RRS feed

  • Question

  • Using Visual C++ and the PowerPoint COM object (msppt9)

    In a loop processing the Shapes of a PowerPoint Slide...

       OpenClipboard();  // This call is successful. (For debug purposes only to demonstrate that the Clipboard is available.)

       CloseClipboard();   // This call is successful. (For debug purposes only to demonstrate that the Clipboard is available.)

       shape.Copy();  // or textRange.Copy();

       OpenClipboard();  // This call fails "Access Denied" on many Windows 7 systems.

    It appears that for some reason on many Windows 7 systems (but not all), the shape.copy() is not closing the clipboard???

    Why wouldn't the PowerPoint COM close the clipboard when done copying into it?

     

     - Thanks for any help,

       Bob

    Monday, April 11, 2011 9:19 PM

All replies

  •  Hi rzybach,

     

    Thanks for posting in the MSDN Forum.

     

    As far as I see the shape.Copy will copy object to Clipboard. I think the clipboard perhaps is closed by some logic in your project. Would you please provide some snippet for further research?

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, April 13, 2011 3:56 AM
    Moderator
  • Tom,

     

    Thanks for looking into this.  Here is a simple code snippet that demonstrates the issue in our application.  It is actually a textRange.Copy that is causing the problem.  It only occurs on some Windows 7 systems.  And it only occurs when an Internet Explorer or Chrome window is up.  The following code will get stuck in the OpenClipboard loop. (The IE/Chrome browser window is pretty much locked up at this point also.)  When the Internet Explorer/Chrome window is closed, the next OpenClipboard call succeeds and the code continues on just fine.

       _Application*    myApp = new _Application( pWizData->pPptDispatch );   
        _Presentation*    myPres = new _Presentation( myApp->GetActivePresentation() );
        Slides mySlides( myPres->GetSlides() );
        _Slide mySlide( mySlides.Item( COleVariant( (long)1 ) ) );
        Shapes myShapes( mySlide.GetShapes() );
        long lMyShapeCount = myShapes.GetCount();
        Shape* myShape=NULL;
        for( int jj=1; jj<=lMyShapeCount; jj++ )
        {
            myShape = new Shape( ( myShapes.Item( COleVariant( (long)jj ) ) ) );
            if( myShape == NULL )
                continue;
            TextFrame* textFrame = new TextFrame(myShape->GetTextFrame());
            if( textFrame == NULL )
                continue;
            TextRange* textRange = new TextRange(textFrame->GetTextRange());
            if( textRange == NULL )
                continue;

            textRange->Copy();
            BOOL bRC = OpenClipboard( NULL );  // This call fails (Access is denied) when an IE/Chrome browser window is open.
            for( int k=0; (k<10000)&&(!bRC); k++ )
            {
                Sleep(100);
                bRC = OpenClipboard( NULL );
            }
            CloseClipboard();


            if( myShape != NULL )
            {
                delete myShape;
                myShape = NULL;
            }
            if( textFrame != NULL )
            {
                delete textFrame;
                textFrame = NULL;
            }
            if( textRange != NULL )
            {
                delete textRange;
                textRange = NULL;
            }
        }

     

     - Thanks,

        Bob

    Wednesday, April 13, 2011 1:10 PM