当前位置:首页 > 编程学习 > C++获取文件版本等信息

C++获取文件版本等信息

编程学习2022-07-1062720

C++获取文件版本等信息.jpg C++获取文件版本等信息  编程 技术 C++ 第1张



#include "stdio.h"
#include <iostream>
#include <string>
#include <tchar.h>
#include <windows.h>

#pragma comment(lib, "version.lib")
using namespace std;
std::string GetFileVersion(char *strFilePath)
{
    DWORD dwSize;
    DWORD dwRtn;
    std::string szVersion;
    //获取版本信息大小
    dwSize = GetFileVersionInfoSize(strFilePath, NULL);
    if (dwSize == 0)
    {
        return "读取文件失败!";
    }
    char *pBuf;
    pBuf = new char[dwSize + 1];
    if (pBuf == NULL)
        return "";
    memset(pBuf, 0, dwSize + 1);
    //获取版本信息
    dwRtn = GetFileVersionInfo(strFilePath, NULL, dwSize, pBuf);
    if (dwRtn == 0)
    {
        return "";
    }
    LPVOID lpBuffer = NULL;
    UINT uLen = 0;
    //版本资源中获取信息

    dwRtn = VerQueryValue(pBuf,
                          TEXT("\\StringFileInfo\\080404b0\\FileDescription"), // 0804中文
                          // 04b0即1252,ANSI
                          //可以从ResourceView中的Version中BlockHeader中看到
                          //可以测试的属性
                          /*
                          CompanyName
                          FileDescription
                          FileVersion
                          InternalName
                          LegalCopyright
                          OriginalFilename
                          ProductName
                          ProductVersion
                          Comments
                          LegalTrademarks
                          PrivateBuild
                          SpecialBuild
                          */
                          &lpBuffer,
                          &uLen);
    if (dwRtn == 0)
    {
        return "";
    }
    szVersion = (char *)lpBuffer;
    delete pBuf;
    return szVersion;
}

void main()
{
    char *strFilePath = "C:\\Program Files (x86)\\Tencent\\QQ\\Bin\\QQ.exe";
    cout << strFilePath << " FileDescription is: " << GetFileVersion(strFilePath) << endl;
    getchar();
}


扫描二维码推送至手机访问。

版权声明:本文由海阔天空发布,如需转载请注明出处。

本文链接:https://apull.net/html/20220710164438.html

标签: 编程技术C++
分享给朋友:

相关文章

MD5加密VB版

MD5加密VB版

'MD5加密VB版 '调用方法:str=MD5("Apull",32),就能得到"Apull"的32位的MD5。 Private m_lOnBits(30) Private m_l2Power(30) Private Const BITS_TO_A_BYTE = 8 Private Const BYTES_TO_A_WORD = 4 Private Const BITS_TO_A_WORD = 32 Private Fu...

常用asp函数

常用asp函数

<% '------------------------------------- '所有功能函数名如下: ' StrLength(str) 取得字符串长度 ' CutStr(str,strlen) 字符串长度切割 ' CheckIsEmpty(tstr) 检测是否为空 ' isInteger(para) 整数检验 ' CheckName(str) 名字字符校验 ' CheckPassword(str) 密码检验 ' CheckEmail(emai...

计算机蓝屏代码的含义

计算机蓝屏代码的含义

0 0x0000 作业完成。1 0x0001 不正确的函数。2 0x0002 系统找不到指定的档案。3 0x0003 系统找不到指定的路径。4 0x0004 系统无法开启档案。5 0x0005 拒绝存取。6 0x0006 无效的代码。7 0x0007 储存体控制区块已毁。8 0x0008 储存体空间不足,无法处理这个指令。9 0x0009 储存体控制区块地址无效。10 0x000A 环境不正确。11 0x000B 尝试加载一个格式错误的程序。12 0x000C 存取码错误。1...

在ASP中访问和更新Cookies集合

在ASP中访问和更新Cookies集合

  Cookies的值比ASP其他集合(例如Form和ServerVariables)的值要复杂得多。Cookie是一小块由浏览器存贮在客户端系统上的文本,且随同每次请求发往它们应用于的域中的服务器。  ASP使得应用cookie较为容易,可以从Request对象的Cookies集合中获得所有随同请求发出的cookie值,并可创建或修改cookie,通过Response对象的Cookies集合发回给用户。  Cookie包含可用两种方式构造的信息,单值cookie提供其值给代...