Export (0) Print
Expand All

MapFileAndCheckSum function

Computes the checksum of the specified file.

Syntax


DWORD MapFileAndCheckSum(
  _In_   PTSTR Filename,
  _Out_  PDWORD HeaderSum,
  _Out_  PDWORD CheckSum
);

Parameters

Filename [in]

The file name of the file for which the checksum is to be computed.

HeaderSum [out]

A pointer to a variable that receives the original checksum from the image file, or zero if there is an error.

CheckSum [out]

A pointer to a variable that receives the computed checksum.

Return value

If the function succeeds, the return value is CHECKSUM_SUCCESS (0).

If the function fails, the return value is one of the following.

Return code/valueDescription
CHECKSUM_MAP_FAILURE
2

Could not map the file.

CHECKSUM_MAPVIEW_FAILURE
3

Could not map a view of the file.

CHECKSUM_OPEN_FAILURE
1

Could not open the file.

CHECKSUM_UNICODE_FAILURE
4

Could not convert the file name to Unicode.

 

Remarks

The MapFileAndCheckSum function computes a new checksum for the file and returns it in the CheckSum parameter. This function is used by any application that creates or modifies an executable image. Checksums are required for kernel-mode drivers and some system DLLs. The linker computes the original checksum at link time, if you use the appropriate linker switch. For more details, see your linker documentation.

It is recommended that all images have valid checksums. It is the caller's responsibility to place the newly computed checksum into the mapped image and update the on-disk image of the file.

Passing a Filename parameter that does not point to a valid executable image will produce unpredictable results. Any user of this function is encouraged to make sure that a valid executable image is being passed.

All ImageHlp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more than one thread to this function.

Note  The Unicode implementation of this function calls the ASCII implementation and as a result, the function can fail if the codepage does not support the characters in the path. For example, if you pass a non-English Unicode file path, and the default codepage is English, the unrecognized non-English wide chars are converted to "??" and the file cannot be opened (the function returns CHECKSUM_OPEN_FAILURE).

Requirements

Minimum supported client

Windows XP [desktop apps only]

Minimum supported server

Windows Server 2003 [desktop apps only]

Header

Imagehlp.h

Library

Imagehlp.lib

DLL

Imagehlp.dll

Unicode and ANSI names

MapFileAndCheckSumW (Unicode) and MapFileAndCheckSumA (ANSI)

See also

ImageHlp Functions
CheckSumMappedFile

 

 

Community Additions

ADD
Show:
© 2014 Microsoft