Presentations.Item(1) fails... though the Count() is 1

M

MS

I'm calling this from C++.

When I get the Presentations collection, ->Count() tells me that I have
1 presentation in the collection.

When I retrieve ->Item(1) from it, it fails with E_INVALIDARG.

Am I not entitled to request the item from in as an index?

Or is there something else at play here. I'm manually starting up
PowerPoint, and I'm sitting at the point where Untitled1 was
automatically created, and I've entered data. The presentation hasn't
been saved yet.

I'm able to create new presentations via automation through the
Presentations collection, but I'm not able to get the existing presentation.

Any suggestions.

-mark
 
M

MS

MS said:
I'm calling this from C++.

When I get the Presentations collection, ->Count() tells me that I have
1 presentation in the collection.

When I retrieve ->Item(1) from it, it fails with E_INVALIDARG.

Am I not entitled to request the item from in as an index?

One more thing. I did look at the error description that was tossed back:

Bad argument type. Expected collection index (string or integer).

I'm passing an integer 1 to it...

I thought it was having a problem with it not being a variant, so I
passed it as _variant_t(1).

Something wrong with that?
 
M

MS

MS said:
MS wrote:

I thought it was having a problem with it not being a variant, so I
passed it as _variant_t(1).

Something wrong with that?

After 6 hours of pounding my head, I posted here. After another 20
minutes, I figured it out. I need to case the 1 to a long before
passing it to the _variant_t constructor.

->Item(_variant_t(index)) where index was a long instead of an int made
all of the different in the world.

In C++, ints and longs are pretty interchangable, but not when
_variant_t has the constructor overloaded, such that passing in int sets
the variants type to VT_INT, and passing a long to the constructor
sets it to VT_I4.

The latter type being compatible with automation, while the VT_INT is not.

Why automation isn't smart enough to attempt a conversion of the
variant, I don't know. But anyway, I'm on my way to the next obstacle.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top