Results 1 to 4 of 4
  1. #1
    Lounger
    Join Date
    Jan 2003
    Location
    Brisbane, Queensland, Australia
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing SafeArray in Word Automating ? (2000)

    In a MS Word automating program, I want to get a ShapeRange from a Shapes object, which need a SafeArray parameter. I wrote the following code:
    ------------------------------------------
    COleSafeArray sa;
    DWORD bounds=1;
    sa.Create(VT_VARIANT,1,&bounds);
    COleVariant v_ind((long)1,VT_I4);
    long ind=0;
    sa.PutElement(&ind,&v_ind);
    //sa.Detach();

    CShapes shapes(doc.GetShapes());
    CShapeRange sr(shapes.Range(sa));
    -------------------------------------------
    It just throws an exception saying that the parameter has an invalid value. If I Detach the array before passing it to the Range method, the array becomes empty. Another exception is thrown out saying that out of bound.

    Anyone can tell me how can I get it right?
    Thx

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Passing SafeArray in Word Automating ? (2000)

    Tough one to answer, not knowing C.

    It looks like you've built custom methods like GetShapes to get a shapes collection; don't know if that is complicating things, but if it's any help, in VBA, "Shapes.Range(index)" wants an Integer or Long for index; it doesn't look like it will handle an array.

    Gary

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Passing SafeArray in Word Automating ? (2000)

    Couple thoughts:

    (1) Are you sure there is a GetShapes method available? To return the Shapes collection in Word you typically use something like:

    Document.Shapes

    (2) What does the data in your array look like?

    I assume the 1 element is for testing, but if you only have one element, you can use either a string or integer parameter, as the case may be, and skip the array entirely.

    If you really do have an array, and you need to return multiple shapes as a single ShapeRange, maybe there's another way.

  4. #4
    Lounger
    Join Date
    Jan 2003
    Location
    Brisbane, Queensland, Australia
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing SafeArray in Word Automating ? (2000)

    One element just for testing. In the program I need get several shapes with arbitary names or index.
    I don't know other ways to do it.
    What's even strange is that the code works perfectly for PowerPoint, but for Word, I always get the exception.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •