[This is preliminary documentation and subject to change.]
The CryptMsgDuplicate function duplicates a cryptographic message handle by incrementing the reference count. The reference count keeps track of the lifetime of the message.
#include <wincrypt.h>
HCRYPTMSG WINAPI CryptMsgDuplicate(
HCRYPTMSG hCryptMsg // in
);
A copy is not made of the message, and the returned handle is the same as the handle that was input.
CryptMsgDuplicate is used to increase the reference count on a HCRYPTMSG handle so that multiple calls to CryptMsgClose are required to actually release the handle.
// EXAMPLE CODE FOR USING CryptMsgDuplicate().
// Duplicates a message handle by incrementing its reference count.
// Assume that the application has a handle (hCryptMsg)
// to the message that is to be duplicated.
// Set up the variables.
HCRYPTMSG hCryptMsg; // Message handle
HCRYPTMSG hResult; // Duplicated message handle
// Function call to CryptMsgDuplicate to duplicate the handle.
hResult = CryptMsgDuplicate(
hCryptMsg); // in- Initialized elsewhere
if (hResult){ // returned value is the handle
cout<< "CryptMsgDuplicate is successful"<< endl
<< "original handle (hCryptMsg) = "<< hCryptMsg<< endl
<< "Duplicate handle (hResult) = "<< hResult<< endl
<< "Note that they are identical"<< endl
<< "The handle reference count has been incremented"<< endl
<< endl;
// Free memory. Multiple calls to CryptMsgClose are required to
// decrement the reference count and actually release the handle.
CryptMsgClose(hResult);
CryptMsgClose(hCryptMsg);
}
else{ // returned value is NULL
cout<< "CryptMsgDuplicate is not successful"<< endl<< endl;
}
Windows NT: Requires version 4.0 SP3 or later (or version 4.0 with IE 3.02 or later).
Windows: Requires Windows 98 or later.
Windows CE: Unsupported.
Header: Declared in wincrypt.h.
Import Library: Use crypt32.lib.