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

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

编程学习2022-07-1084920

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++
分享给朋友:

相关文章

计算机蓝屏代码的含义

计算机蓝屏代码的含义

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错误提示大全

ASP错误提示大全

Microsoft VBScript 语法错误(0×800A03E9)–>内存不足Microsoft VBScript 语法错误(0×800A03EA)–>语法错误Microsoft VBScript 语法错误(0×800A03EB)–>缺少’:’Microsoft VBScript 语法错误(0×800A03ED)–>缺少’(’Mi...

SetTimer(), KillTimer() 使用

SetTimer(), KillTimer() 使用

SetTimer函数的用法  1 )用WM_TIMER来设置定时器  先请看SetTimer这个API函数的原型  UINT_PTR SetTimer(   HWND hWnd, // 窗口句柄   UINT_PTR nIDEvent, // 定时器ID,多个定时器时,可以通过该ID判断是哪个定时器   UINT uElapse, // 时间间隔,单位为毫秒   TIMERPROC lpTimerFunc // 回调函数   );例如  SetTimer...

ASP.NET AJAX下alert弹出对话框

ASP.NET AJAX下alert弹出对话框

ASP.NET AJAX下alert弹出对话框定义:protected void ajaxMessage(Control control, string message) { ajaxMessage(control, message, "click"); } protected void ajaxMessage(Control control, string message, string key) { ScriptManager...