CryptGetDefaultProviderA function (wincrypt.h)
Syntax
BOOL CryptGetDefaultProviderA(
[in] DWORD dwProvType,
[in] DWORD *pdwReserved,
[in] DWORD dwFlags,
[out] LPSTR pszProvName,
[in, out] DWORD *pcbProvName
);
Parameters
[in] dwProvType
The provider type for which the default CSP name is to be found.
Defined provider types are as follows:
- PROV_RSA_FULL
- PROV_RSA_SIG
- PROV_DSS
- PROV_DSS_DH
- PROV_DH_SCHANNEL
- PROV_FORTEZZA
- PROV_MS_EXCHANGE
- PROV_RSA_SCHANNEL
- PROV_SSL
[in] pdwReserved
This parameter is reserved for future use and must be NULL.
[in] dwFlags
The following flag values are defined.
Value | Meaning |
---|---|
|
Returns the user-context default CSP of the specified type. |
|
Returns the computer default CSP of the specified type. |
[out] pszProvName
A pointer to a null-terminated character string buffer to receive the name of the default CSP.
To find the size of the buffer for memory allocation purposes, this parameter can be NULL. For more information, see Retrieving Data of Unknown Length.
[in, out] pcbProvName
A pointer to a DWORD value that specifies 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 or to be 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 code prefaced by NTE is generated by the particular CSP being used. Possible error codes include the following.
Return code | Description |
---|---|
|
One of the parameters contains a value that is not valid. This is most often a pointer that is not valid. |
|
The buffer for the name is not large enough. |
|
The operating system ran out of memory. |
|
The dwFlags parameter has an unrecognized value. |
Remarks
This function determines which installed CSP is currently set as the default for the local computer or current user. This information is often displayed to the user.
Examples
The following example retrieves the name of the default CSP for the PROV_RSA_FULL provider type. For another example that uses this function, see Example C Program: Enumerating CSP Providers and Provider Types.
#include <stdio.h>
#include <windows.h>
#include <Wincrypt.h>
#pragma comment(lib, "crypt32.lib")
void main()
{
DWORD cbProvName=0;
LPTSTR pbProvName=NULL;
// Copyright (C) Microsoft. All rights reserved.
// Get the length of the RSA_FULL default provider name.
if (!(CryptGetDefaultProvider(
PROV_RSA_FULL,
NULL,
CRYPT_MACHINE_DEFAULT,
NULL,
&cbProvName)))
{
printf("Error getting the length of the default "
"provider name.\n");
exit(1);
}
// Allocate local memory for the name of the default provider.
if (!(pbProvName = (LPTSTR)LocalAlloc(LMEM_ZEROINIT,
cbProvName)))
{
printf("Error during memory allocation for "
"provider name.\n");
exit(1);
}
// Get the default provider name.
if (CryptGetDefaultProvider(
PROV_RSA_FULL,
NULL,
CRYPT_MACHINE_DEFAULT,
pbProvName,
&cbProvName))
{
printf("The default provider name is %s\n",pbProvName);
}
else
{
printf("Getting the name of the provider failed.\n");
exit(1);
}
// Free resources when done.
LocalFree(pbProvName);
}
Note
The wincrypt.h header defines CryptGetDefaultProvider as an alias which 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 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 |