CryptoSys PKI Pro Manual

PKI_LastError

Retrieves the last error message set by the toolkit.

VBA/VB6 Syntax

Public Declare Function PKI_LastError Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long) As Long

nRet = PKI_LastError(strOutput, nOutChars)

C/C++ Syntax

long __stdcall PKI_LastError(char *szOutput, long nOutChars);

Parameters

szOutput
[out] to receive last error message.
nOutChars
[in] specifying the maximum length of the string to be copied.

Returns (VBA/C)

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.

VBA Wrapper Syntax

Public Function pkiLastError() As String

.NET Equivalent

General.LastError Method

C++ (STL) Equivalent

static std::string dipki::Err::LastError ()

Python Equivalent

static Gen.last_error()

Remarks

Not all functions set the error message string. The error message will never be longer than 511 characters.

Example (VBA/C core function)

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");
}

Example (VBA wrapper function)

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'

See Also

PKI_ErrorCode PKI_ErrorLookup Error codes

[Contents] [Index]

[PREV: PKI_FormatErrorMessage...]   [Contents]   [Index]   
   [NEXT: PKI_LicenceType...]

Copyright © 2004-24 D.I. Management Services Pty Ltd. All rights reserved. Generated 2024-09-23T07:52:09Z.