Dank der neuen Define-Compiler-Directiven kann man das Teil auch sehr komfortabel gestalten.
Wann immer ihr nen Fehler inner Exe sucht, pappt ihr das Teil einfach an den Anfang eures Source-Codes, oder macht ne Include draus und compiliert das ganze.
(Nur noch die OnError unterstützung aktivieren... wieso gibts dafür eigentlich noch keinen Compiler-Schalter ? Oder weiss ich nur nix davon...)
Viel Spass
[Edit]
12.12.2008 Nun auch mit PB4.3 nutzbar.
13.12.2008 Continue-Button bei PB4.3 entfernt
08.12.2020 DPI Awareness hinzugefügt
09.12.2020 Auf MessageRequester umgebaut.
Code: Alles auswählen
;+------------------------------------------------------
;|
;| OnError Include for PB >=4.0
;|
;| Usage:
;| Define the following Constants in your main program:
;|
;| #APP_NAME = "Name of your Application"
;| #APP_VERSION = "1.0"
;| #APP_AUTOR = "Name of Autor"
;| #APP_AUTOR_EMAIL = "email_of_autor@mail.com"
;|
;| #USE_ON_ERROR = #True -> OnError will be used
;| = #False -> OnError won't be used
;|
;| Alternative:
;| Fill the DEFAULT-Constants with your normal Values
;|
;| Copy/Paste this to the top of your application
;| (or create an includefile)
;|
;| Have Fun
;| HeX0R
;|
;+-------------------------------------------------------
;
;-Default Values
; (will be used if nothing is set in main application)
;{
#APP_NAME_DEFAULT = "Unknown Application"
#APP_VERSION_DEFAULT = "0.1"
#APP_AUTOR_DEFAULT = "Unknown Autor"
#APP_AUTOR_EMAIL_DEFAULT = "max.mustermann@web.de"
#USE_ON_ERROR_DEFAULT = #True
;}
CompilerIf Defined(USE_ON_ERROR, #PB_Constant) = 0
#USE_ON_ERROR = #USE_ON_ERROR_DEFAULT
CompilerEndIf
;
;-OnError Routine
;
CompilerIf #USE_ON_ERROR
;{
CompilerIf #PB_Compiler_LineNumbering = 0
CompilerError "Please enable the OnError compiler option!"
CompilerEndIf
CompilerIf #PB_Compiler_Debugger
CompilerError "Please disable Debugger, while OnError is activated!"
CompilerEndIf
CompilerIf Defined(APP_NAME, #PB_Constant) = 0
#APP_NAME = #APP_NAME_DEFAULT
CompilerEndIf
CompilerIf Defined(APP_VERSION, #PB_Constant) = 0
#APP_VERSION = #APP_VERSION_DEFAULT
CompilerEndIf
CompilerIf Defined(APP_AUTOR, #PB_Constant) = 0
#APP_AUTOR = #APP_AUTOR_DEFAULT
CompilerEndIf
CompilerIf Defined(APP_AUTOR_EMAIL, #PB_Constant) = 0
#APP_AUTOR_EMAIL = #APP_AUTOR_EMAIL_DEFAULT
CompilerEndIf
Procedure ErrorDialog()
Protected ExeFileName.s, MessageBody.s, ErrorHWND.l, A.l, B.l, C.l, Mail.s, dx.f, dy.f
CompilerIf #PB_Compiler_Version < 430
;-Parse Body-Message
MessageBody = "0x" + Hex(GetErrorNumber()) + #CRLF$ + #TAB$ + GetErrorDescription() + #CRLF$
MessageBody + #CRLF$
MessageBody + "Line:" + #TAB$ + Str(GetErrorLineNR()) + #CRLF$
MessageBody + "Modul:" + #TAB$ + GetErrorModuleName() + #CRLF$
Mail = GetErrorDLL()
If Mail
MessageBody + "Dll-Error:" + #TAB$ + Mail + #CRLF$
EndIf
MessageBody + #CRLF$
MessageBody + "EIP" + #TAB$ + "=" + #TAB$ + "0x" + Hex(GetErrorAddress()) + #CRLF$
MessageBody + "EAX" + #TAB$ + "=" + #TAB$ + "0x" + Hex(GetErrorRegister(#PB_OnError_EAX)) + #CRLF$
MessageBody + "EBX" + #TAB$ + "=" + #TAB$ + "0x" + Hex(GetErrorRegister(#PB_OnError_EBX)) + #CRLF$
MessageBody + "ECX" + #TAB$ + "=" + #TAB$ + "0x" + Hex(GetErrorRegister(#PB_OnError_ECX)) + #CRLF$
MessageBody + "EDX" + #TAB$ + "=" + #TAB$ + "0x" + Hex(GetErrorRegister(#PB_OnError_EDX)) + #CRLF$
MessageBody + "EBP" + #TAB$ + "=" + #TAB$ + "0x" + Hex(GetErrorRegister(#PB_OnError_EBP)) + #CRLF$
MessageBody + "EDI" + #TAB$ + "=" + #TAB$ + "0x" + Hex(GetErrorRegister(#PB_OnError_EDI)) + #CRLF$
MessageBody + "SegCS" + #TAB$ + "=" + #TAB$ + "0x" + Hex(GetErrorRegister(#PB_OnError_SegCS)) + #CRLF$
MessageBody + "FFlags" + #TAB$ + "=" + #TAB$ + "0x" + Hex(GetErrorRegister(#PB_OnError_FFLags))
CompilerElse
;-Parse Body-Message
MessageBody + "Error Message: " + ErrorMessage() + #CRLF$
MessageBody + "Error Code: " + Str(ErrorCode()) + #CRLF$
MessageBody + "Code Address: " + Str(ErrorAddress()) + #CRLF$
If ErrorCode() = #PB_OnError_InvalidMemory
MessageBody + "Target Address: " + Str(ErrorTargetAddress()) + #CRLF$
EndIf
If ErrorLine() = -1
MessageBody + "Sourcecode line: Enable OnError lines support to get code line information." + #CRLF$
Else
MessageBody + "Sourcecode line: " + Str(ErrorLine()) + #CRLF$
MessageBody + "Sourcecode file: " + ErrorFile() + #CRLF$
EndIf
MessageBody + #CRLF$
MessageBody + "Register content:" + #CRLF$
CompilerSelect #PB_Compiler_Processor
CompilerCase #PB_Processor_x86
MessageBody + "EAX" + #TAB$ + "=" + #TAB$ + "0x" + Hex(ErrorRegister(#PB_OnError_EAX)) + #CRLF$
MessageBody + "EBX" + #TAB$ + "=" + #TAB$ + "0x" + Hex(ErrorRegister(#PB_OnError_EBX)) + #CRLF$
MessageBody + "ECX" + #TAB$ + "=" + #TAB$ + "0x" + Hex(ErrorRegister(#PB_OnError_ECX)) + #CRLF$
MessageBody + "EDX" + #TAB$ + "=" + #TAB$ + "0x" + Hex(ErrorRegister(#PB_OnError_EDX)) + #CRLF$
MessageBody + "EBP" + #TAB$ + "=" + #TAB$ + "0x" + Hex(ErrorRegister(#PB_OnError_EBP)) + #CRLF$
MessageBody + "ESI" + #TAB$ + "=" + #TAB$ + "0x" + Hex(ErrorRegister(#PB_OnError_ESI)) + #CRLF$
MessageBody + "EDI" + #TAB$ + "=" + #TAB$ + "0x" + Hex(ErrorRegister(#PB_OnError_EDI)) + #CRLF$
MessageBody + "ESP" + #TAB$ + "=" + #TAB$ + "0x" + Hex(ErrorRegister(#PB_OnError_ESP)) + #CRLF$
CompilerCase #PB_Processor_x64
MessageBody + "RAX" + #TAB$ + "=" + #TAB$ + "0x" + Hex(ErrorRegister(#PB_OnError_RAX)) + #CRLF$
MessageBody + "RBX" + #TAB$ + "=" + #TAB$ + "0x" + Hex(ErrorRegister(#PB_OnError_RBX)) + #CRLF$
MessageBody + "RCX" + #TAB$ + "=" + #TAB$ + "0x" + Hex(ErrorRegister(#PB_OnError_RCX)) + #CRLF$
MessageBody + "RDX" + #TAB$ + "=" + #TAB$ + "0x" + Hex(ErrorRegister(#PB_OnError_RDX)) + #CRLF$
MessageBody + "RBP" + #TAB$ + "=" + #TAB$ + "0x" + Hex(ErrorRegister(#PB_OnError_RBP)) + #CRLF$
MessageBody + "RSI" + #TAB$ + "=" + #TAB$ + "0x" + Hex(ErrorRegister(#PB_OnError_RSI)) + #CRLF$
MessageBody + "RDI" + #TAB$ + "=" + #TAB$ + "0x" + Hex(ErrorRegister(#PB_OnError_RDI)) + #CRLF$
MessageBody + "RSP" + #TAB$ + "=" + #TAB$ + "0x" + Hex(ErrorRegister(#PB_OnError_RSP)) + #CRLF$
MessageBody + "Display of registers R8-R15 skipped." + #CRLF$
CompilerCase #PB_Processor_PowerPC
MessageBody + "r0" + #TAB$ + "=" + #TAB$ + "0x" + Hex(ErrorRegister(#PB_OnError_r0)) + #CRLF$
MessageBody + "r1" + #TAB$ + "=" + #TAB$ + "0x" + Hex(ErrorRegister(#PB_OnError_r1)) + #CRLF$
MessageBody + "r2" + #TAB$ + "=" + #TAB$ + "0x" + Hex(ErrorRegister(#PB_OnError_r2)) + #CRLF$
MessageBody + "r3" + #TAB$ + "=" + #TAB$ + "0x" + Hex(ErrorRegister(#PB_OnError_r3)) + #CRLF$
MessageBody + "r4" + #TAB$ + "=" + #TAB$ + "0x" + Hex(ErrorRegister(#PB_OnError_r4)) + #CRLF$
MessageBody + "r5" + #TAB$ + "=" + #TAB$ + "0x" + Hex(ErrorRegister(#PB_OnError_r5)) + #CRLF$
MessageBody + "r6" + #TAB$ + "=" + #TAB$ + "0x" + Hex(ErrorRegister(#PB_OnError_r6)) + #CRLF$
MessageBody + "r7" + #TAB$ + "=" + #TAB$ + "0x" + Hex(ErrorRegister(#PB_OnError_r7)) + #CRLF$
MessageBody + "Display of registers r8-R31 skipped." + #CRLF$
CompilerEndSelect
CompilerEndIf
;-Parse Mail-Message
Mail = "mailto:" + #APP_AUTOR_EMAIL
Mail + "?subject=Error Description&body="
Mail + "Hi " + #APP_AUTOR + ",%0A"
Mail + "i discovered an Error with " + #APP_NAME + " V " + #APP_VERSION + " :%0A"
Mail + RemoveString(ReplaceString(MessageBody, #CRLF$, "%0A"), #TAB$)
MessageBody + #CRLF$ + #CRLF$ + "Do you want to send this by mail to the author?"
If MessageRequester(#APP_NAME + " V" + #APP_VERSION + " [Runtime-Error]", MessageBody, #PB_MessageRequester_YesNoCancel | #PB_MessageRequester_Error) = #PB_MessageRequester_Yes
RunProgram(Mail)
EndIf
ProcedureReturn 0
EndProcedure
;
;-Call to OnError
;
CompilerIf #PB_Compiler_Version < 430
OnErrorGosub(@ErrorDialog())
CompilerElse
OnErrorCall(@ErrorDialog())
CompilerEndIf
;}
CompilerEndIf
;Example
;F = A / B