none
Fail to Insert Picture Into Document(RPC_E_DISCONNECTED) RRS feed

  • Question

  • Hi,

    I am using Visual C++ to automate Word. I use the following statement to insert a picture:

       COLEInlineShape InlineShape = InlineShapes.AddPicture(strPicFile, COleVariant(0l), COleVariant(1l), VARIANT_OPTIONAL);

    But found after inserting some pictures, the above call will fail and return InlineShape with m_lpDispatch == NULL.

    I want to figure out the reason, so I try to step into .AddPicture function and find the function actually invoke IDispatch::Invoke. The function returns an invalid result because IDispatch::Invoke returns an error code(0x80010108). I checked the help document for IDispatch::Invoke at https://docs.microsoft.com/en-us/windows/desktop/api/oaidl/nf-oaidl-idispatch-invoke but cannot find that code. After searching in WinError.h, I find the error is RPC_E_DISCONNECTED. How to solve the error?

    Thanks

    Saturday, October 13, 2018 9:14 AM

All replies

  • Hi chcw,

    >> I want to figure out the reason, so I try to step into .AddPicture function and find the function actually invoke IDispatch::Invoke. The function returns an invalid result because IDispatch::Invoke returns an error code(0x80010108).

    This problem occurs when the RPCSS service does not ping remote sets at the required two-minute interval.

    >> I checked the help document for IDispatch::Invoke but cannot find that code.

    Please try the following code to insert a picture to a document:

    void CAutomateWordDlg::OnBnClickedAutomatewordInsertPicture()
    {
            COleVariant ovTrue((short)TRUE);
            COleVariant ovFalse((short)FALSE);
            COleVariant ovOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
            CFileDialog fdlgPicture(TRUE);
    
            if (fdlgPicture.DoModal() == IDCANCEL)
            {
                    return;
            }
    
            CSelection      iSelection = m_iAppInterface.get_Selection();
            CnlineShapes    iInlineShapes = iSelection.get_InlineShapes();
            COleVariant     ovLinkToFile((short)0);
            COleVariant     ovSaveWithDocument((short)1);
    
            // Insert picture
            iInlineShapes.AddPicture(fdlgPicture.GetPathName(), 
                            ovLinkToFile, 
                            ovSaveWithDocument, 
                            ovOptional);
    
            // Add a paragraph (return & new line)
            iSelection.TypeParagraph();
    }


    >> After searching in WinError.h, I find the error is RPC_E_DISCONNECTED. How to solve the error?

    You can try the solution in the following link to fix it:

    FIX: The RPC_E_DISCONNECTED error code may be returned intermittently when you call a method for a remote DCOM object or for a COM+ object

    Also, please have a look at this post

    The InlineShapes.AddPicture method accepts a local path and file name of the picture. So you need to download the picture on a local machine and add a picture from a hard drive, not a web server.

    Hopefully it helps you.

    Best Regards,

    Yuki


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Monday, October 15, 2018 6:08 AM
    Moderator
  • Hi,

    My file is in the local computer. And "RPC_E_DISCONNECTED" error is different from the "The graphics filter was unable to convert this file." error. The former comes from a normal .png file, the latter comes from a .wdp file. I guess .wdp file is not supported by AddPicture. But for the former error, I cannot figure out the reason, I try to invoke AddPicture in a simple program with the specific .png file, then that will be OK. but when try to invoke AddPicture in a complex program with a lot of automation invokes, then that will fail. Will too many invokes to automation cause RPC_E_DISCONNECTED problem?

    Thanks

    Monday, October 15, 2018 7:17 AM