Show OLE errors using wxLogDebug() in wxAutomationObject.
Enable the previously commented out ShowException() but use wxLogDebug() in it instead of wxLogWarning() to avoid confusing the users with errors they don't care about. Closes #11632. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64427 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -54,13 +54,16 @@
|
|||||||
#include "wx/datetime.h"
|
#include "wx/datetime.h"
|
||||||
#endif // wxUSE_DATETIME
|
#endif // wxUSE_DATETIME
|
||||||
|
|
||||||
// static void ShowException(LPOLESTR szMember, HRESULT hr, EXCEPINFO *pexcep, unsigned int uiArgErr);
|
|
||||||
|
|
||||||
#if wxUSE_OLE_AUTOMATION
|
#if wxUSE_OLE_AUTOMATION
|
||||||
|
|
||||||
/*
|
// Report an OLE error to the user via wxLog.
|
||||||
* wxAutomationObject
|
static void
|
||||||
*/
|
ShowException(const wxString& member,
|
||||||
|
HRESULT hr,
|
||||||
|
EXCEPINFO *pexcep,
|
||||||
|
unsigned int uiArgErr);
|
||||||
|
|
||||||
|
// wxAutomationObject
|
||||||
|
|
||||||
wxAutomationObject::wxAutomationObject(WXIDISPATCH* dispatchPtr)
|
wxAutomationObject::wxAutomationObject(WXIDISPATCH* dispatchPtr)
|
||||||
{
|
{
|
||||||
@@ -144,7 +147,7 @@ bool wxAutomationObject::Invoke(const wxString& member, int action,
|
|||||||
1 + namedArgCount, LOCALE_SYSTEM_DEFAULT, dispIds);
|
1 + namedArgCount, LOCALE_SYSTEM_DEFAULT, dispIds);
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
// ShowException(szMember, hr, NULL, 0);
|
ShowException(member, hr, NULL, 0);
|
||||||
delete[] argNames;
|
delete[] argNames;
|
||||||
delete[] dispIds;
|
delete[] dispIds;
|
||||||
return false;
|
return false;
|
||||||
@@ -198,7 +201,7 @@ bool wxAutomationObject::Invoke(const wxString& member, int action,
|
|||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
// display the exception information if appropriate:
|
// display the exception information if appropriate:
|
||||||
// ShowException((const char*) member, hr, &excep, uiArgErr);
|
ShowException(member, hr, &excep, uiArgErr);
|
||||||
|
|
||||||
// free exception structure information
|
// free exception structure information
|
||||||
SysFreeString(excep.bstrSource);
|
SysFreeString(excep.bstrSource);
|
||||||
@@ -493,25 +496,32 @@ bool wxAutomationObject::GetInstance(const wxString& classId) const
|
|||||||
if (m_dispatchPtr)
|
if (m_dispatchPtr)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
HRESULT hr;
|
||||||
CLSID clsId;
|
CLSID clsId;
|
||||||
IUnknown * pUnk = NULL;
|
IUnknown * pUnk = NULL;
|
||||||
|
|
||||||
wxBasicString unicodeName(classId);
|
wxBasicString unicodeName(classId);
|
||||||
|
|
||||||
if (FAILED(CLSIDFromProgID((BSTR) unicodeName, &clsId)))
|
hr = CLSIDFromProgID((BSTR) unicodeName, &clsId);
|
||||||
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
|
ShowException(classId, hr, NULL, 0);
|
||||||
wxLogWarning(wxT("Cannot obtain CLSID from ProgID"));
|
wxLogWarning(wxT("Cannot obtain CLSID from ProgID"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FAILED(GetActiveObject(clsId, NULL, &pUnk)))
|
hr = GetActiveObject(clsId, NULL, &pUnk);
|
||||||
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
|
ShowException(classId, hr, NULL, 0);
|
||||||
wxLogWarning(wxT("Cannot find an active object"));
|
wxLogWarning(wxT("Cannot find an active object"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pUnk->QueryInterface(IID_IDispatch, (LPVOID*) &m_dispatchPtr) != S_OK)
|
hr = pUnk->QueryInterface(IID_IDispatch, (LPVOID*) &m_dispatchPtr);
|
||||||
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
|
ShowException(classId, hr, NULL, 0);
|
||||||
wxLogWarning(wxT("Cannot find IDispatch interface"));
|
wxLogWarning(wxT("Cannot find IDispatch interface"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -526,12 +536,15 @@ bool wxAutomationObject::CreateInstance(const wxString& classId) const
|
|||||||
if (m_dispatchPtr)
|
if (m_dispatchPtr)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
HRESULT hr;
|
||||||
CLSID clsId;
|
CLSID clsId;
|
||||||
|
|
||||||
wxBasicString unicodeName(classId);
|
wxBasicString unicodeName(classId);
|
||||||
|
|
||||||
if (FAILED(CLSIDFromProgID((BSTR) unicodeName, &clsId)))
|
hr = CLSIDFromProgID((BSTR) unicodeName, &clsId);
|
||||||
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
|
ShowException(classId, hr, NULL, 0);
|
||||||
wxLogWarning(wxT("Cannot obtain CLSID from ProgID"));
|
wxLogWarning(wxT("Cannot obtain CLSID from ProgID"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -541,77 +554,92 @@ bool wxAutomationObject::CreateInstance(const wxString& classId) const
|
|||||||
// NB: using CLSCTX_INPROC_HANDLER results in failure when getting
|
// NB: using CLSCTX_INPROC_HANDLER results in failure when getting
|
||||||
// Automation interface for Microsoft Office applications so don't use
|
// Automation interface for Microsoft Office applications so don't use
|
||||||
// CLSCTX_ALL which includes it
|
// CLSCTX_ALL which includes it
|
||||||
if (FAILED(CoCreateInstance(clsId, NULL, CLSCTX_SERVER, IID_IDispatch,
|
hr = CoCreateInstance(clsId, NULL, CLSCTX_SERVER, IID_IDispatch,
|
||||||
(void**)&m_dispatchPtr)))
|
(void**)&m_dispatchPtr);
|
||||||
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
wxLogWarning(wxT("Cannot start an instance of this class."));
|
ShowException(classId, hr, NULL, 0);
|
||||||
|
wxLogWarning(wxT("Could not start an instance of this class."));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxUSE_OLE_AUTOMATION
|
static void
|
||||||
|
ShowException(const wxString& member,
|
||||||
#if 0
|
HRESULT hr,
|
||||||
|
EXCEPINFO *pexcep,
|
||||||
void ShowException(LPOLESTR szMember, HRESULT hr, EXCEPINFO *pexcep, unsigned int uiArgErr)
|
unsigned int uiArgErr)
|
||||||
{
|
{
|
||||||
TCHAR szBuf[512];
|
wxString message;
|
||||||
|
|
||||||
switch (GetScode(hr))
|
switch (GetScode(hr))
|
||||||
{
|
{
|
||||||
case DISP_E_UNKNOWNNAME:
|
case DISP_E_UNKNOWNNAME:
|
||||||
wsprintf(szBuf, L"%s: Unknown name or named argument.", szMember);
|
message = wxT("Unknown name or named argument.");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DISP_E_BADPARAMCOUNT:
|
case DISP_E_BADPARAMCOUNT:
|
||||||
wsprintf(szBuf, L"%s: Incorrect number of arguments.", szMember);
|
message = wxT("Incorrect number of arguments.");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DISP_E_EXCEPTION:
|
case DISP_E_EXCEPTION:
|
||||||
wsprintf(szBuf, L"%s: Error %d: ", szMember, pexcep->wCode);
|
{
|
||||||
|
message = wxT("Error Code (");
|
||||||
|
message << pexcep->wCode ;// unsigned short
|
||||||
|
message += wxT(")");
|
||||||
if (pexcep->bstrDescription != NULL)
|
if (pexcep->bstrDescription != NULL)
|
||||||
lstrcat(szBuf, pexcep->bstrDescription);
|
message += pexcep->bstrDescription;
|
||||||
else
|
else
|
||||||
lstrcat(szBuf, L"<<No Description>>");
|
message += wxT("<<No Description>>");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DISP_E_MEMBERNOTFOUND:
|
case DISP_E_MEMBERNOTFOUND:
|
||||||
wsprintf(szBuf, L"%s: method or property not found.", szMember);
|
message = wxT("Method or property not found.");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DISP_E_OVERFLOW:
|
case DISP_E_OVERFLOW:
|
||||||
wsprintf(szBuf, L"%s: Overflow while coercing argument values.", szMember);
|
message = wxT("Overflow while coercing argument values.");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DISP_E_NONAMEDARGS:
|
case DISP_E_NONAMEDARGS:
|
||||||
wsprintf(szBuf, L"%s: Object implementation does not support named arguments.",
|
message = wxT("Object implementation does not support named arguments.");
|
||||||
szMember);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DISP_E_UNKNOWNLCID:
|
case DISP_E_UNKNOWNLCID:
|
||||||
wsprintf(szBuf, L"%s: The locale ID is unknown.", szMember);
|
message = wxT("The locale ID is unknown.");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DISP_E_PARAMNOTOPTIONAL:
|
case DISP_E_PARAMNOTOPTIONAL:
|
||||||
wsprintf(szBuf, L"%s: Missing a required parameter.", szMember);
|
message = wxT("Missing a required parameter.");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DISP_E_PARAMNOTFOUND:
|
case DISP_E_PARAMNOTFOUND:
|
||||||
wsprintf(szBuf, L"%s: Argument not found, argument %d.", szMember, uiArgErr);
|
message = wxT("Argument not found, argument.");
|
||||||
|
message << uiArgErr;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DISP_E_TYPEMISMATCH:
|
case DISP_E_TYPEMISMATCH:
|
||||||
wsprintf(szBuf, L"%s: Type mismatch, argument %d.", szMember, uiArgErr);
|
message = wxT("Type mismatch, argument.");
|
||||||
|
message << uiArgErr;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ERROR_FILE_NOT_FOUND:
|
||||||
|
message = wxT("The system cannot find the file specified.");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case REGDB_E_CLASSNOTREG:
|
||||||
|
message = wxT("Class not registered.");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
wsprintf(szBuf, L"%s: Unknown error occurred.", szMember);
|
message = wxT("Unknown error occurred. Return value is ");
|
||||||
|
message << hr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxLogWarning(szBuf);
|
wxLogDebug("OLE Automation error in %s: %s", member, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif // wxUSE_OLE_AUTOMATION
|
||||||
|
Reference in New Issue
Block a user