From 1244d2e07fd3ddf1123613d54ae3ae3503256119 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 19 Feb 2011 12:33:08 +0000 Subject: [PATCH] Add wxAutomationInstance_SilentIfNone flag for wxMSW OLE code. This flag allows to suppress the error message in case there are no currently running instances of this object and can be useful if the caller doesn't know in advance whether it's available or not. Closes #12734. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66967 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 4 +++- include/wx/msw/ole/automtn.h | 6 +++++- interface/wx/msw/ole/automtn.h | 14 +++++++++++++- src/msw/ole/automtn.cpp | 11 +++++++++-- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index bb79b65387..d1769863ed 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -178,7 +178,9 @@ Changes in behaviour not resulting in compilation errors, please read this! - wxMSW-specific wxAutomationObject::GetInstance() method now creates a new instance if needed instead of failing if the application providing the requested ProgID is not running. Pass wxAutomationInstance_UseExistingOnly - flag to it to revert to the old behaviour. + flag to it to revert to the old behaviour. It is also possible to use the + wxAutomationInstance_SilentIfNone flag to prevent the error message if no + currently running instances of this object are available. Changes in behaviour which may result in compilation errors diff --git a/include/wx/msw/ole/automtn.h b/include/wx/msw/ole/automtn.h index 63b9414d29..beae01b33e 100644 --- a/include/wx/msw/ole/automtn.h +++ b/include/wx/msw/ole/automtn.h @@ -33,7 +33,11 @@ enum wxAutomationInstanceFlags wxAutomationInstance_UseExistingOnly = 0, // Create a new instance if there are no existing ones. - wxAutomationInstance_CreateIfNeeded = 1 + wxAutomationInstance_CreateIfNeeded = 1, + + // Do not log errors if we failed to get the existing instance because none + // is available. + wxAutomationInstance_SilentIfNone = 2 }; /* diff --git a/interface/wx/msw/ole/automtn.h b/interface/wx/msw/ole/automtn.h index c351d20e88..916bc1b80d 100644 --- a/interface/wx/msw/ole/automtn.h +++ b/interface/wx/msw/ole/automtn.h @@ -31,7 +31,15 @@ enum wxAutomationInstanceFlags instance failed, we should call wxAutomationObject::CreateInstance() to create a new one. */ - wxAutomationInstance_CreateIfNeeded = 1 + wxAutomationInstance_CreateIfNeeded = 1, + + /** + Do not show an error message if no existing instance is currently + running. + + All other errors will still be reported as usual. + */ + wxAutomationInstance_SilentIfNone = 2 }; @@ -134,6 +142,10 @@ public: If attaching to an existing object failed and @a flags includes wxAutomationInstance_CreateIfNeeded flag, a new object will be created. + Otherwise this function will normally log an error message which may be + undesirable if the object may or may not exist. The + wxAutomationInstance_SilentIfNone flag can be used to prevent the error + from being logged in this case. Returns @true if a pointer was successfully retrieved, @false otherwise. diff --git a/src/msw/ole/automtn.cpp b/src/msw/ole/automtn.cpp index dce44ebc5a..12a46ffcad 100644 --- a/src/msw/ole/automtn.cpp +++ b/src/msw/ole/automtn.cpp @@ -545,8 +545,15 @@ bool wxAutomationObject::GetInstance(const wxString& progId, int flags) const } else { - wxLogSysError(hr, - _("Cannot get an active instance of \"%s\""), progId); + // Log an error except if we're supposed to fail silently when the + // error is that no current instance exists. + if ( hr != MK_E_UNAVAILABLE || + !(flags & wxAutomationInstance_SilentIfNone) ) + { + wxLogSysError(hr, + _("Cannot get an active instance of \"%s\""), + progId); + } } return false; -- 2.45.2