Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

CryptContextAddRef (Windows CE 5.0)

Windows CE 5.0
Send Feedback

This function adds one to the reference count of an HCRYPTPROV handle.

BOOL WINAPI CryptContextAddRef( 
  DWORD* pdwReserved, 
  DWORD dwFlags


[in] HCRYPTPROV handle to a cryptographic service provider (CSP) created by a call to the CryptAcquireContext function for which the reference count is being incremented.
[in] Reserved for future use and must be set to NULL.
[in] Reserved for future use and must be set to zero.

Return Values

TRUE indicates success. FALSE indicates failure. To get extended error information, call the GetLastError function.

A common value for GetLastError is ERROR_INVALID_PARAMETER. It means that one of the parameters contain an invalid value, which is often an illegal pointer.


This function should be used if the CSP handle is included as a member of any structure passed to another function. The CryptReleaseContext function should be called when the CSP handle is no longer needed.

This function increases the reference count of a HCRYPTPROV handle; therefore, multiple calls to the CryptReleaseContext function are required to actually free the handle.

Example Code


// Acquire a context handle using CryptAcquireContext
// For sample code, see CryptAcquireContext.

if (!CryptContextAddRef(&hProv, NULL, 0)) {
 printf("Error %x during CryptContextAddRef!\n", GetLastError);


// The first call to CryptReleaseContext will not free the provider 
// handle because the reference count has been bumped up.
if (!CryptReleaseContext(hProv, 0)) {
 printf("Error %x during CryptReleaseContext!\n", GetLastError);

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


OS Versions: Windows CE 2.10 and later.
Header: Wincrypt.h.
Link Library: Coredll.lib.

See Also

CryptAcquireContext | CryptReleaseContext | HCRYPTPROV

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.