This function is used to add one to the reference count on an HCRYPTPROV handle.
At a Glance
Header file: | Wincrypt.h |
Windows CE versions: | 2.10 and later |
Syntax
BOOL WINAPI CryptContextAddRef( HCRYPTPROV hProv,
DWORD *pdwReserved, DWORD dFlags );
Parameters
hProv
[in] HCRYPTPROV handle for which the reference count is being incremented.
pdwReserved
[in] Reserved for future use; set to NULL.
dwFlags
[in] Specifies a bitmask of flags. This parameter is reserved for future use; set to 0.
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.
Value | 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;
}
See Also