Group:  Microsoft Word ยป microsoft.public.word.oleinterop
Thread: How can I enumerate embedded objects in Word in a general fashion?

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

How can I enumerate embedded objects in Word in a general fashion?
winslars 03.09.2006 09:47:01
I am currently making our OCX components Office-compatible and I have
run into a small problem that I haven't found a good solution for yet.

We have two control types: one represents the document and the other
represents
individual fields within that document. We want the document control to find
its
associated fields (or vice versa). Initially we developed this with IE as
container but
now we extend it to general OLE containers and the problem we have run into
is that Word does not seem to support IOLEContainer::EnumObjects. The code
that runs fine in Excel and PowerPoint and allows us to enumerate over the
embedded objects returns 0 (zero) objects in Word.

I have tried to find documentation about this on the Internet, but the info
is dated and indicates that Excel should have the same behavior and that is
definitely wrong.
There are suggestions about using the Word automation model, but I would
like to avoid that if I can and use general interfaces to accomplish the task.

Any suggestions?
Re: How can I enumerate embedded objects in Word in a general fashion?
Cindy M. <C.Meister-C[ at ]hispeed.ch> 04.09.2006 14:21:17
Hi =?Utf-8?B?d2luc2xhcnM=?=,

It would have helped if you could have provided information on which approach
you are using for PPT/Excel. As far as I know, the only way to pick up OLE
objects in Word is to loop through the InlineShapes and Shapes collections,
checking the type (whether it's an OLE control), then picking up the
OLEFormat.Object to get to the "guts".

[Quoted Text]
> I am currently making our OCX components Office-compatible and I have
> run into a small problem that I haven't found a good solution for yet.
>
> We have two control types: one represents the document and the other
> represents
> individual fields within that document. We want the document control to find
> its
> associated fields (or vice versa). Initially we developed this with IE as
> container but
> now we extend it to general OLE containers and the problem we have run into
> is that Word does not seem to support IOLEContainer::EnumObjects. The code
> that runs fine in Excel and PowerPoint and allows us to enumerate over the
> embedded objects returns 0 (zero) objects in Word.
>
> I have tried to find documentation about this on the Internet, but the info
> is dated and indicates that Excel should have the same behavior and that is
> definitely wrong.
> There are suggestions about using the Word automation model, but I would
> like to avoid that if I can and use general interfaces to accomplish the task.
>
> Any suggestions?
>

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)

Re: How can I enumerate embedded objects in Word in a general fash
winslars 05.09.2006 07:01:01
As I wrote in my original post I use IOleContainer::EnumObjects
Here is a snippet of my code that works in IE/Excel/PowerPoint but not in
Word:
("TOLEIP" is a smart pointer class, "ioc" is the IOleContainer pointer in my
control,
"_DQlix" is the dispatch interface to my satelite object)

TOLEIP<IEnumUnknown> pEnumerator;

// Get an enumerator for the embedded objects
HRESULT hr = ioc->EnumObjects (OLECONTF_EMBEDDINGS, &pEnumerator);
_ASSERTE (SUCCEEDED (hr));
if (FAILED (hr)) return;

TOLEIP<IUnknown> pUnk;
ULONG uFetched = 0;

for (UINT i = 0; pEnumerator->Next (1, &pUnk, &uFetched) == S_OK; i ++) {

// Try to convert IUnknown pointer into wanted interface
TOLEIP<IDispatch> pDQlix;
hr = pUnk->QueryInterface (__uuidof (_DQlix), (void**) &pDQlix);
pUnk = NULL;

if (pDQlix) {
// We have a match, use the interface
...
}
}

As you can see I am working at the low-level generic IOleContainer /
IOleObject level. I find it strange that Word does not supply the same kind
of support that
Excel does, but everything seems to indicate that that is the case.

Can i get to the InlineShapes and Shapes collections in a general manner or
are they Word-specific?


"Cindy M." wrote:

[Quoted Text]
> Hi =?Utf-8?B?d2luc2xhcnM=?=,
>
> It would have helped if you could have provided information on which approach
> you are using for PPT/Excel. As far as I know, the only way to pick up OLE
> objects in Word is to loop through the InlineShapes and Shapes collections,
> checking the type (whether it's an OLE control), then picking up the
> OLEFormat.Object to get to the "guts".
>
> > I am currently making our OCX components Office-compatible and I have
> > run into a small problem that I haven't found a good solution for yet.
> >
> > We have two control types: one represents the document and the other
> > represents
> > individual fields within that document. We want the document control to find
> > its
> > associated fields (or vice versa). Initially we developed this with IE as
> > container but
> > now we extend it to general OLE containers and the problem we have run into
> > is that Word does not seem to support IOLEContainer::EnumObjects. The code
> > that runs fine in Excel and PowerPoint and allows us to enumerate over the
> > embedded objects returns 0 (zero) objects in Word.
> >
> > I have tried to find documentation about this on the Internet, but the info
> > is dated and indicates that Excel should have the same behavior and that is
> > definitely wrong.
> > There are suggestions about using the Word automation model, but I would
> > like to avoid that if I can and use general interfaces to accomplish the task.
> >
> > Any suggestions?
> >
>
> Cindy Meister
> INTER-Solutions, Switzerland
> http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
> http://www.word.mvps.org
>
> This reply is posted in the Newsgroup; please post any follow question or reply
> in the newsgroup and not by e-mail :-)
>
>
Re: How can I enumerate embedded objects in Word in a general fash
Cindy M. <C.Meister-C[ at ]hispeed.ch> 05.09.2006 11:41:49
Hi =?Utf-8?B?d2luc2xhcnM=?=,

You might be best off with this question in the Office.developer.automation
newsgroup. You're more likely to meet other programmers there who work at this
level. The Word, Excel and Powerpoint interfaces were all developed
individually, by different teams, many years ago. What they expose/provide is
quite different.

InlineShapes is particular to Word. The other Office apps do use the Shapes
collection, as it bases on the shared Office graphics tools, but it's not said
that you can use it at the level you appear to be working at.

[Quoted Text]
> As I wrote in my original post I use IOleContainer::EnumObjects
> Here is a snippet of my code that works in IE/Excel/PowerPoint but not in
> Word:
> ("TOLEIP" is a smart pointer class, "ioc" is the IOleContainer pointer in my
> control,
> "_DQlix" is the dispatch interface to my satelite object)
>
> TOLEIP<IEnumUnknown> pEnumerator;
>
> // Get an enumerator for the embedded objects
> HRESULT hr = ioc->EnumObjects (OLECONTF_EMBEDDINGS, &pEnumerator);
> _ASSERTE (SUCCEEDED (hr));
> if (FAILED (hr)) return;
>
> TOLEIP<IUnknown> pUnk;
> ULONG uFetched = 0;
>
> for (UINT i = 0; pEnumerator->Next (1, &pUnk, &uFetched) == S_OK; i ++) {
>
> // Try to convert IUnknown pointer into wanted interface
> TOLEIP<IDispatch> pDQlix;
> hr = pUnk->QueryInterface (__uuidof (_DQlix), (void**) &pDQlix);
> pUnk = NULL;
>
> if (pDQlix) {
> // We have a match, use the interface
> ...
> }
> }
>
> As you can see I am working at the low-level generic IOleContainer /
> IOleObject level. I find it strange that Word does not supply the same kind
> of support that
> Excel does, but everything seems to indicate that that is the case.
>
> Can i get to the InlineShapes and Shapes collections in a general manner or
> are they Word-specific?
>

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)

Re: How can I enumerate embedded objects in Word in a general fash
winslars 05.09.2006 11:54:01
I will do that.
Thanks

"Cindy M." wrote:

[Quoted Text]
> Hi =?Utf-8?B?d2luc2xhcnM=?=,
>
> You might be best off with this question in the Office.developer.automation
> newsgroup. You're more likely to meet other programmers there who work at this
> level. The Word, Excel and Powerpoint interfaces were all developed
> individually, by different teams, many years ago. What they expose/provide is
> quite different.
>
> InlineShapes is particular to Word. The other Office apps do use the Shapes
> collection, as it bases on the shared Office graphics tools, but it's not said
> that you can use it at the level you appear to be working at.
>
> > As I wrote in my original post I use IOleContainer::EnumObjects
> > Here is a snippet of my code that works in IE/Excel/PowerPoint but not in
> > Word:
> > ("TOLEIP" is a smart pointer class, "ioc" is the IOleContainer pointer in my
> > control,
> > "_DQlix" is the dispatch interface to my satelite object)
> >
> > TOLEIP<IEnumUnknown> pEnumerator;
> >
> > // Get an enumerator for the embedded objects
> > HRESULT hr = ioc->EnumObjects (OLECONTF_EMBEDDINGS, &pEnumerator);
> > _ASSERTE (SUCCEEDED (hr));
> > if (FAILED (hr)) return;
> >
> > TOLEIP<IUnknown> pUnk;
> > ULONG uFetched = 0;
> >
> > for (UINT i = 0; pEnumerator->Next (1, &pUnk, &uFetched) == S_OK; i ++) {
> >
> > // Try to convert IUnknown pointer into wanted interface
> > TOLEIP<IDispatch> pDQlix;
> > hr = pUnk->QueryInterface (__uuidof (_DQlix), (void**) &pDQlix);
> > pUnk = NULL;
> >
> > if (pDQlix) {
> > // We have a match, use the interface
> > ...
> > }
> > }
> >
> > As you can see I am working at the low-level generic IOleContainer /
> > IOleObject level. I find it strange that Word does not supply the same kind
> > of support that
> > Excel does, but everything seems to indicate that that is the case.
> >
> > Can i get to the InlineShapes and Shapes collections in a general manner or
> > are they Word-specific?
> >
>
> Cindy Meister
> INTER-Solutions, Switzerland
> http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
> http://www.word.mvps.org
>
> This reply is posted in the Newsgroup; please post any follow question or reply
> in the newsgroup and not by e-mail :-)
>
>

Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net