Output compile time stamp in Visual C++ executable?

前端 未结 6 951
借酒劲吻你
借酒劲吻你 2021-01-04 02:08

How can I insert compilation timestamp information into an executable I build with Visual C++ 2005? I want to be able to output something like this when I execute the progra

6条回答
  •  灰色年华
    2021-01-04 02:45

    Well... for Visual C++, there's a built in symbol called __ImageBase. Specifically:

    EXTERN_C IMAGE_DOS_HEADER __ImageBase;

    You can inspect that at runtime to determine the timestamp in the PE header:

    const IMAGE_NT_HEADERS *nt_header= (const IMAGE_NT_HEADERS *)((char *)&__ImageBase + __ImageBase.e_lfanew);

    And use nt_header->FileHeader.TimeDateStamp to get the timestamp, which is seconds from 1/1/1970.

提交回复
热议问题