CryptEnumProviderTypes function
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 WINAPI CryptEnumProviderTypes( _In_ DWORD dwIndex, _In_ DWORD *pdwReserved, _In_ DWORD dwFlags, _Out_ DWORD *pdwProvType, _Out_ LPTSTR pszTypeName, _Inout_ DWORD *pcbTypeName );
Parameters
- dwIndex [in]
-
Index of the next provider type to be enumerated.
- pdwReserved [in]
-
Reserved for future use and must be NULL.
- dwFlags [in]
-
Reserved for future use and must be zero.
- pdwProvType [out]
-
Address of the DWORD value designating the enumerated provider type.
- pszTypeName [out]
-
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.
- pcbTypeName [in, out]
-
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 |
|---|---|
|
There are no more items to enumerate. |
|
The operating system ran out of memory. |
|
The dwFlags parameter has an unrecognized value. |
|
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.
Requirements
|
Minimum supported client |
Windows XP [desktop apps only] |
|---|---|
|
Minimum supported server |
Windows Server 2003 [desktop apps only] |
|
Header |
|
|
Library |
|
|
DLL |
|
|
Unicode and ANSI names |
CryptEnumProviderTypesW (Unicode) and CryptEnumProviderTypesA (ANSI) |
See also