From d9ecce24d430e0f3e040bb500375530b496c9691 Mon Sep 17 00:00:00 2001 From: Rom Walton Date: Mon, 20 Apr 2015 16:11:07 -0400 Subject: [PATCH] VBOX: Add error trap for COM errors raised by the MSVC compiler stubs. Dump the contents of the error to stderr and halt the wrapper. --- samples/vboxwrapper/vbox_mscom_impl.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/samples/vboxwrapper/vbox_mscom_impl.cpp b/samples/vboxwrapper/vbox_mscom_impl.cpp index 6969ab49d5..b33dcbf94c 100644 --- a/samples/vboxwrapper/vbox_mscom_impl.cpp +++ b/samples/vboxwrapper/vbox_mscom_impl.cpp @@ -100,6 +100,27 @@ int virtualbox_check_error(HRESULT rc, char* szFunction, char* szFile, int iLine return rc; } +void __stdcall virtualbox_com_raise_error(HRESULT rc, IErrorInfo* perrinfo) { + HRESULT hr; + CComPtr pErrorInfo; + CComBSTR strSource; + CComBSTR strDescription; + + pErrorInfo.Attach(perrinfo); + + vboxlog_msg("COM Error 0x%x", rc); + hr = pErrorInfo->GetSource(&strSource); + if (SUCCEEDED(hr) && strSource) { + vboxlog_msg("Error Source : %S", strSource); + } + hr = pErrorInfo->GetDescription(&strDescription); + if (SUCCEEDED(hr) && strDescription) { + vboxlog_msg("Error Description: %S", strDescription); + } + + DebugBreak(); +} + // We want to recurisively walk the snapshot tree so that we can get the most recent children first. // We also want to skip whatever the most current snapshot is. @@ -166,6 +187,10 @@ void TraverseMediums(std::vector>& mediums, IMedium* pMedium) { VBOX_VM::VBOX_VM() { + // Initialize COM Exception Trap + // + _set_com_error_handler(virtualbox_com_raise_error); + m_pPrivate = new VBOX_PRIV(); }