IDebugDocumentChecksum2::GetChecksumAndAlgorithmId
Pobiera sumę kontrolną dokumentu i identyfikator algorytmu, biorąc pod uwagę maksymalną liczbę bajtów do użycia.
Składnia
public int GetChecksumAndAlgorithmId(
out Guid pRetVal,
uint cMaxBytes,
out byte pChecksum,
out uint pcNumBytes
);
Parametry
pRetVal
[out] Unikatowy identyfikator algorytmu sumy kontrolnej.
cMaxBytes
[in] Maksymalna liczba bajtów do użycia dla sumy kontrolnej.
pChecksum
[out] Wartość sumy kontrolnej.
pcNumBytes
[out] Rzeczywista liczba bajtów używanych dla sumy kontrolnej.
Wartość zwracana
Jeśli operacja powiedzie się, zwraca wartość S_OK
; w przeciwnym razie zwraca kod błędu.
Przykład
W poniższym przykładzie użyto tej metody do pobrania sumy kontrolnej i algorytmu dla dokumentu.
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 );
}