CryptEnumProviders

This function is used to enumerate the providers on a machine.

At a Glance

Header file: Wincrypt.h
Windows CE versions: 2.10 and later

Syntax

BOOL WINAPI CryptEnumProviders( DWORD dwIndex,
DWORD *pdwReserved, DWORD dwFlags, DWORD *pdwProvType,
LPTSTR pszProvName, DWORD *pcbProvName );

Parameters

dwIndex

[in] Specifies the index of the next provider to be enumerated.

pdwReserved

[in] Reserved for future use; set to NULL.

dwFlags

[in] Specifies a bitmask of flags. This parameter is reserved for future use and should always be zero.

pdwProvType

[in] Pointer to the DWORD value that designates the type of the enumerated provider.

pszProvName

[out] Pointer to a buffer that receives the data from the enumerated provider. A null-terminated string.

This parameter can be NULL to set the size of the name for memory allocation purposes.

pcbProvName

[in/out] Pointer to a variable that specifies the size, in bytes, of the buffer pointed to by the pszProvName parameter. When the function returns, the variable pointed to by the pcbProvName parameter contains the number of bytes stored in the buffer.

Note   When processing the data returned in the buffer, applications need to use the actual size of the data returned. The actual size may be slightly smaller than the size of the buffer specified on input. (On input, buffer sizes are usually specified large enough to ensure that the largest possible output data will fit in the buffer.) On output, the variable pointed to by this parameter is updated to reflect the actual size of the data copied to the buffer.

Return Values

TRUE indicates success. FALSE indicates failure. To get extended error information, call GetLastError. Common values for GetLastError are described in the following table. The error values prefaced by "NTE" are generated by the particular CSP you are using.

Value Description
ERROR_MORE_DATA The pszProvName buffer was not large enough to hold the provider name.
ERROR_NO_MORE_ITEMS There are no more items to enumerate.
ERROR_NOT_ENOUGH_MEMORY The operating system ran out of memory.
NTE_BAD_FLAGS dwFlags has an unrecognized value.
NTE_FAIL Something was wrong with the type registration.

Remarks

CryptEnumProviders is used to enumerate the providers on a machine. The provider types may be enumerated by using CryptEnumProviderTypes.

Windows CE does not support the ANSI version of this function.

Example

long i;
LPTSTR pszName;
DWORD dwType;
DWORD cbName;
DWORD dwErr;
 
// Loop through enumerating provider types.
for (i=0;;i++)
{
if (!CryptEnumProviders(
 i, // in- dwIndex
 NULL, // in- pdwReserved- set to NULL
 0, // in- dwFlags- set to 0
 &dwType, // out- pdwProvType
 NULL, // out- pszProvName- NULL on the first call
 &cbName // in, out-pcbProvName
 ))
 {if (ERROR_NO_MORE_ITEMS != (dwErr = GetLastError()))
 {printf("ERROR - CryptEnumProviders : %X\n", dwErr);
 }
 break;
 }

if (NULL == (pszName = (LPTSTR)LocalAlloc(LMEM_ZEROINIT, cbName)))
 {printf("ERROR - LocalAlloc failed!\n");
 }

if (!CryptEnumProviders(
 i,
 NULL,
 0,
 &dwType,
 pszName,
 &cbName // pcbProvName- size of pszName
 ))
 {if (ERROR_NO_MORE_ITEMS != (dwErr = GetLastError()))
 {printf("ERROR - CryptEnumProviders : %X\n", dwErr);
 }
 LocalFree(pszName);
 break;
 }
printf ("Provider %s is type %d\n", pszName, dwType);
LocalFree(pszName);
} 

See Also

CryptEnumProviderTypes