SCardIsValidContext function (winscard.h)

The SCardIsValidContext function determines whether a smart card context handle is valid.

Syntax

LONG SCardIsValidContext(
  [in] SCARDCONTEXT hContext
);

Parameters

[in] hContext

Handle that identifies the resource manager context. The resource manager context can be set by a previous call to SCardEstablishContext.

Return value

This function returns one of the following values.

Return code Description
SCARD_S_SUCCESS
The hContext parameter is valid.
ERROR_INVALID_HANDLE
The hContext parameter is not valid.
Other values
An error code. For more information, see Smart Card Return Values.

Remarks

Call this function to determine whether a smart card context handle is still valid. After a smart card context handle has been set by SCardEstablishContext, it may become not valid if the resource manager service has been shut down.

Examples

The following example shows determining whether a smart card context handle is valid.

// Check the smart card context handle.
// hContext was set previously by SCardEstablishContext.

LONG    lReturn;
lReturn = SCardIsValidContext(hContext);
if ( SCARD_S_SUCCESS != lReturn )
{
    // Function failed; check return value.
    if ( ERROR_INVALID_HANDLE == lReturn )
        printf("Handle is invalid\n");
    else
    {
        // Some unexpected error occurred; report and bail out.
        printf("Failed SCardIsValidContext - %x\n", lReturn);
        exit(1);  // Or other appropriate error action.
    }
}
else
{
    // Handle is valid; proceed as needed.
    // ...
}

Requirements

Requirement Value
Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Target Platform Windows
Header winscard.h
Library Winscard.lib
DLL Winscard.dll

See also

SCardEstablishContext