Visual C++ linker timestamp

Nice trick to get build’s timestamp at runtime (Visual C++ only):



IMAGE_NT_HEADERS const* ntHeader
= (IMAGE_NT_HEADERS*) ( (char*) &__ImageBase + __ImageBase.e_lfanew );
DWORD const timeStamp = ntHeader->FileHeader.TimeDateStamp;

It’s not very portable, but it doesn’t require any additional recompilation (as __DATE__ __TIME__ macros do).

This entry was posted in C++. Bookmark the permalink.

1 Response to Visual C++ linker timestamp

  1. ktornai says:

    The first HINSTANCE parameter from WinMain points to this IMAGE_DOS_HEADER, so no need to the global extern image dos header.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s