diff --git a/samples/vboxwrapper/vbox_win.cpp b/samples/vboxwrapper/vbox_win.cpp index 84a1c1fde4..fd4c77320e 100644 --- a/samples/vboxwrapper/vbox_win.cpp +++ b/samples/vboxwrapper/vbox_win.cpp @@ -46,6 +46,39 @@ using std::string; +// Helper function to print MSCOM exception information set on the current +// thread after a failed MSCOM method call. This function will also print +// extended VirtualBox error info if it is available. +// +void virtualbox_dump_error() { + HRESULT rc; + char buf[256]; + CComPtr pErrorInfo; + CComBSTR strDescription; + + rc = GetErrorInfo(0, &pErrorInfo); + + if (FAILED(rc)) { + fprintf( + stderr, + "%s Error: getting error info! rc = 0x%x\n", + vboxwrapper_msg_prefix(buf, sizeof(buf)), + rc + ); + } else { + rc = pErrorInfo->GetDescription(&strDescription); + if (SUCCEEDED(rc)) { + fprintf( + stderr, + "%s Error description: %S\n", + vboxwrapper_msg_prefix(buf, sizeof(buf)), + CW2A(strDescription) + ); + } + } +} + + const char *MachineStateToName(MachineState State) { switch (State) @@ -97,49 +130,6 @@ const char *MachineStateToName(MachineState State) } -// -// Helper function to print MSCOM exception information set on the current -// thread after a failed MSCOM method call. This function will also print -// extended VirtualBox error info if it is available. -// -void virtualbox_dump_error() { - HRESULT rc; - BSTR strDescription = NULL; - char buf[256]; - IErrorInfo* pErrorInfo; - - rc = GetErrorInfo(0, &pErrorInfo); - - if (FAILED(rc)) { - fprintf( - stderr, - "%s Error: getting error info! rc = 0x%x\n", - vboxwrapper_msg_prefix(buf, sizeof(buf)), - rc - ); - } else { - rc = pErrorInfo->GetDescription(&strDescription); - if (FAILED(rc) || !strDescription) { - fprintf( - stderr, - "%s Error: getting error description! rc = 0x%x\n", - vboxwrapper_msg_prefix(buf, sizeof(buf)), - rc - ); - } else { - fprintf( - stderr, - "%s Error description: %S\n", - vboxwrapper_msg_prefix(buf, sizeof(buf)), - strDescription - ); - SysFreeString(strDescription); - } - pErrorInfo->Release(); - } -} - - VBOX_VM::VBOX_VM() { VBOX_BASE::VBOX_BASE();