Reproduced in: http://www.cnblogs.com/procoder/archive/2009/11/13/windows-mobile-wtl-version.html
Products developed under Windows Mobile and WinCE (Windows Embedded CE) sometimes need to display version information for the current product. In general, the version information is stored in the resource file, for example:
In order to remain consistent, all version information should be read from the resource file and should not be hardcoded (hard code) otherwise.
Here's how to read the resource file version information:
1. Create a new version information item in the resource file
2. Modify version information as required
3. Add version information function
Here is the version that I compiled under VS2003.
Although the compile-time passed, but the connection will still appear wrong, the following is the workaround:
Add Version.lib in the project properties--Configuration Properties--linker--Input, additional dependencies.
CString getversioninfo (hmodule hlib) {CString version; TCHAR Appfilepath[max_path]; memset (Appfilepath,0,sizeof(Char) *MAX_PATH); if(GetModuleFileName (Hlib, Appfilepath, MAX_PATH)) {DWORD hand=0; DWORD Verlen= GetFileVersionInfoSize (appfilepath,&hand); if(0<Verlen) {TCHAR*verdata = (TCHAR *)malloc(Verlen); if(verdata) {if(Getfileversioninfow ((LPCWSTR) appfilepath,hand,verlen,verdata)) {Vs_fixedfileinfo *Verinfo; unsigned buflen; if(Verqueryvaluew (Verdata, (LPWSTR) _t ("\\"), (LPVOID *) &verinfo, (Puint) &Buflen)) {TCHAR numbtxt[8]; memset (Numbtxt,0,8); //Major_itow (HiWord (VERINFO->DWFILEVERSIONMS), (wchar_t*) Numbtxt,Ten); Version=Numbtxt; Version+ = _t ("."); //Minor_itow (LoWord (VERINFO->DWFILEVERSIONMS), (wchar_t*) Numbtxt,Ten); Version+=Numbtxt; Version+ = _t ("."); //Build_itow (HiWord (VERINFO->DWFILEVERSIONLS), (wchar_t*) Numbtxt,Ten); Version+=Numbtxt; Version+ = _t ("."); //Revision_itow (LoWord (VERINFO->DWFILEVERSIONLS), (wchar_t*) Numbtxt,Ten); Version+=Numbtxt; } } Free(Verdata); } } } returnversion;}
This is the original of the author.
CString cconfigdialog::getversioninfo (hmodule hlib) {CString version; TCHAR Appfilepath[max_path]; memset (Appfilepath,0,sizeof(Char) *MAX_PATH); if(GetModuleFileName (Hlib, Appfilepath, MAX_PATH)) {DWORD hand=0; DWORD Verlen= GetFileVersionInfoSize (appfilepath,&hand); if(0<Verlen) {TCHAR*verdata = (TCHAR *)malloc(Verlen); if(verdata) {if(Getfileversioninfow (appfilepath,hand,verlen,verdata)) {Vs_fixedfileinfo*Verinfo; unsigned buflen; if(Verqueryvaluew (verdata,_t ("\\"), (LPVOID *) &verinfo, (Puint) &Buflen)) {TCHAR numbtxt[8]; memset (Numbtxt,0,8); //Major_itow (HiWord (VERINFO->DWFILEVERSIONMS), Numbtxt,Ten); Version=Numbtxt; Version+ = _t ("."); //Minor_itow (LoWord (VERINFO->DWFILEVERSIONMS), Numbtxt,Ten); Version+=Numbtxt; Version+ = _t ("."); //Build_itow (HiWord (VERINFO->DWFILEVERSIONLS), Numbtxt,Ten); Version+=Numbtxt; Version+ = _t ("."); //Revision_itow (LoWord (VERINFO->DWFILEVERSIONLS), Numbtxt,Ten); Version+=Numbtxt; } } Free(Verdata); } } } returnversion;}
4. Remove the version information
HInstance HInst = (hinstance) hmodule; GetVersionInfo (hInst);
Finished, the effect is as follows:
VS get version information in the resource file