SCardGetCardTypeProviderName function

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 WINAPI SCardGetCardTypeProviderName(
  _In_    SCARDCONTEXT hContext,
  _In_    LPCTSTR      szCardName,
  _In_    DWORD        dwProviderId,
  _Out_   LPTSTR       szProvider,
  _Inout_ LPDWORD      pcchProvider
);

Parameters

hContext [in]

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.

szCardName [in]

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

dwProviderId [in]

Identifier for the provider associated with this card type.

ValueMeaning
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.

 

szProvider [out]

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

pcchProvider [in, out]

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


Requirements

Minimum supported client

Windows XP [desktop apps only]

Minimum supported server

Windows Server 2003 [desktop apps only]

Header

Winscard.h

Library

Winscard.lib

DLL

Winscard.dll

Unicode and ANSI names

SCardGetCardTypeProviderNameW (Unicode) and SCardGetCardTypeProviderNameA (ANSI)

See also

SCardSetCardTypeProviderName
SCardFreeMemory
SCardEstablishContext

 

 

Show: