Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

System Errors Message Text

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • System Errors Message Text

    This is an enhanced version of a fucntion I have posted several times before... except this version has been updated to
    A) Be %UNICODE equate (and Wide char) aware
    B) Include the extended internet errors


    Code:
    ' SYSEMT.INC
    ' FUNCTION TO RETURN (nnnn) text from result of GetLastError
    ' Added as library #INCLUDE 11/09/02
    ' added %SYSEMNT_INC include control 2/27/04
    ' 08.03.12: Add test for %UNICODE defined and if so change to WSTRING where appropriate
    ' 09.12.13: Add WinInetSpecificErrorText and constants.
    ' 02.19.14: Add handling of %ERROR_INTERNET_EXTENDED_ERROR.
    '
    ' WHen this is the error, the text and a number value come from InternetGetLastResponseInfo.
    ' This is kind of like a GLOBAL variable, retaining its value until the next call to WinInet function:
    '"InternetGetLastResponseInfo can be called multiple times until another function is called
    ' on this thread. When another function is called, the internal buffer that is storing
    ' the last response information is cleared."
    
    #IF NOT %DEF (%SYSEMT_INC)
    %SYSEMT_INC = 1
    
    #IF NOT %DEF (%INTERNET_ERROR_BASE) ' really means if WinInet.inc already included
    
    #IF %DEF(%UNICODE)
    DECLARE FUNCTION InternetGetLastResponseInfo LIB "wininet.dll" _
    ALIAS "InternetGetLastResponseInfoW" _
    ( _
    lpdwError AS DWORD, _ ' out
    lpszBuffer AS WSTRINGZ , _ ' out
    lpdwBufferLength AS DWORD _ ' in, out
    ) _
    AS LONG
    #ELSE
    DECLARE FUNCTION InternetGetLastResponseInfo LIB "wininet.dll" _
    ALIAS "InternetGetLastResponseInfoA" _
    ( _
    lpdwError AS DWORD, _ ' out
    lpszBuffer AS ASCIIZ, _ ' out
    lpdwBufferLength AS DWORD _ ' in, out
    ) _
    AS LONG
    #ENDIF
    
    %INTERNET_ERROR_BASE = 12000
    
    %ERROR_INTERNET_OUT_OF_HANDLES = (%INTERNET_ERROR_BASE + 1)
    %ERROR_INTERNET_TIMEOUT = (%INTERNET_ERROR_BASE + 2)
    %ERROR_INTERNET_EXTENDED_ERROR = (%INTERNET_ERROR_BASE + 3)
    %ERROR_INTERNET_INTERNAL_ERROR = (%INTERNET_ERROR_BASE + 4)
    %ERROR_INTERNET_INVALID_URL = (%INTERNET_ERROR_BASE + 5)
    %ERROR_INTERNET_UNRECOGNIZED_SCHEME = (%INTERNET_ERROR_BASE + 6)
    %ERROR_INTERNET_NAME_NOT_RESOLVED = (%INTERNET_ERROR_BASE + 7)
    %ERROR_INTERNET_PROTOCOL_NOT_FOUND = (%INTERNET_ERROR_BASE + 8)
    %ERROR_INTERNET_INVALID_OPTION = (%INTERNET_ERROR_BASE + 9)
    %ERROR_INTERNET_BAD_OPTION_LENGTH = (%INTERNET_ERROR_BASE + 10)
    %ERROR_INTERNET_OPTION_NOT_SETTABLE = (%INTERNET_ERROR_BASE + 11)
    %ERROR_INTERNET_SHUTDOWN = (%INTERNET_ERROR_BASE + 12)
    %ERROR_INTERNET_INCORRECT_USER_NAME = (%INTERNET_ERROR_BASE + 13)
    %ERROR_INTERNET_INCORRECT_PASSWORD = (%INTERNET_ERROR_BASE + 14)
    %ERROR_INTERNET_LOGIN_FAILURE = (%INTERNET_ERROR_BASE + 15)
    %ERROR_INTERNET_INVALID_OPERATION = (%INTERNET_ERROR_BASE + 16)
    %ERROR_INTERNET_OPERATION_CANCELLED = (%INTERNET_ERROR_BASE + 17)
    %ERROR_INTERNET_INCORRECT_HANDLE_TYPE = (%INTERNET_ERROR_BASE + 18)
    %ERROR_INTERNET_INCORRECT_HANDLE_STATE = (%INTERNET_ERROR_BASE + 19)
    %ERROR_INTERNET_NOT_PROXY_REQUEST = (%INTERNET_ERROR_BASE + 20)
    %ERROR_INTERNET_REGISTRY_VALUE_NOT_FOUND = (%INTERNET_ERROR_BASE + 21)
    %ERROR_INTERNET_BAD_REGISTRY_PARAMETER = (%INTERNET_ERROR_BASE + 22)
    %ERROR_INTERNET_NO_DIRECT_ACCESS = (%INTERNET_ERROR_BASE + 23)
    %ERROR_INTERNET_NO_CONTEXT = (%INTERNET_ERROR_BASE + 24)
    %ERROR_INTERNET_NO_CALLBACK = (%INTERNET_ERROR_BASE + 25)
    %ERROR_INTERNET_REQUEST_PENDING = (%INTERNET_ERROR_BASE + 26)
    %ERROR_INTERNET_INCORRECT_FORMAT = (%INTERNET_ERROR_BASE + 27)
    %ERROR_INTERNET_ITEM_NOT_FOUND = (%INTERNET_ERROR_BASE + 28)
    %ERROR_INTERNET_CANNOT_CONNECT = (%INTERNET_ERROR_BASE + 29)
    %ERROR_INTERNET_CONNECTION_ABORTED = (%INTERNET_ERROR_BASE + 30)
    %ERROR_INTERNET_CONNECTION_RESET = (%INTERNET_ERROR_BASE + 31)
    %ERROR_INTERNET_FORCE_RETRY = (%INTERNET_ERROR_BASE + 32)
    %ERROR_INTERNET_INVALID_PROXY_REQUEST = (%INTERNET_ERROR_BASE + 33)
    %ERROR_INTERNET_NEED_UI = (%INTERNET_ERROR_BASE + 34)
    
    %ERROR_INTERNET_HANDLE_EXISTS = (%INTERNET_ERROR_BASE + 36)
    %ERROR_INTERNET_SEC_CERT_DATE_INVALID = (%INTERNET_ERROR_BASE + 37)
    %ERROR_INTERNET_SEC_CERT_CN_INVALID = (%INTERNET_ERROR_BASE + 38)
    %ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR = (%INTERNET_ERROR_BASE + 39)
    %ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR = (%INTERNET_ERROR_BASE + 40)
    %ERROR_INTERNET_MIXED_SECURITY = (%INTERNET_ERROR_BASE + 41)
    %ERROR_INTERNET_CHG_POST_IS_NON_SECURE = (%INTERNET_ERROR_BASE + 42)
    %ERROR_INTERNET_POST_IS_NON_SECURE = (%INTERNET_ERROR_BASE + 43)
    %ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED = (%INTERNET_ERROR_BASE + 44)
    %ERROR_INTERNET_INVALID_CA = (%INTERNET_ERROR_BASE + 45)
    %ERROR_INTERNET_CLIENT_AUTH_NOT_SETUP = (%INTERNET_ERROR_BASE + 46)
    %ERROR_INTERNET_ASYNC_THREAD_FAILED = (%INTERNET_ERROR_BASE + 47)
    %ERROR_INTERNET_REDIRECT_SCHEME_CHANGE = (%INTERNET_ERROR_BASE + 48)
    %ERROR_INTERNET_DIALOG_PENDING = (%INTERNET_ERROR_BASE + 49)
    %ERROR_INTERNET_RETRY_DIALOG = (%INTERNET_ERROR_BASE + 50)
    %ERROR_INTERNET_HTTPS_HTTP_SUBMIT_REDIR = (%INTERNET_ERROR_BASE + 52)
    %ERROR_INTERNET_INSERT_CDROM = (%INTERNET_ERROR_BASE + 53)
    %ERROR_INTERNET_FORTEZZA_LOGIN_NEEDED = (%INTERNET_ERROR_BASE + 54)
    %ERROR_INTERNET_SEC_CERT_ERRORS = (%INTERNET_ERROR_BASE + 55)
    %ERROR_INTERNET_SEC_CERT_NO_REV = (%INTERNET_ERROR_BASE + 56)
    %ERROR_INTERNET_SEC_CERT_REV_FAILED = (%INTERNET_ERROR_BASE + 57)
    
    '
    ' FTP API errors
    '
    
    %ERROR_FTP_TRANSFER_IN_PROGRESS = (%INTERNET_ERROR_BASE + 110)
    %ERROR_FTP_DROPPED = (%INTERNET_ERROR_BASE + 111)
    %ERROR_FTP_NO_PASSIVE_MODE = (%INTERNET_ERROR_BASE + 112)
    
    #ENDIF ' if NOT %DEF(%INTERNET_ERROR_BASE
    
    #IF %DEF(%UNICODE)
    FUNCTION SystemErrorMessageText (BYVAL ECode AS LONG) AS WSTRING
    LOCAL Buffer AS WSTRINGZ * 255
    
    SELECT CASE AS LONG eCode
    CASE %ERROR_INTERNET_OUT_OF_HANDLES TO %ERROR_INTERNET_SEC_CERT_REV_FAILED, _
    %ERROR_FTP_TRANSFER_IN_PROGRESS TO %ERROR_FTP_NO_PASSIVE_MODE
    Buffer = WinInetSpecificErrorText (Ecode)
    CASE ELSE
    FormatMessage %FORMAT_MESSAGE_FROM_SYSTEM, BYVAL %NULL, ECode, %NULL, buffer, SIZEOF(buffer), BYVAL %NULL
    END SELECT
    FUNCTION = FORMAT$(ECode, "##### ") & Buffer
    END FUNCTION
    
    #ELSE
    ' original function
    FUNCTION SystemErrorMessageText (BYVAL ECode AS LONG) AS STRING
    LOCAL Buffer AS ASCIIZ * 255
    
    'MSGBOX "Enter Sysemt with ecode " & FORMAT$(Ecode)
    
    SELECT CASE AS LONG eCode
    CASE %ERROR_INTERNET_OUT_OF_HANDLES TO %ERROR_INTERNET_SEC_CERT_REV_FAILED, _
    %ERROR_FTP_TRANSFER_IN_PROGRESS TO %ERROR_FTP_NO_PASSIVE_MODE
    Buffer = WinInetSpecificErrorText (Ecode)
    ' MSGBOX "Sysemt buffer = " & BUffer,,"From New Function"
    CASE ELSE
    FormatMessage %FORMAT_MESSAGE_FROM_SYSTEM, BYVAL %NULL, ECode, %NULL, buffer, SIZEOF(buffer), BYVAL %NULL
    END SELECT
    
    
    
    FUNCTION = FORMAT$(ECode, "##### ") & Buffer
    END FUNCTION
    
    #ENDIF ' if %DEF(%UNICODE)
    
    
    
    ' From WinInet.INC:
    ' Internet API error returns
    
    
    ' ------------------------------------------------------------
    ' FUNCTION TO RETURN TEXT FOR WinInet Errors; called only when
    ' LE passed to systemErrorMessageText is in the supported range
    
    #IF %DEF(%UNICODE)
    FUNCTION WinInetSpecificErrorText (BYVAL iERR AS LONG) PRIVATE AS WSTRING
    LOCAL W AS WSTRING
    LOCAL szText AS WSTRINGZ * 1024
    
    #ELSE
    FUNCTION WinInetSpecificErrorText (BYVAL iERR AS LONG) PRIVATE AS STRING
    LOCAL W AS STRING
    LOCAL szText AS ASCIIZ * 1024
    #ENDIF
    ' Internet API error returns
    ' variables not subject to unicode or not.
    LOCAL iret AS LONG, nErr AS LONG, ccbText AS LONG
    'MSGBOX "Enter WinInetErrorText with Error code" & FORMAT$(iErr)
    
    ccbText = SIZEOF(szText) -1&
    SELECT CASE AS LONG iERR
    
    CASE %ERROR_INTERNET_OUT_OF_HANDLES : W = "Out of Handles"
    CASE %ERROR_INTERNET_TIMEOUT : W = "Timeout"
    CASE %ERROR_INTERNET_EXTENDED_ERROR
    iret = InternetGetLastResponseInfo (iErr, szText, ccbText)
    W = USING$ ("Extended error # &", iErr, LEFT$(szText, ccbText))
    
    
    CASE %ERROR_INTERNET_INTERNAL_ERROR : W = "Internal Error"
    CASE %ERROR_INTERNET_INVALID_URL : W = "Invalid URL"
    CASE %ERROR_INTERNET_UNRECOGNIZED_SCHEME : W = "Unrecognized Scheme"
    CASE %ERROR_INTERNET_NAME_NOT_RESOLVED : W = "Name not resolved"
    CASE %ERROR_INTERNET_PROTOCOL_NOT_FOUND : W = "Protocol Not Found"
    CASE %ERROR_INTERNET_INVALID_OPTION : W = "Invalid Option"
    CASE %ERROR_INTERNET_BAD_OPTION_LENGTH : W = "Invalid Option Length"
    CASE %ERROR_INTERNET_OPTION_NOT_SETTABLE : W = "Option Not Settable"
    CASE %ERROR_INTERNET_SHUTDOWN : W = "Internet Shutdown"
    CASE %ERROR_INTERNET_INCORRECT_USER_NAME : W = "Incorrect User Name"
    CASE %ERROR_INTERNET_INCORRECT_PASSWORD : W = "Incorrect Password"
    CASE %ERROR_INTERNET_LOGIN_FAILURE : W = "Login Failure"
    CASE %ERROR_INTERNET_INVALID_OPERATION : W = "Invalid Operation"
    CASE %ERROR_INTERNET_OPERATION_CANCELLED : W = "Operation Canceled"
    CASE %ERROR_INTERNET_INCORRECT_HANDLE_TYPE : W = "Invalid Handle Type"
    CASE %ERROR_INTERNET_INCORRECT_HANDLE_STATE : W = "Incorrect Handle State"
    CASE %ERROR_INTERNET_NOT_PROXY_REQUEST : W = "Not Proxy Request"
    CASE %ERROR_INTERNET_REGISTRY_VALUE_NOT_FOUND : W = "Registry Value Not Found"
    CASE %ERROR_INTERNET_BAD_REGISTRY_PARAMETER : W = "Bad Registry Parameter"
    CASE %ERROR_INTERNET_NO_DIRECT_ACCESS : W = "No Direct Access"
    CASE %ERROR_INTERNET_NO_CONTEXT : W = "No Context"
    CASE %ERROR_INTERNET_NO_CALLBACK : W = "No Callback"
    CASE %ERROR_INTERNET_REQUEST_PENDING : W = "Request Pending"
    CASE %ERROR_INTERNET_INCORRECT_FORMAT : W = "Incorrect Format"
    CASE %ERROR_INTERNET_ITEM_NOT_FOUND : W = "Item Not Found"
    CASE %ERROR_INTERNET_CANNOT_CONNECT : W = "Cannot Connect"
    CASE %ERROR_INTERNET_CONNECTION_ABORTED : W = "Connection Aborted"
    CASE %ERROR_INTERNET_CONNECTION_RESET : W = "Connection Reset"
    CASE %ERROR_INTERNET_FORCE_RETRY : W = "Force Retry"
    CASE %ERROR_INTERNET_INVALID_PROXY_REQUEST : W = "Invalid Proxy Request"
    CASE %ERROR_INTERNET_NEED_UI : W = "Need UI"
    
    CASE %ERROR_INTERNET_HANDLE_EXISTS : W = "Handle Exists"
    CASE %ERROR_INTERNET_SEC_CERT_DATE_INVALID : W = "Security Certificate Date Invalid"
    CASE %ERROR_INTERNET_SEC_CERT_CN_INVALID : W = "Security Certificate Invalid CN"
    CASE %ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR : W = "HTTP to HTTPS on Redirect"
    CASE %ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR : W = "HTTTS to HTTP on Redirect"
    CASE %ERROR_INTERNET_MIXED_SECURITY : W = "Mixed Security"
    CASE %ERROR_INTERNET_CHG_POST_IS_NON_SECURE : W = "CHG POSTt is Non-Secure"
    CASE %ERROR_INTERNET_POST_IS_NON_SECURE : W = "POST is Non_Secure"
    CASE %ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED : W = "Client Authorization Certificate Needed"
    CASE %ERROR_INTERNET_INVALID_CA : W = "Invalid Client Authorization"
    CASE %ERROR_INTERNET_CLIENT_AUTH_NOT_SETUP : W = "Client Authorization Not Set Up"
    CASE %ERROR_INTERNET_ASYNC_THREAD_FAILED : W = "Asych thread failed"
    CASE %ERROR_INTERNET_REDIRECT_SCHEME_CHANGE : W = "Redirect Scheme Change"
    CASE %ERROR_INTERNET_DIALOG_PENDING : W = "Dialog Pending"
    CASE %ERROR_INTERNET_RETRY_DIALOG : W = "Retry Dialog"
    CASE %ERROR_INTERNET_HTTPS_HTTP_SUBMIT_REDIR : W = "HTTPS-HTTP SUBMIT Redirect"
    CASE %ERROR_INTERNET_INSERT_CDROM : W = "Insert CD-ROM"
    CASE %ERROR_INTERNET_FORTEZZA_LOGIN_NEEDED : W = "FORTEZZA Login Needed"
    CASE %ERROR_INTERNET_SEC_CERT_ERRORS : W = "Security Certificate Errors"
    CASE %ERROR_INTERNET_SEC_CERT_NO_REV : W = "Security Certificate has no Revision"
    CASE %ERROR_INTERNET_SEC_CERT_REV_FAILED : W = "Security Certificate Revision Failed"
    ' FTP API errors
    CASE %ERROR_FTP_TRANSFER_IN_PROGRESS : W = "FTP Transfer in Progress"
    CASE %ERROR_FTP_DROPPED : W = "FTP Dropped"
    CASE %ERROR_FTP_NO_PASSIVE_MODE : W = "FTP - No Passive mode"
    CASE ELSE : W = "Unexpected Error Code " & FORMAT$(iErr)
    END SELECT
    
    FUNCTION = W
    END FUNCTION
    
    
    
    ' END OF FILE
    #ENDIF ' if %DEF (%SYSEMT)
    MCM
    Last edited by Michael Mattias; 22 Apr 2021, 05:25 PM.
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com
Working...
X