Getting HRESULT error text for an OLE object exception

106 Views Asked by At

I have an HRESULT scode (0x800A0034) in an EXCEPINFO structure from an IDispatch::Invoke() call on an OLE Object, and I'm trying to get the text associated with this error ("Bad file name or number").

Using the usual FormatMessage() function with FORMAT_MESSAGE_FROM_SYSTEM doesn't return any text. E.g.

int main()
{
   HRESULT hr = 0x800A0034;
   LPWSTR lpMsgBuf = nullptr;

   DWORD dwChars = FormatMessage(
      FORMAT_MESSAGE_ALLOCATE_BUFFER |
      FORMAT_MESSAGE_FROM_SYSTEM |
      FORMAT_MESSAGE_IGNORE_INSERTS,
      nullptr,
      hr,
      MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),
      reinterpret_cast<LPWSTR>( &lpMsgBuf ),
      0,
      nullptr );

   if ( dwChars > 0 )
   {
      std::wcout << L"Error message: " << lpMsgBuf << std::endl;
   }
   else
   {
      std::cerr << "Failed to get error message for HRESULT " << hr << std::endl;
   }

   LocalFree( lpMsgBuf );

   return 0;
}

Looking at the HRESULT further it's related to the FACILITY_CONTROL facility with a error code of 52 as defined in OleCtl.h (CTL_E_BADFILENAMEORNUMBER).

So, does anyone know the API for getting FACILITY_CONTROL error message text from Windows at runtime?

0

There are 0 best solutions below