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