CryptCATAdminCalcHashFromFileHandle2 function

The CryptCATAdminCalcHashFromFileHandle2 function calculates the hash for a file by using the specified algorithm.

This function has no associated import library. You must use the LoadLibrary and GetProcAddress functions to dynamically link to Wintrust.dll.


BOOL WINAPI CryptCATAdminCalcHashFromFileHandle2(
  _In_       HCATADMIN                                        hCatAdmin,
  _In_       HANDLE                                           hFile,
  _Inout_    DWORD                                            *pcbHash,
             _Out_writes_bytes_to_opt_(*pcbHash,*pcbHash)BYTE *pbHash,
  _Reserved_ DWORD                                            dwFlags


hCatAdmin [in]

Handle of an open catalog administrator context. For more information, see CryptCATAdminAcquireContext2.

hFile [in]

A handle to the file whose hash is being calculated. This parameter cannot be NULL and must be a valid file handle.

pcbHash [in, out]

Pointer to a DWORD variable that contains the number of bytes in the pbHash parameter. Upon input, set pcbHash to the number of bytes allocated for pbHash. Upon return, pcbHash contains the number of returned bytes in pbHash. If pbHash is set to NULL, then pcbHash contains the number of bytes to allocate for pbHash.


Pointer to a BYTE buffer that receives the hash. If you set this parameter to NULL, then pcbHash will contain the number of bytes to allocate for pbHash, and a subsequent call can be made to retrieve the hash.


Reserved. This value must be zero.

Return value

If the function succeeds, the return value is nonzero (TRUE).

If the function fails, the return value is zero (FALSE). For extended error information, call GetLastError.

The following table lists the error codes most commonly returned by the GetLastError function.

Return codeDescription

The hFile parameter must not be NULL.

The hFile parameter must be a valid file handle.

The pcbHash parameter must not be NULL.

The dwFlags parameter must be zero (0).


The buffer pointed to by the pbHash parameter was not NULL but was not large enough to be written. The correct size of the required buffer is contained in the value pointed to by the pcbHash parameter.


The hash algorithm specified by the pwszHashAlgorithm parameter cannot be found.



The amount of time this function takes to execute depends on the length of the file being hashed, the algorithm being used, and the file location. For example, it takes several seconds to calculate the hash of a local file that is very large (a few hundred megabytes).


Minimum supported client

Windows 8 [desktop apps only]

Minimum supported server

Windows Server 2012 [desktop apps only]







See also