locked
Shapes.Range method: how to call from C++? RRS feed

  • Question

  • I need to write C++ code that group three shapes in document. I have three “smart” pointers to shapes (leftConnectorPtr, rightConnectorPtr and textBoxPtr) and I must “combine” them into the ShapeRange object.

    I use the Shapes.Range method and pass array with shapes names to that method.

    Here my code:

    SAFEARRAYBOUND rgSABound;
    rgSABound.cElements = 3;
    rgSABound.lLbound = 1;
    SAFEARRAY* pSafeArray = SafeArrayCreateEx(VT_BSTR, 1, &rgSABound, NULL);
    if (pSafeArray)
    {
        BSTR* pData;
        HRESULT hResult = SafeArrayAccessData(pSafeArray, reinterpret_cast<void**> (&pData));
        if (SUCCEEDED(hResult))
        {
            pData[0] = SysAllocString(leftConnectorPtr->GetName());
            pData[1] = SysAllocString(rightConnectorPtr->GetName());
            pData[2] = SysAllocString(textBoxPtr->GetName());
            SafeArrayUnaccessData(pSafeArray);

            CComVariant rangeIndexes(pSafeArray);

            footerPtr->GetShapes()->Range(&rangeIndexes);    // fails!

            // group the shapes...


            HRESULT hResult = SafeArrayAccessData(pSafeArray, reinterpret_cast<void**> (&pData));
            if (SUCCEEDED(hResult))
            {
                SysFreeString(pData[2]);
                SysFreeString(pData[1]);
                SysFreeString(pData[0]);
                SafeArrayUnaccessData(pSafeArray);
            }
        }

        SafeArrayDestroy(pSafeArray);
    }

    At the line, where the Range(…) method is called, my application fails with exception. What’s wrong?
    Thanks!


    Sunday, November 2, 2008 5:11 PM

Answers

  • Hi,

     

    Thanks for contacting "Innovate on Office" forum, but this is not the right place to post your request, as we provide support on advisory issues for Office 2007. Basically  we address "How-to" questions and this is a trouble shooting issue.  

    Depending upon your partner level, you have the following three options.

    - Purchase an incident pack. Please contact the main-stream support team of OneNote in Microsoft.

                            OR

    - Use one of the incidents available to you.

                            OR

    - Visit https://partner.microsoft.com/global/supportsecurity/technicalsupport/40014662

     

     

                   

    Thanks,

     

    Harjit.

     

    Monday, November 3, 2008 5:27 PM
    Moderator

All replies

  • Hi,

     

    Thanks for contacting "Innovate on Office" forum, but this is not the right place to post your request, as we provide support on advisory issues for Office 2007. Basically  we address "How-to" questions and this is a trouble shooting issue.  

    Depending upon your partner level, you have the following three options.

    - Purchase an incident pack. Please contact the main-stream support team of OneNote in Microsoft.

                            OR

    - Use one of the incidents available to you.

                            OR

    - Visit https://partner.microsoft.com/global/supportsecurity/technicalsupport/40014662

     

     

                   

    Thanks,

     

    Harjit.

     

    Monday, November 3, 2008 5:27 PM
    Moderator
  • I had the same problem and eventually worked out how to do it. Since the Range method is designed for VBA/scripting, it's expecting an array of variants-containing-strings, not an array of strings.
    Wednesday, November 12, 2008 10:27 AM