Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This function adds one to the reference count of an HCRYPTPROVhandle.

Syntax

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

Parameters

hProv

[in] HCRYPTPROVhandle to a cryptographic service provider (CSP) created by a call to the CryptAcquireContextfunction for which the reference count is being incremented.

pdwReserved

[in] Reserved for future use and must be set to NULL.

dwFlags

[in] Reserved for future use and must be set to zero.

Return Value

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

A common value for GetLastErroris 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 CryptReleaseContextfunction should be called when the CSP handle is no longer needed.

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

Example Code

Copy Code
HCRYPTPROV hProv = 0;
// Acquire a context handle using CryptAcquireContext
// For sample code, see <A
HREF="wce50lrfcryptacquirecontext.htm">CryptAcquireContext</A>.
...
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
Windows Embedded CE Windows CE 2.10 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also