Tipp 10.1 - API-Fehler
Wie kann ich die Beschreibung eines API-Fehlers ermitteln?
Mit dieser Funktion können Sie einen Dateiauswahldialog aufrufen. Kopieren Sie einfach nachfolgenden Quellcode in die Zwischenablage und fügen Sie anschließend den Inhalt der Zwischenablage in ein neues Modul ein. Die Aufrufparameter finden Sie im Quellcode beschrieben.
Verwendete Win32-Api-Aufrufe und Typen: FormatMessage
Beispiel:
Option Explicit Public Declare Function FormatMessage Lib "kernel32" Alias _ "FormatMessageA" _ (ByVal dwFlags As Long, _ lpSource As Any, _ ByVal dwMessageId As Long, _ ByVal dwLanguageId As Long, _ ByVal lpBuffer As String, _ ByVal nSize As Long, _ Arguments As Long) As Long Public Function APIErrorMessage(lErrCode As Long) As String '// -------------------------------------------------------- '// Methode: | Beschreibung eines API-Fehlers ermitteln '// -------------------------------------------------------- '// Parameter: | lErrCode - API-Fehlercode '// -------------------------------------------------------- '// Rückgabe: | Beschreibender Text des Fehlers '// -------------------------------------------------------- '// Autor: | Stefan Kulpa '// | EDV Innovation & Consulting - Dormagen '// -------------------------------------------------------- Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000 Const FORMAT_MESSAGE_IGNORE_INSERTS = &H200 Const FORMAT_MESSAGE_MAX_WIDTH_MASK = &HFF Const LANG_USER_DEFAULT = &H400& Dim sBuffer As String Dim lResult As Long sBuffer = Space$(257) lResult = _ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM Or _ FORMAT_MESSAGE_IGNORE_INSERTS Or _ FORMAT_MESSAGE_MAX_WIDTH_MASK, _ ByVal 0, lErrCode, LANG_USER_DEFAULT, _ ByVal sBuffer, 256, 0) If lResult Then APIErrorMessage = Left$(sBuffer, lResult) Else If lErrCode <> 0 Then APIErrorMessage = _ "Unbekannter Windows-Fehler: &H" & Hex$(lErrCode) End If End If End Function