Hi people,
I'm using Word automation, embedding some OLE objects into a document and
then later on creating links to object within them. Anyway, the embedding
phase goes through just fine. But when I attempt the second pass, accessing
the InlineShape object and attempting to cast it to my given object, it
fails.
A first chance exception of type 'System.InvalidCastException' occurred
in CR.exe
Additional information: No such interface supported
I can SEE the objects embedded in Microsoft Word. I can select, activate,
manipulate and otherwise play around with them. The InlineShapes collection
contains all of the objects too. But when I try and cast the object to the
given type, I get the above error:
' Fetch the shape (success)
theShape = theDocument.ResultingDocument.InlineShapes.Item(1)
' Fetch the Thermo.Image. (fails)
theOLEObject = CType(theShape.OLEFormat.Object, Thermo.Image)
Now, this cast from theShape.OLEFormat.Object to "Thermo.Image" (our own OLE
object class) fails although the "ProgID" of the InlineShape.OLEFormat is
"Thermo.Image"!
Can anyone explain what is going on here? Perhaps I am doing something
wrong with COM and my interop? The odd thing is, I iterate through 90 odd
objects, some of them succeed and some don't. Any ideas?
Thanks.
Robin Tucker - 18 Oct 2004 13:52 GMT
I fixed this one. It was quite simple in the end - Word doesn't keep all of
its embedded objects in the running state all the time. In order to access
the interface you first have to ensure the object is in the running state,
ie: OLEFormat.Activate() (or something). This ensures the object is in the
running state and the interfaces can now be accessed. Slower but it works
:)
> Hi people,
>
[quoted text clipped - 31 lines]
>
> Thanks.
Robin Tucker - 18 Oct 2004 15:11 GMT
Well actually, executing the verb "wdOLEVerbHide" seems to work just as well
without the overhead of activation.
>I fixed this one. It was quite simple in the end - Word doesn't keep all
>of its embedded objects in the running state all the time. In order to
[quoted text clipped - 38 lines]
>>
>> Thanks.