Type mismatch from MFC automation interface

J

Joseph M. Newcomer

VS.NET 2003, talking to PPT 2003

When I open some presentations, using presentations.Open, everything works fine, but in
other presentations, it throws a COleException whose code is 'Type mismatch'. The call is

presentations.Open(filename, 0, 0, 1)

Specifically, the code is

try { /* try */
CPresentations presentations; // From CPresentations.h, the presentations coll.
CPresentation presentation; // From CPresentation.h

CString uname = filename;
uname.MakeUpper(); // convert ot all-uppercase

HERE(); // part of my debugging support, records line# for error report
presentations = app.get_Presentations(); // works fine

HERE();
int PresentationsCount = presentations.get_Count(); // # of presentations

// See if the presentation is already open; if so, just connect to it,
// don't open it a second time

for(int i = 1; i <= PresentationsCount; i++)
{ /* scan presentations */
HERE();
presentation = presentations.Item(COleVariant((long)i));
HERE();
CString pname = presentation.get_FullName();
pname.MakeUpper();
if(uname == pname)
{ /* found presentation */
TRACE(_T("PowerPointManager::OpenPresentation Found [%d] \"%s\"\n"), i,
filename);
FileSet::SetPresentation(fid, presentation);
FileSet::SetAlreadyOpen(fid, TRUE);
return TRUE;
} /* found presentation */
} /* scan presentations */

TRACE(_T("PowerPointManager::OpenPresentation Opening \"%s\"\n"), filename);
HERE();
presentation = presentations.Open(filename,
0, // ReadOnly
0, // Untitled
1); // WithWindow
//******************** Throws exception ***********************8

if(presentation == NULL)
return FALSE;
return FileSet::SetPresentation(fid, presentation);
} /* try find */
catch(COleException * e)
{ /* find failed */
HandleOleException(e, fid, 0, where, NULL);
return FALSE;
} /* find failed */
============================================

There are two problems here. One is that many other presentations have been opened
already from this call, and if I proceed from the call, many other presentations will be
opened by this call (the processing opens eight presentations, but only two of them report
"type mismatch". The second one is that in the debug build, it throws the exception, I
catch it in the catch clause, and all is sort-of-good. But in the Release build, the
lower-level code terminates the execution, which doesn't make any sense. It doesn't let
the exception get back to me.

So: what does 'type mismatch' mean? (my HandleOleException function prints out the
FormatMessage of the m_sc code of the COleException). How do I avoid it? And how do I
make sure that I get all the exceptions, without, shall we say, exception?
joe
Joseph M. Newcomer [MVP]
email: (e-mail address removed)
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
 
S

Steve Rindsberg

What happens when you try to open the same presentations manually, in the same copy of
PPT/same machine/same user as you're automating?

Speculation, but a few things that might cause trouble:

Password-protected PPT files
Files that might be open in another instance of PPT on a different PC
Files from older versions of PPT that are now blocked if you've installed SP3
Files that PPT 2003 can't open (as may happen frequently if you haven't applied at least
SP1)

VS.NET 2003, talking to PPT 2003

When I open some presentations, using presentations.Open, everything works fine, but in
other presentations, it throws a COleException whose code is 'Type mismatch'. The call is

presentations.Open(filename, 0, 0, 1)

Specifically, the code is

try { /* try */
CPresentations presentations; // From CPresentations.h, the presentations coll.
CPresentation presentation; // From CPresentation.h

CString uname = filename;
uname.MakeUpper(); // convert ot all-uppercase

HERE(); // part of my debugging support, records line# for error report
presentations = app.get_Presentations(); // works fine

HERE();
int PresentationsCount = presentations.get_Count(); // # of presentations

// See if the presentation is already open; if so, just connect to it,
// don't open it a second time

for(int i = 1; i <= PresentationsCount; i++)
{ /* scan presentations */
HERE();
presentation = presentations.Item(COleVariant((long)i));
HERE();
CString pname = presentation.get_FullName();
pname.MakeUpper();
if(uname == pname)
{ /* found presentation */
TRACE(_T("PowerPointManager::OpenPresentation Found [%d] \"%s\"\n"), i,
filename);
FileSet::SetPresentation(fid, presentation);
FileSet::SetAlreadyOpen(fid, TRUE);
return TRUE;
} /* found presentation */
} /* scan presentations */

TRACE(_T("PowerPointManager::OpenPresentation Opening \"%s\"\n"), filename);
HERE();
presentation = presentations.Open(filename,
0, // ReadOnly
0, // Untitled
1); // WithWindow
//******************** Throws exception ***********************8

if(presentation == NULL)
return FALSE;
return FileSet::SetPresentation(fid, presentation);
} /* try find */
catch(COleException * e)
{ /* find failed */
HandleOleException(e, fid, 0, where, NULL);
return FALSE;
} /* find failed */
============================================

There are two problems here. One is that many other presentations have been opened
already from this call, and if I proceed from the call, many other presentations will be
opened by this call (the processing opens eight presentations, but only two of them report
"type mismatch". The second one is that in the debug build, it throws the exception, I
catch it in the catch clause, and all is sort-of-good. But in the Release build, the
lower-level code terminates the execution, which doesn't make any sense. It doesn't let
the exception get back to me.

So: what does 'type mismatch' mean? (my HandleOleException function prints out the
FormatMessage of the m_sc code of the COleException). How do I avoid it? And how do I
make sure that I get all the exceptions, without, shall we say, exception?
joe
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