Retrieves the error message associated with a given error code.
Public Declare Function API_ErrorLookup Lib "diCryptoSys.dll"
(ByVal strOutput As String, ByVal nMaxChars As Long, ByVal nErrorCode As Long) As Long
nRet = API_ErrorLookup(strOutput, nMaxChars, nErrorCode)
String to receive error message.Long specifying the maximum number of characters to be received.Long specifying the error code for which the message is required.
long _stdcall API_ErrorLookup(char *szOutput, long nMsgLen, long nErrCode);
Long: the number of characters in the output string or zero if there
is no corresponding error message.
The error message will never be longer than 127 characters.
The Visual Basic apiErrorLookup wrapper function is in the VB declaration module.
Public Function apiErrorLookup(nCode As Long) As String ' Returns a string with the error message for code nCode Dim strMsg As String Dim nRet As Long strMsg = String(128, " ") nRet = API_ErrorLookup(strMsg, Len(strMsg), nCode) apiErrorLookup = Left(strMsg, nRet) End Function
To use:
Dim nErrCode As Long
nErrCode = 33
Debug.Print "ErrorLookup(" & nErrCode & ")=" & apiErrorLookup(nErrCode)
ErrorLookup(33)=Invalid key length (BAD_KEY_LEN_ERROR)
To display all possible error messages:
Dim nRet As Long
Dim strErrMsg As String * 128
Dim i As Integer
For i = 0 To 10000
nRet = API_ErrorLookup(strErrMsg, Len(strErrMsg), i)
If (nRet > 0) Then
Debug.Print i & " = " & Left(strErrMsg, nRet)
End If
Next