CryptContextAddRef (Compact 2013)

3/28/2014

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

Syntax

BOOL WINAPI CryptContextAddRef( 
  HCRYPTPROV hProv,
  DWORD* pdwReserved, 
  DWORD dwFlags
);

Parameters

  • hProv
    [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.
  • pdwReserved
    [in] Reserved; set to NULL.
  • dwFlags
    [in] Reserved; set to 0 (zero).

Return Value

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.

Remarks

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

Important

For readability, the following code example does not contain security checking or error handling. Do not use the following code in a production environment.

HCRYPTPROV hProv = 0;
// Acquire a context handle using CryptAcquireContext.
// For sample code, see the CryptAcquireContext topic.
...
if (!CryptContextAddRef(&hProv, NULL, 0)) {
 printf("Error %x during CryptContextAddRef!\n", GetLastError);
 return;
}
...
// 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);
 return;
}
// Free the provider handle.
if (!CryptReleaseContext(hProv, 0)) {
 printf("Error %x during CryptReleaseContext!\n", GetLastError);
 return;
}

Requirements

Header

wincrypt.h

Library

coredll.lib

See Also

Reference

Cryptography Functions
CryptAcquireContext
CryptReleaseContext
HCRYPTPROV