Visual C++ linker timestamp

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

</pre>
EXTERN_C IMAGE_DOS_HEADER __ImageBase;

(...)

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

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

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

One 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.

    Like

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s