devxlogo

SystemErrorDescription – Convert an API error code to a string

SystemErrorDescription – Convert an API error code to a string

Private 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 LongPrivate Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000' Convert an API error number to a descriptive string'' If any error it returns an empty string, in which case' the Err.LastDllError property can be use to retrieve' extended error informationFunction SystemErrorDescription(ByVal ErrCode As Long) As String    Dim buffer As String * 1024    Dim ret As Long    ' return value is the length of the result message    ret = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, ErrCode, 0, buffer, _        Len(buffer), 0)    SystemErrorDescription = Left$(buffer, ret)End Function

devx-admin

Share the Post: