Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This function determines whether a smart card context handle is valid.

Syntax

LONG SCardIsValidContext(
  SCARDCONTEXT 
hContext 
);

Parameters

hContext

[in] Supplies the handle that identifies the resource manager context. The resource manager context can be set by a previous call to SCardEstablishContext.

Return Value

Value Description

SCARD_S_SUCCESS

hContextis valid.

SCARD_E_INVALID_HANDLE

hContextis not valid.

An error value (see Smart Card Error Valuesfor a list of all error values).

Fails

Remarks

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

Copy Code
Example Code
// 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 ( SCARD_E_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

Header winscard.h
Library winscard.lib
Windows Embedded CE Windows CE .NET 4.1 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also