Как получить текст ошибки от внешней API-функци Err.LastDllError (12029) - VB
Формулировка задачи:
Всем привет! Как получить текст ошибки от внешней API-функци Err.LastDllError (12029) Error (Err.LastDllError) результата не дает
Решение задачи: «Как получить текст ошибки от внешней API-функци Err.LastDllError (12029)»
textual
Листинг программы 1
Private Declare Function FormatMessage Lib "kernel32.dll" Alias "FormatMessageW" (ByVal dwFlags As Long, ByVal lpSource As Long, ByVal dwMessageId As Long, ByVal dwLanguageId As Long, ByVal lpBuffer As Long, ByVal nSize As Long, Arguments As Any) As Long Public Function ErrMessageText(lCode As Long) As String Const FORMAT_MESSAGE_FROM_SYSTEM As Long = &H1000& Const FORMAT_MESSAGE_IGNORE_INSERTS As Long = &H200 Dim sRtrnMsg As String Dim lret As Long sRtrnMsg = Space$(MAX_PATH) lret = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM Or FORMAT_MESSAGE_IGNORE_INSERTS, ByVal 0&, lCode, 0&, StrPtr(sRtrnMsg), MAX_PATH, 0&) If lret > 0 Then ErrMessageText = Left$(sRtrnMsg, lret) ErrMessageText = Replace$(ErrMessageText, vbCrLf, vbNullString) End If End Function
textual
Листинг программы 2
Private Declare Function FormatMessage Lib "kernel32.dll" Alias "FormatMessageW" (ByVal dwFlags As Long, ByVal lpSource As Long, ByVal dwMessageId As Long, ByVal dwLanguageId As Long, ByVal lpBuffer As Long, ByVal nSize As Long, Arguments As Any) As Long Private Declare Function GetModuleHandle Lib "kernel32.dll" Alias "GetModuleHandleW" (ByVal lpModuleName As Long) As Long Private Declare Function LoadLibrary Lib "kernel32.dll" Alias "LoadLibraryW" (ByVal lpFileName As Long) As Long Const MAX_PATH = 260& Public Function ErrMessageText(lCode As Long) As String Const FORMAT_MESSAGE_FROM_SYSTEM As Long = &H1000& Const FORMAT_MESSAGE_IGNORE_INSERTS As Long = &H200 Const FORMAT_MESSAGE_FROM_HMODULE As Long = &H800& Dim sRtrnMsg As String Dim lret As Long Dim hLib As Long sRtrnMsg = Space$(MAX_PATH) hLib = GetModuleHandle(StrPtr("wininet.dll")) If hLib = 0 Then hLib = LoadLibrary(StrPtr("wininet.dll")) End If lret = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM Or FORMAT_MESSAGE_FROM_HMODULE Or FORMAT_MESSAGE_IGNORE_INSERTS, ByVal hLib, lCode, 0&, StrPtr(sRtrnMsg), MAX_PATH, 0&) If lret > 0 Then ErrMessageText = Left$(sRtrnMsg, lret) ErrMessageText = Replace$(ErrMessageText, vbCrLf, vbNullString) End If End Function
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д