SCardIsValidContext function (winscard.h)

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


LONG SCardIsValidContext(
  [in] SCARDCONTEXT hContext


[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
The hContext parameter is valid.
The hContext parameter is not valid.
Other values
An error code. For more information, see Smart Card Return Values.


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.


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");
        // Some unexpected error occurred; report and bail out.
        printf("Failed SCardIsValidContext - %x\n", lReturn);
        exit(1);  // Or other appropriate error action.
    // Handle is valid; proceed as needed.
    // ...


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