CryptEnumProvidersW function (wincrypt.h)
Possible CSPs include Microsoft Base Cryptographic Provider version 1.0 and Microsoft Enhanced Cryptographic Provider version 1.0.
Syntax
BOOL CryptEnumProvidersW(
[in] DWORD dwIndex,
[in] DWORD *pdwReserved,
[in] DWORD dwFlags,
[out] DWORD *pdwProvType,
[out] LPWSTR szProvName,
[in, out] DWORD *pcbProvName
);
Parameters
[in] dwIndex
Index of the next provider 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 type of the enumerated provider.
[out] szProvName
A 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 Retrieving Data of Unknown Length.
[in, out] pcbProvName
A pointer to a DWORD value specifying the size, in bytes, of the buffer pointed to by the pszProvName parameter. When the function returns, the DWORD value contains the number of bytes stored in 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 |
---|---|
|
The pszProvName buffer was not large enough to hold the provider name. |
|
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 providers available on a computer. The provider types can be enumerated by using CryptEnumProviderTypes.
Examples
The following example shows a loop listing all available cryptographic service providers. For another example that uses the CryptEnumProviders function, see Example C Program: Enumerating CSP Providers and 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 cbName;
DWORD dwType;
DWORD dwIndex;
CHAR *pszName = NULL;
// Print header lines for providers.
printf("Listing Available Providers:\n");
printf("Provider type\tProvider Name\n");
printf("_____________\t__________________"
"___________________\n");
//---------------------------------------------------------------
// Loop through enumerating providers.
dwIndex = 0;
while(CryptEnumProviders(
dwIndex,
NULL,
0,
&dwType,
NULL,
&cbName
))
{
//-----------------------------------------------------------
// cbName returns the length of the name of the next
// provider. 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 name.
if (CryptEnumProviders(
dwIndex++,
NULL,
0,
&dwType,
pszName,
&cbName
))
{
printf (" %4.0d\t%s\n",dwType, pszName);
}
else
{
printf("ERROR - CryptEnumProviders failed.\n");
exit(1);
}
LocalFree(pszName);
} // End of while loop
printf("\nProvider types and provider names "
"have been listed.\n");
}
Note
The wincrypt.h header defines CryptEnumProviders 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 |