0

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?

Carl
  • 1
  • 1
  • 1
    Not all error code (and headers) have an associated message dll. For the message you mention that comes from OleCtl.h, I don't think there is. I've grepped my Windows directory for it (found many in MFCxx.dll, jscript.dll, etc.) dll but there doesn't seem to be any resource message one. – Simon Mourier Jun 14 '23 at 17:35
  • @SimonMourier - Thanks for looking Simon - I did the same and couldn't find anything either - looks like I might have to do some hard-coding. – Carl Jun 15 '23 at 16:07
  • 1
    Facility code 10 is for libraries that implement their own controls. They are expected to use non-standard error codes and thus implement their own error reporting. Use the ISupportErrorInfo interface to check if they do, IErrorInfo to get the error text. – Hans Passant Jun 20 '23 at 03:07
  • @HansPassant - Thanks Hans - that was really helpful. The object in question ("Scripting.FileSystem") didn't implement that interface but I've added support for ISupportErrorInfo for use with other objects in the future. Much appreciated. – Carl Jul 20 '23 at 15:23

0 Answers0