ArticleDirectory
- 1. Create a new version information item in the resource file.
- 2. Modify version information as needed
- 3. added the version fetch function.
- 4. Retrieve version information
Products developed under Windows Mobile and Windows WinCE (Windows Embedded CE) sometimes need to display the version information of the current product. Generally, the version information is stored in the resource file, for example:
To ensure consistency, all version information should be read from the resource file and not hard code ).
The following describes how to read the version information of a resource file:
1. Create a new version information item in the resource file.
2. Modify version information as needed
3. added the version fetch function.
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, 10 );
Version = numbtxt;
Version + = _ T ( "." );
// Minor
_ Itow (loword (verinfo-> dwfileversionms), numbtxt, 10 );
Version + = numbtxt;
Version + = _ T ( "." );
// Build
_ Itow (hiword (verinfo-> dwfileversionls), numbtxt, 10 );
Version + = numbtxt;
Version + = _ T ( "." );
// Revision
_ Itow (loword (verinfo-> dwfileversionls), numbtxt, 10 );
Version + = numbtxt;
}
}
Free (verdata );
}
}
}
Return Version;
}
4. Retrieve version information
Hinstance hinst = (hinstance) hmodule;
Getversioninfo (hinst );
Finished. The effect is as follows:
I have been developing wtl recently and have written many summary about this. Please refer to my blog.