CryptEnumProviders

The CryptEnumProviders function is used to enumerate the providers on a machine.

#include <wincrypt.h>
BOOL WINAPI CryptEnumProviders(
  DWORD dwIndex,        // in
  DWORD *pdwReserved,   // in
  DWORD dwFlags,        // in
  DWORD *pdwProvType,   // out
  LPTSTR pszProvName,   // out
  DWORD *pcbProvName    // in/out
);
 

Parameters

dwIndex
The index of the next provider to be enumerated.
pdwReserved
This parameter is reserved for future use and must be NULL.
dwFlags
The flag values. This parameter is reserved for future use and should always be zero.
pdwProvType
The address of the DWORD value designating the type of the enumerated provider.
pszProvName
Pointer to a buffer that receives the data from the enumerated provider. This is a string including the terminating NULL character.

This parameter can be NULL to set the size of the name for memory allocation purposes. For more information, see the "Common In/Out Parameter Conventions" section at the beginning of this Reference.

pcbProvName
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. This parameter can be NULL, only if pszProvName is NULL.

Note that 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 insure 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

If the function succeeds, the return value is TRUE. If it fails, the return value is FALSE. To retrieve extended error information, use the GetLastError function.

The following table lists the error codes most commonly returned by the GetLastError function. The error codes prefaced by "NTE" are generated by the particular CSP you are using.

Error code 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.

Example

long       i;
LPTSTR     pszName;
DWORD      cbName;
DWORD      dwErr;

// Loop through enumerating provider types.
for (i=0;;i++)
{
if (!CryptEnumProviders(i, NULL, 0, &dwType, NULL, &cbName))
    {if (ERROR_NO_MORE_ITEMS != (dwErr = GetLastError()))
        {printf("ERROR - CryptEnumProviderTypes : %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))
   {if (ERROR_NO_MORE_ITEMS != (dwErr = GetLastError()))
       {printf("ERROR - CryptEnumProviderTypes : %X\n", dwErr);
       }
    LocalFree(pszName);
    break;
   }
printf ("Provider %s is type %d\n", pszName, dwType);
LocalFree(pszName);
}
 

QuickInfo

  Windows NT: Requires version 5.0 or later.
  Windows: Unsupported.
  Windows CE: Unsupported.
  Header: Declared in wincrypt.h.
  Import Library: Use advapi32.lib.
  Unicode: Defined as Unicode and ANSI prototypes.

See Also

CryptEnumProviderTypes