PB4 - Win32 - Show-API-Error ()
Posted: Wed Apr 26, 2006 2:56 am
Code updated for 5.20+
I think some of you have tried to call any PB or API command and nothing happend. Now this small procedure may hopefully help you to find the problem
Good Luck! Feedback would be nice!
I think some of you have tried to call any PB or API command and nothing happend. Now this small procedure may hopefully help you to find the problem
Code: Select all
;-------------------------------------------------------------------------------------
; P u r e B a s i c v4 S h o w - A P I - E r r o r ( )
; -------------------------------------------------------------------------------------
;
; Description: This function examines, what was wrong with the last command call by
; API/PB like if nothing happens again! It returns a suitable error
; message string in your national language!
;
; Function: ShowAPIError (CheckReturnValue)
;
; Parameters: CheckReturnValue
;
; Enter here the value, where you have saved the return value of the
; API/PB command you have called and want to check.
;
; ReturnValue: A string including the message text will be returned.
;
; -------------------------------------------------------------------------------------
; Program by va!n aka Thorsten Will - 26/April/2006
; -------------------------------------------------------------------------------------
Procedure.s ShowAPIError (CheckReturnValue)
Buffer.s = Space (4096)
NumberOfChars = FormatMessage_(#FORMAT_MESSAGE_FROM_SYSTEM, 0, CheckReturnValue, 0, Buffer.s, Len(Buffer.s), 0)
ProcedureReturn Left (Buffer.s, NumberOfChars-2)
EndProcedure
; -------------------------------------------------------------------------------------
; S m a l l e x a m p l e
; -------------------------------------------------------------------------------------
result = Sleep_(2)
Debug ShowAPIError(result) ; No Error
result = RegOpenKeyEx_(0, 0, 0, 0, 0)
Debug ShowAPIError(result) ; Error
result = MessageBox_(0,0,0,0)
Debug ShowAPIError(result) ; Error (after pressing the MsgBox)
;-------------------------------------------------------------------------------------