VS get version information in the resource file

Source: Internet
Author: User

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-&GT;DWFILEVERSIONMS), (wchar_t*) Numbtxt,Ten); Version=Numbtxt; Version+ = _t ("."); //Minor_itow (LoWord (VERINFO-&GT;DWFILEVERSIONMS), (wchar_t*) Numbtxt,Ten); Version+=Numbtxt; Version+ = _t ("."); //Build_itow (HiWord (VERINFO-&GT;DWFILEVERSIONLS), (wchar_t*) Numbtxt,Ten); Version+=Numbtxt; Version+ = _t ("."); //Revision_itow (LoWord (VERINFO-&GT;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-&GT;DWFILEVERSIONMS), Numbtxt,Ten); Version=Numbtxt; Version+ = _t ("."); //Minor_itow (LoWord (VERINFO-&GT;DWFILEVERSIONMS), Numbtxt,Ten); Version+=Numbtxt; Version+ = _t ("."); //Build_itow (HiWord (VERINFO-&GT;DWFILEVERSIONLS), Numbtxt,Ten); Version+=Numbtxt; Version+ = _t ("."); //Revision_itow (LoWord (VERINFO-&GT;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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.