PowerPoint automation: Not able to save file usingIID_IPersistMoniker

R

RAHUL

Hi All,

I have opened a PPT file using the OLE interfaces, it opens properly
and I am able to edit it, however when I try to save it using the
following code, the Save call fails

void createFromExistingFile()
{
if (SUCCEEDED(hr = CreateBindCtx(0, &_pbctx)))
{
BIND_OPTS bopts = {sizeof(BIND_OPTS), BIND_MAYBOTHERUSER, 0,
10000};
bopts.grfMode = (STGM_TRANSACTED | STGM_SHARE_DENY_WRITE |
STGM_READWRITE);

if (SUCCEEDED(hr = _pbctx->SetBindOptions(&bopts)) &&
SUCCEEDED(hr = CreateFileMoniker(*pbstrFile, &_pmkfile)))
{
// Bind to the object moniker refers to...
hr = _pmkfile->BindToObject(_pbctx, NULL, IID_IOleObject, (void**)
&_poleobj);
}

......... some code
}


void Save()
{
IPersistMoniker *prstMk;
if (SUCCEEDED(hr = _poleobj->QueryInterface(IID_IPersistMoniker,
(void**)&prstMk)))
{
IMoniker * pmk;
hr = prstMk->GetCurMoniker(&pmk);

hr = prstMk->Save(pmk, _pbctx, TRUE); // _pbctx

// Though the above call saves the file properly yet the return code
contains E_FAIL. How do I get the more detailed information about the
error which is happening here. Could somebody please tell what might
be going wrong here. When it is saving the file properly then why does
it return E_FAIL.

Thanks in advance
Rahul
 
J

Joseph M. Newcomer

I have a PowerPoint indexer on my MVP Tips site, and it has the ability to close a
PowerPoint presentation and apparently does so successfully. The code does not resemble
the code below. You are free to download it and see what I did.
joe

Hi All,

I have opened a PPT file using the OLE interfaces, it opens properly
and I am able to edit it, however when I try to save it using the
following code, the Save call fails

void createFromExistingFile()
{
if (SUCCEEDED(hr = CreateBindCtx(0, &_pbctx)))
{
BIND_OPTS bopts = {sizeof(BIND_OPTS), BIND_MAYBOTHERUSER, 0,
10000};
bopts.grfMode = (STGM_TRANSACTED | STGM_SHARE_DENY_WRITE |
STGM_READWRITE);

if (SUCCEEDED(hr = _pbctx->SetBindOptions(&bopts)) &&
SUCCEEDED(hr = CreateFileMoniker(*pbstrFile, &_pmkfile)))
{
// Bind to the object moniker refers to...
hr = _pmkfile->BindToObject(_pbctx, NULL, IID_IOleObject, (void**)
&_poleobj);
}

......... some code
}


void Save()
{
IPersistMoniker *prstMk;
if (SUCCEEDED(hr = _poleobj->QueryInterface(IID_IPersistMoniker,
(void**)&prstMk)))
{
IMoniker * pmk;
hr = prstMk->GetCurMoniker(&pmk);

hr = prstMk->Save(pmk, _pbctx, TRUE); // _pbctx

// Though the above call saves the file properly yet the return code
contains E_FAIL. How do I get the more detailed information about the
error which is happening here. Could somebody please tell what might
be going wrong here. When it is saving the file properly then why does
it return E_FAIL.

Thanks in advance
Rahul
Joseph M. Newcomer [MVP]
email: (e-mail address removed)
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
 

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