SCardGetCardTypeProviderNameA function (winscard.h)

The SCardGetCardTypeProviderName function returns the name of the module (dynamic link library) that contains the provider for a given card name and provider type.

Syntax

LONG SCardGetCardTypeProviderNameA(
  [in]      SCARDCONTEXT hContext,
  [in]      LPCSTR       szCardName,
  [in]      DWORD        dwProviderId,
  [out]     CHAR         *szProvider,
  [in, out] LPDWORD      pcchProvider
);

Parameters

[in] hContext

Handle that identifies the resource manager context. The resource manager context can be set by a previous call to SCardEstablishContext. This value can be NULL if the call to SCardGetCardTypeProviderName is not directed to a specific context.

[in] szCardName

Name of the card type with which this provider name is associated.

[in] dwProviderId

Identifier for the provider associated with this card type.

Value Meaning
SCARD_PROVIDER_PRIMARY
1
The function retrieves the name of the smart card's primary service provider as a GUID string.
SCARD_PROVIDER_CSP
2
The function retrieves the name of the cryptographic service provider.
SCARD_PROVIDER_KSP
3
The function retrieves the name of the smart card key storage provider (KSP).
SCARD_PROVIDER_CARD_MODULE
0x80000001
The function retrieves the name of the card module.

[out] szProvider

String variable to receive the provider name upon successful completion of this function.

[in, out] pcchProvider

Pointer to DWORD value. On input, pcchProvider supplies the length of the szProvider buffer in characters. If this value is SCARD_AUTOALLOCATE, then szProvider is converted to a pointer to a byte pointer and receives the address of a block of memory containing the string. This block of memory must be deallocated by calling SCardFreeMemory.

On output, this value represents the actual number of characters, including the null terminator, in the szProvider variable.

Return value

This function returns different values depending on whether it succeeds or fails.

Return code Description
Success
SCARD_S_SUCCESS.
Failure
An error code. For more information, see Smart Card Return Values.

Remarks

This function is not redirected, but calling the function when inside a Remote Desktop session will not result in an error. It only means that the result will be from the remote computer instead of the local computer.

Upon successful completion of this function, the value in szProvider can be used as the third parameter in a call to CryptAcquireContext.

Examples

The following example shows how to retrieve the provider name for the specified reader context. The example assumes that hContext is a valid handle obtained from a previous call to the SCardEstablishContext function.

LPTSTR szProvider = NULL;
LPTSTR szCardName = _T("WindowsCard");
DWORD  chProvider = SCARD_AUTOALLOCATE;
LONG   lReturn = SCARD_S_SUCCESS;

// Retrieve the provider name.
// hContext was set by SCardEstablishContext.
lReturn = SCardGetCardTypeProviderName(hContext,
                                       szCardName,
                                       SCARD_PROVIDER_CSP,
                                       (LPTSTR)&szProvider,
                                       &chProvider);
if (SCARD_S_SUCCESS == lReturn)
{
    BOOL fSts = TRUE;
    HCRYPTPROV hProv = NULL;
  
  // Acquire a Cryptographic operation context.
    fSts = CryptAcquireContext(&hProv,
                               NULL,
                               szProvider,
                               PROV_RSA_FULL,
                               0);
    // Perform Cryptographic operations with smart card
    // ...

    // Free memory allocated by SCardGetCardTypeProviderName.
    lReturn = SCardFreeMemory(hContext, szProvider);
}

Note

The winscard.h header defines SCardGetCardTypeProviderName as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.

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

SCardFreeMemory

SCardSetCardTypeProviderName