Share via


CryptReleaseContext

This function releases the handle to a cryptographic service provider (CSP) and the key container. At each call to this function, the reference count on the CSP is reduced by one. When the reference count reaches zero, the context is fully released and it can no longer be used by any function in the application.

The application calls this function when it is finished using the CSP. After this function is called, the CSP handle specified by the hProv parameter is no longer valid; however, the function does not destroy either the key container or any key pairs.

BOOL WINAPI CryptReleaseContext( HCRYPTPROVhProv,DWORDdwFlags); 

Parameters

  • hProv
    [in] HCRYPTPROV handle to a CSP created by a call to the CryptAcquireContext function.
  • dwFlags
    [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. The following table shows common values for the GetLastError function. The error values prefaced by NTE are generated by the particular CSP you are using.

Value Description
ERROR_BUSY The CSP context specified by hProv is currently being used by another process.
ERROR_INVALID_HANDLE One of the parameters specifies an invalid handle.
ERROR_INVALID_PARAMETER One of the parameters contains an invalid value. This is most often an illegal pointer.
NTE_BAD_FLAGS The dwFlags parameter is nonzero.
NTE_BAD_UID The hProv parameter does not contain a valid context handle.

Remarks

After calling this function, the session is over and all existing session keys and hash objects that were created by using the hProv handle become invalid. In practice, all of these objects should be destroyed with the CryptDestroyKey and CryptDestroyHash functions before calling the CryptReleaseContext function.

Example Code

See CryptHashSessionKey.

Requirements

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

See Also

CryptAcquireContext | CryptDestroyKey | CryptDestroyHash

 Last updated on Thursday, April 08, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.