Disable Word.Application error message in VC
Hi,
Following code in a VC application use Word.Application to print out a document. But Winword will rise an error message if something is wrong in the document. I don't want the error message, since no body is waiting for clicking that OK button. Is it possible to disable that error message from Word.Application? By the way, is it possible to get the Process ID for the Word.Application, so I can kill it. Thanks.
_Application l_wordApp;
Documents l_wordDocs;
_Document l_wordDoc;
l_wordDocs.ReleaseDispatch();
l_wordDoc.ReleaseDispatch();
l_wordApp.m_bAutoRelease=true;
if(!l_wordApp.CreateDispatch("Word.Application"))
{
AfxMessageBox("Create Word.Application instance error");
return;
}
l_wordApp.SetVisible(FALSE);
COleVariant varFilePath("C:\\TEMP\\FP DS 11 09 03.doc");
COleVariant varstrNull("");
COleVariant varZero((short)0);
COleVariant varTrue(short(1),VT_BOOL);
COleVariant varFalse(short(0),VT_BOOL);
l_wordDocs.AttachDispatch(l_wordApp.GetDocuments());
l_wordDocs.Open(varFilePath,
varFalse,
varTrue,
varFalse,
varstrNull,
varstrNull,
varFalse,
varstrNull,
varstrNull,
varTrue,
varTrue,
varTrue);
l_wordDoc.AttachDispatch(l_wordApp.GetActiveDocument());
//l_wordApp.SetActivePrinter(lpszActivePrinter);
COleVariant covTrue((short)TRUE),
covFalse((short)FALSE),
covOptional((long)DISP_E_PARAMNOTFOUND,
VT_ERROR);
try {
l_wordDoc.PrintOut(covFalse, // It will rise error
covOptional,
covOptional,
covOptional,
covOptional,
covOptional,
covOptional,
COleVariant((long)1),
covOptional,
covOptional,
covOptional,
covOptional,
covOptional,
covOptional,
covOptional,
covOptional,
covOptional,
covOptional);
} catch (...) {}
try {
l_wordApp.Quit(covOptional,covOptional,covOptional);
} catch (...) {}
l_wordDoc.ReleaseDispatch();
l_wordDocs.ReleaseDispatch();
l_wordApp.ReleaseDispatch();