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
// 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