IDebugDocumentChecksum2::GetChecksumAndAlgorithmId
根据要使用的最大字节数检索文档检查和算法标识符。
语法
public int GetChecksumAndAlgorithmId(
out Guid pRetVal,
uint cMaxBytes,
out byte pChecksum,
out uint pcNumBytes
);
参数
pRetVal
[out]检查和算法的唯一标识符。
cMaxBytes
[in]要用于 检查um 的最大字节数。
pChecksum
[out]检查和的值。
pcNumBytes
[out]用于检查和的实际字节数。
返回值
如果成功,则返回 S_OK
;否则,返回错误代码。
示例
以下示例使用此方法获取文档的检查和算法。
HRESULT CDebugCodeContext::GetDocumentChecksumAndAlgorithmId(GUID *pguidAlgorithm, BYTE **ppChecksum, ULONG *pcNumBytes)
{
HRESULT hRes = E_FAIL;
*ppChecksum = NULL;
*pcNumBytes = 0;
CComPtr<IDebugDocumentContext2> pDocContext;
hRes = this->GetDocumentContext(&pDocContext);
if ( HREVAL(S_OK, hRes) )
{
CComQIPtr<IDebugDocumentChecksum2> pDocChecksum(pDocContext);
if ( pDocChecksum != NULL )
{
// Figure out the size of the checksum buffer required
ULONG cNumBytes = 0;
hRes = pDocChecksum->GetChecksumAndAlgorithmId(pguidAlgorithm, 0, NULL, &cNumBytes);
if ( S_OK == hRes )
{
// check to see if we got back valid values
if ( cNumBytes && GUID_NULL != (*pguidAlgorithm) )
{
// Alloc space for the checksum data
BYTE *pChecksum = (BYTE*) CoTaskMemAlloc(cNumBytes);
if ( pChecksum )
{
// Get the buffer containing the checksum info
hRes = pDocChecksum->GetChecksumAndAlgorithmId(pguidAlgorithm, cNumBytes, pChecksum, &cNumBytes);
if ( HREVAL(S_OK, hRes) )
{
*ppChecksum = pChecksum;
*pcNumBytes = cNumBytes;
}
else
{
CoTaskMemFree(pChecksum);
}
}
else
hRes = E_OUTOFMEMORY;
}
else
hRes = S_FALSE; // lang doesn't support checksums
}
else
hRes = S_FALSE; // failed to work out checksum info
}
else
hRes = S_FALSE; // SH doesn't support checksums
}
return ( hRes );
}