[Scripting] System Error Code retrieve message

DOpus.FSUtil.OpenFile (File object) has an error property which returns a Win32 error code. Those codes are described on these MSDN pages, and there is a FormatMessage function mentioned for which it says:

The following list describes system error codes (errors 0 to 499). They are returned by the GetLastError function when many functions fail. To retrieve the description text for the error in your application, use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag.

However this cannot be called in jscript, (I think only in vbscript could this be cludged out to work), so what I'm asking is, could Opus have some kind of scripting function which accepts Win32 error code and returns error description text (unicode string or what have you) by using this FormatMessage function internally?

Use case for this is, I'm making a Drive test button script for Opus, and when an error is detected, I'd like to be able to show the description to the user instead of just Win32 error code returned by the error property of DOpus.FSUtil.OpenFile.

Also, there is a chance that these descriptions are localized by Microsoft, so that would definitely be a bonus.

Yesterday I had an opportunity to use the Win32 API's GetLastError and FormatMessage functions in my C++ project, so I've decided to revisit this thread. FormatMessage does display the error message with a helpful localized description.

For example, in my utility for controlling Dell monitors, if I call the SetVCPFeature with the wrong monitor handle, the GetLastError with FormatMessage produces this helpful string:

This function failed because an invalid monitor handle was passed to it.

Which is very friendly and helpful to show to the user (as opposed to obscure error code). So, it would be really useful to have this wrapped in Opus for use in scripting if possible (as described in the original post). :opusicon::muscle:

You could make use of this.. somehow. o)
Win32_SystemErrorCodes.json.txt (692.7 KB)

Haha yes I had such an idea too :smiley:
But one of the drawbacks would be that the error messages wouldn't be localized.

We'll add this in the next version.

1 Like