System error messages
Posted: Thu Sep 12, 2002 1:05 am
Restored from previous forum. Originally posted by Hi-Toro.
Code updated to 5.20
There's a post on the PB Resources site that does this, but it uses hard-coded strings; this will retrieve the string directly from the OS...
(BTW Can anyone tell me how you post on the PB Resources site?
--
See ya,
James L Boyd.
http://www.hi-toro.com/
--
Code updated to 5.20
There's a post on the PB Resources site that does this, but it uses hard-coded strings; this will retrieve the string directly from the OS...
(BTW Can anyone tell me how you post on the PB Resources site?
Code: Select all
; ----------------------------------------------
; ShowError -- call on failure of a function...
; ----------------------------------------------
; The Windows GetLastError function applies to
; errors caused in the current program (ie. not
; system-wide).
; ------------------------------------------------------------
; IMPORTANT: Call InitErrors (0) at the start of your program!
; ------------------------------------------------------------
; INITERRORS (0)
; Needed, or GetLastError returns 126 ("Module not found") for some
; reason! Maybe something PB programs try to call while loading?
; You must pass 0 as the default parameter. You can see some
; of the other error messages available though, if you set it to
; another number, then call ShowError
Procedure InitErrors (DefaultError)
SetLastError_ (DefaultError)
EndProcedure
; SHOWERROR (title$)
; Puts up a dialog box with last error message, only if an error
; has occurred. The title$ parameter appears in the title bar of
; the dialog box.
Procedure.s ShowError (title$)
error = GetLastError_ ()
If error
*MemoryID = AllocateMemory (255)
FormatMessage_ (#FORMAT_MESSAGE_FROM_SYSTEM, #Null, error, 0, *MemoryID, 255, #Null)
e$ = PeekS (*MemoryID)
FreeMemory (*MemoryID)
MessageRequester (title$, e$, #MB_ICONWARNING) ; ProcedureReturn e$ ; Alternative to MessageRequester!
EndIf
EndProcedure
; ----------------------------------------------
; D E M O . . .
; ----------------------------------------------
InitErrors (0)
If CreateFile (0, "bollox:\test.txt")
CloseFile (0)
EndIf
ShowError ("Oh dear...")See ya,
James L Boyd.
http://www.hi-toro.com/
--