Archive: FileOpen error: how to get descriptive text?


FileOpen error: how to get descriptive text?
I use the following code to trap any errors when I am writing to a file:


FileOpen $0 $INSTDIR\new_file_name w
StrCpy $R1 "creation error"
ifErrors errors

FileWrite $0 $R1
StrCpy $R1 "write error"
ifErrors errors

FileClose $0
StrCpy $R1 "close error"
ifErrors errors
Goto end
errors:
MessageBox MB_OK "Error with file: $R1"
end:

This certainly works and traps the errors. However, all I know when I run this is that I have a creation error, or a write error, etc. How can I get the cause of the error (disk full, no permission, file exists, etc)?

I can't see anything in the manual that helps, and there is no code online that has given me any clues.

Any thoughts are welcome.

Thanks.


Best you can do, without changing the source, is use Windows API directly with the System plug-in. The System plug-in has an option to return the last error code - ?e. You can pass this error code to the FormatMessage API to get a textual message.


OK, thanks. I'll do a bit of digging into the plugins.