CryptEnumProviderTypesA function (wincrypt.h)

Important  This API is deprecated. New and existing software should start using Cryptography Next Generation APIs. Microsoft may remove this API in future releases.
 
The CryptEnumProviderTypes function retrieves the first or next types of cryptographic service provider (CSP) supported on the computer. Used in a loop, this function retrieves in sequence all of the CSP types available on a computer.

Provider types include PROV_RSA_FULL, PROV_RSA_SCHANNEL, and PROV_DSS.

Syntax

BOOL CryptEnumProviderTypesA(
  [in]      DWORD dwIndex,
  [in]      DWORD *pdwReserved,
  [in]      DWORD dwFlags,
  [out]     DWORD *pdwProvType,
  [out]     LPSTR szTypeName,
  [in, out] DWORD *pcbTypeName
);

Parameters

[in] dwIndex

Index of the next provider type to be enumerated.

[in] pdwReserved

Reserved for future use and must be NULL.

[in] dwFlags

Reserved for future use and must be zero.

[out] pdwProvType

Address of the DWORD value designating the enumerated provider type.

[out] szTypeName

A pointer to a buffer that receives the data from the enumerated provider type. This is a string including the terminating NULL character. Some provider types do not have display names, and in this case no name is returned and the returned value pointed to by pcbTypeName is zero.

This parameter can be NULL to get the size of the name for memory allocation purposes. For more information, see Retrieving Data of Unknown Length.

[in, out] pcbTypeName

A pointer to a DWORD value specifying the size, in bytes, of the buffer pointed to by the pszTypeName parameter. When the function returns, the DWORD value contains the number of bytes stored or to be stored in the buffer. Some provider types do not have display names, and in this case no name is returned and the returned value pointed to by pcbTypeName is zero.

Note  When processing the data returned in the buffer, applications must use the actual size of the data returned. The actual size can 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 fits 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 value

If the function succeeds, the return value is nonzero (TRUE).

If the function fails, the return value is zero (FALSE). For extended error information, call GetLastError.

The error codes prefaced by NTE are generated by the particular CSP being used. Some possible error codes follow.

Return code Description
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
The dwFlags parameter has an unrecognized value.
NTE_FAIL
Something was wrong with the type registration.

Remarks

This function enumerates the provider types available on a computer. Providers for any specific provider type can be enumerated using CryptEnumProviders.

Examples

The following example shows a loop listing all available cryptographic service provider types.

#include <stdio.h>
#include <windows.h>
#include <Wincrypt.h>
#pragma comment(lib, "advapi32.lib")

void main()
{
    
    // Copyright (C) Microsoft.  All rights reserved.
    // Declare and initialize variables.

    DWORD       dwIndex;
    DWORD       dwType;
    DWORD       cbName;
    LPTSTR      pszName;

    //--------------------------------------------------------------
    //   Print header lines for provider types.

    printf("Listing Available Provider Types:\n");
    printf("Provider type\tProvider Type Name\n");
    printf("_____________\t_____________________________________\n");

    // Loop through enumerating provider types.
    dwIndex = 0;
    while(CryptEnumProviderTypes(
           dwIndex,
           NULL,
           0,
           &dwType,
           NULL,
           &cbName
           ))
    {

        //-----------------------------------------------------------
        //  cbName returns the length of the name of the next
        //  provider type. Allocate memory in a buffer to retrieve
        //  that name.
        if (!(pszName = (LPTSTR)LocalAlloc(LMEM_ZEROINIT, cbName)))
        {
           printf("ERROR - LocalAlloc failed.\n");
           exit(1);
        }
        //-----------------------------------------------------------
        //  Get the provider type name.

        if (CryptEnumProviderTypes(
               dwIndex++,
               NULL,
               NULL,
               &dwType,   
               pszName,
               &cbName))     
        {
            printf ("     %4.0d\t%s\n",dwType, pszName);
        }
        else
        {
            printf("ERROR - CryptEnumProviderTypes\n");
            exit(1);
        }
        LocalFree(pszName);
    } // End of while loop.
}

For another example that uses the CryptEnumProviderTypes function, see Example C Program: Enumerating CSP Providers and Provider Types.

Note

The wincrypt.h header defines CryptEnumProviderTypes as an alias that 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 is 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 wincrypt.h
Library Advapi32.lib
DLL Advapi32.dll

See also

CryptEnumProviders

Service Provider Functions