Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All


Windows CE 3.0

This function is used to specify the current user default cryptographic service provider (CSP). Typical applications do not use this function. It is intended for use solely by administrative applications.

After this function has been called, any calls this user subsequently makes to CryptAcquireContext specifying the dwProvType provider type but not a provider name result in the pszProvName provider being used.

BOOL CRYPTFUNC CryptSetProvider( 
LPCTSTR pszProvName,
DWORD dwProvType);


[in] Pointer to the null-terminated string that contains the name of the new default CSP. This CSP should have already been installed on the computer.
[in] Specifies the provider type of the CSP defined in the pszProvName parameter.

Return Values

TRUE indicates success. FALSE indicates failure. To get extended error information, call GetLastError. Common values for GetLastError are described in the following table. The error values prefaced by "NTE" are generated by the particular CSP you are using.

Value Description
ERROR_INVALID_HANDLE One of the parameters specifies an invalid handle.
ERROR_INVALID_PARAMETER One of the parameters contains an invalid value. This is most often an illegal pointer.
ERROR_NOT_ENOUGH_MEMORY The operating system ran out of memory during the operation.
Error values returned from the RegCreateKeyEx function. See RegCreateKeyEx.
Error values returned from the RegSetValueEx function. See RegSetValueEx.


Typical applications do not usually specify a CSP name when calling the CryptAcquireContext function. This gives the users a certain amount of freedom in that they can select a CSP that has an appropriate level of security.

This means that a call to CryptSetProvider will often determine the CSP of a given type used by all applications that run from that point on. With this being the case, the CryptSetProvider function should never be called without the user's consent.

Windows CE does not support the ANSI version of this function.



// Specify the default PROV_RSA_SIG provider. Note that this assumes
// that a CSP with a type of PROV_RSA_SIG and named "Joe's Provider"
// has already been installed.
if(!CryptSetProvider(TEXT("Joe's Provider"), PROV_RSA_SIG)) {
 printf("Error %x during CryptSetProvider!\n", GetLastError());

// Get a handle to the provider that you just made the default.
if(!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_SIG, 0)) {
 printf("Error %x during CryptAcquireContext!\n", GetLastError());


// Release the provider handle.
if(!CryptReleaseContext(hProv, 0)) {
 printf("Error %x during CryptReleaseContext!\n", GetLastError());


Runs On Versions Defined in Include Link to
Windows CE OS 2.10 and later Wincrypt.h   Cryptapi.lib
Note   This API is part of the complete Windows CE OS package as provided by Microsoft. The functionality of a particular platform is determined by the original equipment manufacturer (OEM) and some devices may not support this API.

See Also


 Last updated on Tuesday, July 13, 2004

© 1992-2000 Microsoft Corporation. All rights reserved.

© 2015 Microsoft