can't programmatically add picture to powerpoint in win98/me with Visual C++

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am writing codes to programmatically add pictures to powerpoint files with Visual C++ 6.0. It works under 2000 and XP. However, the same code fails under 98 and me with the exception 0x80020009(exception occurred). Here is the code snippet

// create powerpoint objec
CComPtr<IDispatch> pDisp
HRESULT hr = pDisp.CoCreateInstance
L"PowerPoint.Application"
NULL
CLSCTX_LOCAL_SERVER)

CComDispatchDriver pp(pDisp)

// Get Presentations collection
CComVariant varPresentations
hr = pp.GetPropertyByName(L"Presentations", &varPresentations)
CComDispatchDriver pPresentations(varPresentations.pdispVal)

CComVariant varPresentation
CComVariant varFalse = VARIANT_FALSE

// Add one presentatio
hr = pPresentations.Invoke1(L"Add", &varFalse, &varPresentation)
CComDispatchDriver pPresentation(varPresentation.pdispVal)

// Get Slides collectio
CComVariant varSlides
hr = pPresentation.GetPropertyByName(L"Slides", &varSlides)
CComDispatchDriver pSlides(varSlides.pdispVal)

CComVariant varPage = 0
CComVariant varLayout = 12; // blank layou

// Add one new slid
CComVariant varSlide
hr = pSlides.Invoke2(L"Add", &varPage, &varLayout, &varSlide)

// Get Shapes collectio
CComVariant varShapes
hr = pSlide.GetPropertyByName(L"Shapes", &varShapes)
CComDispatchDriver pShapes(varShapes.pdispVal)

// add a bitmap pictur
CComVariant varArray[7]
varArray[6] = sBitmapFilename.c_str()
varArray[5] = VARIANT_FALSE; // link to fil
varArray[4] = VARIANT_TRUE; // save with documen
varArray[3] = (float)0; // lef
varArray[2] = (float)0; // righ
varArray[1] = (float)300; // widt
varArray[0] = (float)200; // heigh

hr = pShapes.InvokeN(L"AddPicture", varArray, 7)

// The above moethod fails under 98/me!! hr = 0x8002000

Any problem with the codes? But why it works under 2000 and xp?

I am very frustrated. Thanks for help

Junha
 
It would help if you told us what line it breaks on.
Brian Reilly, PowerPoint MVP
 
It breaks on the last line in the code post

hr = pShapes.InvokeN(L"AddPicture", varArray, 7)

and hr = 0x80020009, which indicates "Exception occurred."

Thanks

Junha
----- Brian Reilly, MS MVP wrote: ----

It would help if you told us what line it breaks on.
Brian Reilly, PowerPoint MV
 
This is the method I use with nor problems:

// The height and width are just place holders. We have to set the
scale height and width after inserting the picture.
pCurrentShape =
pCurrentSlide->Shapes->AddPicture(logoPath.AllocSysString(),
Office::msoFalse,
Office::msoCTrue, left, top, 10, 10);
 
I have to rewrite all my codes If I follow your solution. Is there any easy way to fix the bug

Thanks

Junha
----- Mike M. wrote: ----

This is the method I use with nor problems

// The height and width are just place holders. We have to set th
scale height and width after inserting the picture
pCurrentShape
pCurrentSlide->Shapes->AddPicture(logoPath.AllocSysString()
Office::msoFalse
Office::msoCTrue, left, top, 10, 10)
 
I haven't worked with .NET yet. I would suspect something is wrong with
your arguments (varArray?) that PowerPoint doesn't like. Is the path to the
picture correct? Do all the other arguments match what PowerPoint is
execting?
 
You are right. After I use your code style instead of CDispatchDriver, I got an error code which indicates "Invalid parameter", I realize the powerpoint doesn't like the bmp format I input

Thanks very much

Junhai
 
I've only done Gif and Jpeg. Can't say whether bmp works or not. If you
find a method please let us know.

Junhai said:
You are right. After I use your code style instead of CDispatchDriver, I
got an error code which indicates "Invalid parameter", I realize the
powerpoint doesn't like the bmp format I input.
 
Back
Top