Restored from previous forum. Originally posted by Rings.
Too big to post here, download at
http://www.reelmediaproductions.com/pb/ ... essage.zip
Code: Select all
;NOTE: this code has been posted in lieu of the broken link above
Procedure.s GetErrorMessage()
Define errCode, errMsgLength, errMessage.s, *msgBuffer
errCode = GetLastError_()
If errCode
*msgBuffer = AllocateMemory(255)
If *msgBuffer
errMsgLength = FormatMessage_ (#FORMAT_MESSAGE_FROM_SYSTEM, #Null,
errCode, 0, *msgBuffer, 255, #Null)
If errMsgLength > 1
errMessage = PeekS(*msgBuffer, errMsgLength - 2)
Else
errMessage = "Undefined error."
EndIf
FreeMemory(*msgBuffer)
Else
errMessage = "Unable to retrieve error message." + Chr(10) +
"(look up error code: " + Str(errCode) + ")"
EndIf
Else
errMessage = "No error found."
EndIf
ProcedureReturn errMessage
EndProcedure
;turn debugger off to test
LoadImage(1, "x:\xx.xxx") ;load non-existent file
MessageRequester("GetLastError:", GetErrorMessage())