Last active
February 7, 2019 08:20
-
-
Save prodeveloper0/a00602d8ed1a86385399d78616be0745 to your computer and use it in GitHub Desktop.
Get compiled time and date from current EXE program for Win32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <time.h> | |
| #include <Windows.h> | |
| #include <tchar.h> | |
| DWORD GetCompiltedTime() | |
| { | |
| TCHAR szFilename[MAX_PATH]; | |
| IMAGE_DOS_HEADER idh; | |
| IMAGE_NT_HEADERS inh; | |
| DWORD dwTimeStamp = 0; | |
| ZeroMemory(&idh, sizeof(idh)); | |
| ZeroMemory(&inh, sizeof(inh)); | |
| GetModuleFileName(NULL, szFilename, MAX_PATH); | |
| FILE* pf = _tfopen(szFilename, TEXT("rb")); | |
| if(pf == NULL) | |
| goto done; | |
| if(fread(&idh, sizeof(idh), 1, pf) != 1) | |
| goto done; | |
| fseek(pf, idh.e_lfanew, 0); | |
| if(fread(&inh, sizeof(inh), 1, pf) != 1) | |
| goto done; | |
| dwTimeStamp = inh.FileHeader.TimeDateStamp; | |
| done: | |
| if(pf != NULL) | |
| fclose(pf); | |
| return dwTimeStamp; | |
| } | |
| int main(int argc, char** argv) | |
| { | |
| DWORD dwCompiledTime = GetCompiltedTime(); | |
| time_t timeCompiledTime = (time_t)dwCompiledTime; | |
| tm tmCompiledTime; | |
| char strTimeStamp[128]; | |
| localtime_s(&tmCompiledTime, &timeCompiledTime); | |
| strftime(strTimeStamp, 128, "%Y/%m/%d %H:%M:%S", &tmCompiledTime); | |
| printf("Current program is compiled at %s\n", strTimeStamp); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment