We write software, always want to change the program can automatically generate version number, do not manually to change, so much convenient ah. The VS compiler can implement this functionality. As shown below:
/* Get program compile time to generate version number automatically __date__ "2013" "Mar 1 2013" __time__ "21:42:20" * * void Getprogramcompiletime (
SYSTEMTIME &st) {TCHAR szdate[20];
ZeroMemory (szdate, sizeof (szdate));
ZeroMemory (&st, sizeof (SYSTEMTIME));
_stprintf (Szdate, TEXT ("%s"), __date__);
St.wyear = _tcstoul (szdate+7, 0, 10);
St.wday = szdate[5]-TEXT (' 0 ');
if (Szdate[4]!= text (")" {st.wday + = (szdate[4]-text (' 0 ')) * 10;
Switch (szdate[0]) {case TEXT (' A '): if (szdate[1] = = TEXT (' P ')) {st.wmonth = 4;
else {st.wmonth = 8;
} break;
Case TEXT (' D '): St.wmonth = 12;
Break
Case TEXT (' F '): St.wmonth = 2;
Break
Case TEXT (' J '): if (szdate[1] = = TEXT (' a ')) {st.wmonth = 1;
else {if (szdate[2] = = TEXT (' n ')) {st.wmonth = 6;
else {st.wmonth = 7;
}} break;
Case TEXT (' M '): if (szdate[2] = = TEXT (' r ')) {st.wmonth = 3;
} else{st.wmonth = 5;
} break;
Case TEXT (' N '): St.wmonth = 11;
Break
Case TEXT (' O '): St.wmonth = 10;
Break
Case TEXT (' S '): St.wmonth = 9;
Break
} zeromemory (szdate, sizeof (szdate));
sprintf (Szdate, TEXT ("%s"), __time__);
St.whour = (szdate[0]-text (' 0 ')) * + (Szdate[1]-TEXT (' 0 '));
St.wminute = (szdate[3]-text (' 0 ')) * + (Szdate[4]-TEXT (' 0 '));
St.wsecond = (Szdate[6]-text (' 0 ')) * + (Szdate[7]-TEXT (' 0 '));
Return }
Getprogramcompiletime This function to get the compile time out and save it in a SYSTEMTIME structure so that it can be used casually.