从资源文件中获取版本信息

来源:互联网 发布:如何投诉淘宝店家 编辑:程序博客网 时间:2024/05/16 13:43

/*********************************************************************************
 * author: hjjdebug
 * date: 2011
 * description:
 * version info 储存在资源文件中,需要用api 来获得信息。
 * 这是一个实例, GetFileVersionInfo, VerQueryValue 的用法
 *********************************************************************************/
#include "stdafx.h"
#include <windows.h>
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    if(argc==1)
    {
        cout << "Usage: " <<argv[0] << " filename" << endl;
        system("pause");
        return -1;
    }
    DWORD size=GetFileVersionInfoSize(argv[1],NULL);
    char *buffer = new char[size+1]; // 分配足够大内存储存信息
    if(!GetFileVersionInfo(argv[1],NULL,size,buffer))
    {
        delete[] buffer;
        cout << "can't get version info!"<<endl;
        system("pause");
        return -1;
    }
    VS_FIXEDFILEINFO *FixDataInfo;
    UINT len;
    if(VerQueryValue(buffer,"//",(LPVOID *)&FixDataInfo,&len))
    {
        cout <<"Major version:"<<hex<<FixDataInfo->dwFileVersionMS<<endl;
        cout <<"Minor version:"<<hex<<FixDataInfo->dwFileVersionLS<<endl;
        cout << "ok" << endl;
    }
    delete[] buffer;
    system("pause");
    return 0;
}