QT 获取文件的版本号

QString getFileVertion( QString fullName )
{
    QString result = "";
    char* pData = nullptr;
    do
    {
        DWORD dwLen = GetFileVersionInfoSize(fullName.toStdWString().c_str(), 0);
        if (0 == dwLen)
        {
            break;
        }
        pData = new char [dwLen+1];
        BOOL bSuccess = GetFileVersionInfo(fullName.toStdWString().c_str(), 0, dwLen, pData);
        if (!bSuccess)
        {
            break;
        }
        struct LANGANDCODEPAGE
        {
          WORD wLanguage;
          WORD wCodePage;
        } *lpTranslate;
        LPVOID lpBuffer = nullptr;
        UINT uLen = 0;
        bSuccess = VerQueryValue(pData, (TEXT("\\VarFileInfo\\Translation")), (LPVOID*)&lpTranslate, &uLen);
        if(!bSuccess)
        {
            break;
        }
        QString str1, str2;
        str1.setNum(lpTranslate->wLanguage, 16);
        str2.setNum(lpTranslate->wCodePage, 16);
        str1 = "000" + str1;
        str2 = "000" + str2;
        QString verPath = "\\StringFileInfo\\"+ str1.right(4) + str2.right(4) +"\\FileVersion";
        bSuccess = VerQueryValue(pData, (verPath.toStdWString().c_str()), &lpBuffer, &uLen);
        if(!bSuccess)
        {
            break;
        }
        result = QString::fromUtf16((const unsigned short int *)lpBuffer);
    }while(false);
    if(nullptr != pData)
    {
        delete pData;
    }
    return result;
}

发布了53 篇原创文章 · 获赞 5 · 访问量 4万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览