在Windows Mobile和Wince(Windows Embedded CE)下开发的产品,有时候需要显示当前产品的版本信息。一般来说,版本信息是保存在资源文件里面的,例如下图:

为了保持一致,所有版本信息应该都从资源文件读取,不应该另外硬编码(Hard code)。

下面讲述读取资源文件版本信息的方法:

1.在资源文件中新建一个版本信息项

2.根据需求修改版本信息

3.增加取版本信息函数

要加入version。lib的链接库

CString GetProductVersion()
{
int nMaxPathName = ; // Max length of file name/path
char *pBuffer;
UINT nItemLength;
void* pData, *lpBuffer;
CString sVersion;
DWORD dwInfoSize, dwHandle;
VS_FIXEDFILEINFO *pFileInfo; // Get the file path and name
pBuffer = new char[nMaxPathName];
GetModuleFileName(NULL, pBuffer, nMaxPathName-); // Get File Version Info size
dwInfoSize = GetFileVersionInfoSize(pBuffer, &dwHandle);
if(dwInfoSize > )
{
pData = new char[dwInfoSize];
if(GetFileVersionInfo(pBuffer, dwHandle, dwInfoSize, pData))
if(VerQueryValue(pData, "\\", &lpBuffer, &nItemLength))
{
pFileInfo = (VS_FIXEDFILEINFO*)lpBuffer;
sVersion.Format("%d.%d.%d.%d",
pFileInfo->dwProductVersionMS >> ,
pFileInfo->dwProductVersionMS & 0xFFFF,
pFileInfo->dwProductVersionLS >> ,
pFileInfo->dwProductVersionLS & 0xFFFF);
// Calculate the product version as a number, you can delete the next statement if you don't need it.
DWORD dwProductVersion = (pFileInfo->dwProductVersionMS >> ) * +
(pFileInfo->dwProductVersionMS & 0xFFFF) * +
(pFileInfo->dwProductVersionLS >> ) * +
(pFileInfo->dwProductVersionLS & 0xFFFF) * ; }
// Delete the data buffer
delete [] pData;
}
// Get rid of the allocated string buffer
delete [] pBuffer;
return sVersion;
}

4.用法

/* 用法 */
CString sProductVersion = GetProductVersion();

完成了,效果如下图:

vs下取得资源文件中的版本信息的更多相关文章

  1. Direct2D开发:MFC下从资源文件中加载位图

    转载请注明出处:http://www.cnblogs.com/ye-ming 0X01 概述: 相对于GDI处理界面,Direct2D有得天独厚的优势,下图就是Direct2D与GDI的效果对比,wi ...

  2. java中根据key获取resource下properties资源文件中对应的参数

    properties资源文件是放在resource目录下的: 新建工具类: package com.demo.utils; import java.io.InputStream; import jav ...

  3. Windows Store App 全球化:引用分离资源文件中的资源

    大部分应用程序仅需要单个默认资源文件,例如Strings/zh-CN/Resources.resw,但是在某些应用程序中,最好将资源分离到多个资源文件中,以便更好地组织资源内容,这样就需要考虑如何引用 ...

  4. 文件_ _android从资源文件中读取文件流并显示的方法

    ======== 1   android从资源文件中读取文件流并显示的方法. 在android中,假如有的文本文件,比如TXT放在raw下,要直接读取出来,放到屏幕中显示,可以这样: private ...

  5. maven 编译部署src/main/java下的资源文件

    maven 编译部署src/main/java下的资源文件 maven默认会把src/main/resources下的所有配置文件以及src/main/java下的所有java文件打包或发布到targ ...

  6. 如何在Qt资源文件中包含和释放exe等各种类型文件?

    操作系统:Windows 10 X64 企业版 Qt: 5.8.0 QtCreater: 4.2.1 刚刚开始学习Qt,不断遇到困难和挑战,前几天在各个QQ群里询问如何在Qt的资源文件中包含和释放ex ...

  7. (转载)Android xml资源文件中@、@android:type、@*、?、@+引用写法含义以及区别

    原帖地址:http://blog.csdn.net/zfrong/article/details/7332545 Android xml资源文件中@.@android:type.@*.?.@+引用写法 ...

  8. 读取web应用下的资源文件(例如properties)

    package gz.itcast.b_resource; import java.io.IOException; import java.io.InputStream; import java.ut ...

  9. [转载] linux查找目录下的所有文件中是否含有某个字符串

    链接自 http://blog.sina.com.cn/s/blog_691a84f301015khx.html,并略加修订. 查找目录下的所有文件中是否含有某个字符串 find .|xargs gr ...

随机推荐

  1. [转]50 Tips for Working with Unity (Best Practices)

    About these tips These tips are not all applicable to every project. They are based on my experience ...

  2. [network]交换机中用户权限

    LEVEL 0(访问级):可以执行用于网络诊断等功能的命令.包括ping.tracert.telnet等命令,执行该级别命令的结果不能被保存到配置文件中. LEVEL 1(监控级):可以执行用于系统维 ...

  3. Elasticsearch.Net 异常:[match] query doesn't support multiple fields, found [field] and [query]

    用Elasticsearch.Net检索数据,报异常: )); ElasticLowLevelClient client = new ElasticLowLevelClient(settings); ...

  4. SVN部署与简单使用

    原文发表于cu:2016-05-24 参考文档: http://www.tuicool.com/articles/Yv2iyu7 http://www.centoscn.com/CentosServe ...

  5. openstack-r版(rocky)搭建基于centos7.4 的openstack swift对象存储服务 四

    openstack-r版(rocky)搭建基于centos7.4 的openstack swift对象存储服务 一 openstack-r版(rocky)搭建基于centos7.4 的openstac ...

  6. R-CNN学习总结

    R-CNN是一个比较早期的用于目标检测方法,但却十分经典,在此结合论文对这一方法做一个总结. (写给小白:通过下图简单理解图像分类,图像定位,目标检测和实例分割) R-CNN方法提出的背景: 1.近1 ...

  7. Paper Reading - Deep Captioning with Multimodal Recurrent Neural Networks ( m-RNN ) ( ICLR 2015 ) ★

    Link of the Paper: https://arxiv.org/pdf/1412.6632.pdf Main Points: The authors propose a multimodal ...

  8. [linux] centos搭建openvpn服务,脚本颁发/吊销证书 (转载+原创)

    搭建过程转载:http://yestreenstars.blog.51cto.com/1836303/1429537 环境说明:服务端:CentOS 6.5_X64客户端:Windows 7 服务端配 ...

  9. Js 问题分析--js 影响页面性能

    文档下载链接:http://pan.baidu.com/s/1i4Hci4d (失效请留言)

  10. Alpha阶段中间产物——GUI Prototype、WBS及PSP

    作业地址:https://edu.cnblogs.com/campus/nenu/SWE2017FALL/homework/1224 内容: GUI Prototype 我的书架 我的书架→添加图书 ...