CryptContextAddRef

The CryptContextAddRef function is used to add one to the reference count on a HCRYPTPROV handle.

#include <wincrypt.h>
BOOL WINAPI CryptContextAddRef(
  HCRYPTPROV hProv,      // in
  DWORD *pdwReserved,    // in
  DWORD dwFlags          // in
);
 

Parameters

hProv
HCRYPTPROV handle for which the reference count is being incremented.
pdwReserved
This parameter is reserved for future use and must be NULL.
dwFlags
Flag values. This parameter is reserved for future use and should always be zero.

Return Values

If the function succeeds, the return value is TRUE. If it fails, the return value is FALSE. To retrieve extended error information, use the GetLastError function.

The following table lists the error codes most commonly returned by the GetLastError function. The error codes prefaced by "NTE" are generated by the particular CSP you are using.

Error code Description
ERROR_INVALID_PARAMETER One of the parameters contains an invalid value. This is most often an illegal pointer.

Remarks

CryptContextAddRef is used to increase the reference count on a HCRYPTPROV handle so that multiple calls to CryptReleaseContext are required to actually release the handle.

Example

HCRYPTPROV    hProv = 0;

// Acquire a context handle
if (!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_SIG, 0)) {
   printf("Error %x during CryptAcquireContext!\n", GetLastError);
   return;
}

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

...

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

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

QuickInfo

  Windows NT: Requires version 5.0 or later.
  Windows: Unsupported.
  Windows CE: Unsupported.
  Header: Declared in wincrypt.h.
  Import Library: Use advapi32.lib.

See Also

CryptAcquireContext, CryptReleaseContext