Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
922 B

  1. //=======================================================================
  2. //
  3. // Copyright (c) 1999 Microsoft Corporation. All Rights Reserved.
  4. //
  5. // File: filecrc.h
  6. //
  7. // Purpose: Calculating and using CRC for files
  8. //
  9. //=======================================================================
  10. #include <windows.h>
  11. #include <objbase.h>
  12. #include <filecrc.h>
  13. #include <wincrypt.h>
  14. #include <mscat.h>
  15. HRESULT CalculateFileCRC(LPCTSTR pszFN, WUCRC_HASH* pCRC)
  16. {
  17. HANDLE hFile;
  18. HRESULT hr = S_OK;
  19. DWORD cbHash = WUCRC_HASH_SIZE;
  20. hFile = CreateFile(pszFN, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  21. if (hFile != INVALID_HANDLE_VALUE)
  22. {
  23. if (!CryptCATAdminCalcHashFromFileHandle(hFile, &cbHash, pCRC->HashBytes, 0))
  24. {
  25. hr = HRESULT_FROM_WIN32(GetLastError());
  26. }
  27. CloseHandle(hFile);
  28. }
  29. else
  30. {
  31. hr = HRESULT_FROM_WIN32(GetLastError());
  32. }
  33. return hr;
  34. }