Thalon
Anmeldedatum: 25.10.2005 Beiträge: 1867 Wohnort: Österreich
|
Verfasst am: Fr Feb 09, 2007 4:04 pm Titel: Funktion für den Fehlerstring von "A_LastError" |
|
|
Die Funktion GetErrorString kann dazu verwendet werden den korrekten Fehlerstring zu allen System-Fehler-IDs zu finden.
Dies tritt üblicherweise bei DllCalls auf (A_LastError).
| Code: | GetErrorString(Errornumber)
{
VarSetCapacity(ErrorString, 1024) ;String to hold the error-message.
DllCall("FormatMessage"
, UINT, 0x00001000 ;FORMAT_MESSAGE_FROM_SYSTEM: The function should search the system message-table resource(s) for the requested message.
, UINT, NULL ;A handle to the module that contains the message table to search.
, UINT, Errornumber
, UINT, 0 ;Language-ID is automatically retreived
, Str, ErrorString
, UINT, 1024 ;Buffer-Length
, str, "") ;An array of values that are used as insert values in the formatted message. (not used)
StringReplace, ErrorString, ErrorString, `r`n, %A_Space%, All ;Replaces newlines by A_Space for inline-output
return %ErrorString%
} |
Hier ein kleines Beispiel mit einem gültigen und einem ungültigen DllCall: | Code: | ;Calls the Windows API function "MessageBox" and report which button the user presses.
;Correct Call
WhichButton := DllCall("MessageBox", "int", "0", "str", "Press Yes or No", "str", "Title of box", "int", 4)
if A_LastError != 0
msgbox % GetErrorString(A_LastError)
else
MsgBox You pressed button #%WhichButton%.
;Incorrect Call
WhichButton := DllCall("MessageBox", "int", "0", "str", "Press Yes or No", "str", "Title of box", "int", 7)
if A_LastError != 0
msgbox % GetErrorString(A_LastError)
else
MsgBox You pressed button #%WhichButton%.
return |
_________________ Mein Motto: Hilfe zur Selbsthilfe!
Teildeutsche Hilfe (CHM)!! und Deutsche Online-Hilfe |
|