Disable Word.Application error message in VC

MyPlanet 2003-11-07 02:33:36
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();
...全文
95 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
MyPlanet 2003-11-09
  • 打赏
  • 举报
回复
I have run that piece of code on five computers with valid ms word (three word 2000 and two word xp), but get similar result.
ablefirst 2003-11-09
  • 打赏
  • 举报
回复
看来你只能重新安装word了。
MyPlanet 2003-11-09
  • 打赏
  • 举报
回复
It looks that it is quite hard to disable it in VC application. The error message is from WINWORD 2000. The message title is "WINWORD.EXE - Application Error", and the content is "The exception unknown software exception (0xc00000fd) occurred in the application at location 0x3050c46d.". If I try to print this document in Winword, the Winword will quit without any warning. Maybe it is a bug inside Winword.

Thanks you guys all the same.
everandforever 2003-11-08
  • 打赏
  • 举报
回复
TRY
{
_Application l_wordApp;
Documents l_wordDocs;
_Document l_wordDoc;
...
}
CATCH_ALL(e)
{
e->Delete();
}
END_CATCH_ALL
sunyuan_01 2003-11-08
  • 打赏
  • 举报
回复
warning
#pragma warning( warning-specifier : warning-number-list [,warning-specifier : warning-number-list...] )

#pragma warning( push[ , n ] )

#pragma warning( pop )

Allows selective modification of the behavior of compiler warning messages.

The warning-specifier can be one of the following.

Warning-specifier Meaning
once Display the specified message(s) only once.
default Apply the default compiler behavior to the specified message(s).
1, 2, 3, 4 Apply the given warning level to the specified warning message(s).
disable Do not issue the specified warning message(s).
error Report the specified warnings as errors.


The warning-number-list can contain any warning numbers. Multiple options can be specified in the same pragma directive as follows:

#pragma warning( disable : 4507 34; once : 4385; error : 164 )

This is functionally equivalent to:

#pragma warning( disable : 4507 34 ) // Disable warning messages
// 4507 and 34.
#pragma warning( once : 4385 ) // Issue warning 4385
// only once.
#pragma warning( error : 164 ) // Report warning 164
// as an error.

For warning numbers greater than 4699, those associated with code generation, the warning pragma has effect only when placed outside function definitions. The pragma is ignored if it specifies a number greater than 4699 and is used inside a function. The following example illustrates the correct placement of warning pragmas to disable, and then restore, the generation of a code-generation warning message:

int a;
#pragma warning( disable : 4705 )
void func()
{
a;
}
#pragma warning( default : 4705 )

The warning pragma also supports the following syntax:

#pragma warning( push [ ,n ] )

#pragma warning( pop )

Where n represents a warning level (1 through 4).

The pragma warning( push ) stores the current warning state for all warnings. The pragma warning( push, n) stores the current state for all warnings and sets the global warning level to n.

The pragma warning( pop ) pops the last warning state pushed onto the stack. Any changes made to the warning state between push and pop are undone. Consider this example:

#pragma warning( push )
#pragma warning( disable : 4705 )
#pragma warning( disable : 4706 )
#pragma warning( disable : 4707 )
// Some code
#pragma warning( pop )

At the end of this code, pop restores the state of all warnings (including 4705, 4706, and 4707) to what it was at the beginning of the code.

When you write header files, you can use push and pop to ensure that changes to warning states made by the user do not prevent your headers from compiling properly. Use push at the beginning of the header and pop at the end. Suppose, for example, you have a header that does not compile cleanly at warning level 4. The following code changes the warning level to 3, then restores the original warning level at the end of the header:

#pragma warning( push, 3 )
// Declarations/ definitions
#pragma warning( pop )


--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.
f4t 2003-11-08
  • 打赏
  • 举报
回复
ding
f4t 2003-11-07
  • 打赏
  • 举报
回复
MyPlanet 2003-11-07
  • 打赏
  • 举报
回复
up

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧