Retrieves the last error message set by the toolkit.
Public Declare Function PKI_LastError Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long) As Long
nRet = PKI_LastError(strOutput, nOutChars)
long __stdcall PKI_LastError(char *szOutput, long nOutChars);
If the preceding function call before calling PKI_LastError
was successful, the return value is
zero indicating no error; otherwise it is the number of characters that have been set in szOutput.
For the "raw" VBA/C function, the user must allocate an output string buffer szOutput of the required length.
Specify a zero nOutChars or an empty string for szOutput to find the required length.
ANSI C users must add one to this value when allocating memory.
Public Function pkiLastError
() As String
static std::string dipki::Err::LastError ()
static Gen.last_error()
Not all functions set the error message string. The error message will never be longer than 511 characters.
Sample C function to obtain the last error message.
/** Display error codes and corresponding messages. @param nRet Error code returned by last function. */ static void disp_error(long nRet) { long errcode; char lasterrmsg[PKI_MAX_LASTERROR_CHARS + 1] = { 0 }; char errlookupmsg[PKI_MAX_ERRORLOOKUP_CHARS + 1] = { 0 }; // Get error message that occurred when calling last function (if any) PKI_LastError(lasterrmsg, sizeof(lasterrmsg) - 1); // Get error code for first error that occurred (may be different from nRet) errcode = PKI_ErrorCode(); // Lookup message for error code if (errcode != 0) PKI_ErrorLookup(errlookupmsg, sizeof(errlookupmsg), errcode); else PKI_ErrorLookup(errlookupmsg, sizeof(errlookupmsg), nRet); // Display error details printf("ERROR Returned=%ld/Code=%ld: %s", nRet, errcode, errlookupmsg); // If we had a last error message, show it if (lasterrmsg[0]) printf(": %s\n", lasterrmsg); else printf("\n"); }
Dim s As String ' Valid function call, no error s = hashHexFromHex("616263", PKI_HASH_SHA1) Debug.Print "SHA1('abc')=" & s ' No error, so expecting empty string Debug.Print "LastError='" & pkiLastError() & "'" ' Force an error s = rsaFromXMLString("BADSTRING") Debug.Print "rsaFromXMLString(ERROR) returns '" & s & "'" Debug.Print "LastError='" & pkiLastError() & "'"
SHA1('abc')=a9993e364706816aba3e25717850c26c9cd0d89d LastError='' rsaFromXMLString(ERROR) returns '' LastError='Cannot find valid RSAKeyValue or RSAKeyPair element'
PKI_ErrorCode PKI_ErrorLookup Error codes