QT用API获得文件的版本信息
文章转自王牌软件
站长推荐:NSetup一键部署软件
一键式完成美化安装包制作,自动增量升级,数据统计,数字签名。应对各种复杂场景,脚本模块化拆分,常规复杂的脚本代码,图形化设置。无需专业的研发经验,轻松完成项目部署。(www.nsetup.cn)
只回答业务咨询
站长推荐:NSetup一键部署软件
一键式完成美化安装包制作,自动增量升级,数据统计,数字签名。应对各种复杂场景,脚本模块化拆分,常规复杂的脚本代码,图形化设置。无需专业的研发经验,轻松完成项目部署。(www.nsetup.cn)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
#include<windows.h> #include<winver.h> ///引入Version.lib库 QString InfomationCollect::GetFileVertion( QString fullName ) { DWORD dwLen = 0; char* lpData=NULL; BOOL bSuccess = FALSE; QString fileInfomation; //获得文件基础信息 //-------------------------------------------------------- dwLen = GetFileVersionInfoSize(fullName.toStdWString().c_str(), 0); if (0 == dwLen) { //qDebug()<<"Get file verstion error! "; return ""; } lpData =new char [dwLen+1]; bSuccess = GetFileVersionInfo(fullName.toStdWString().c_str(), 0, dwLen, lpData); if (!bSuccess) { //qDebug()<<"Get file verstion error! "; delete lpData; return ""; } LPVOID lpBuffer = NULL; UINT uLen = 0; //获得语言和代码页(language and code page) //--------------------------------------------------- bSuccess = VerQueryValue(lpData, (TEXT("\\VarFileInfo\\Translation")), &lpBuffer, &uLen); QString strTranslation,str1,str2; unsigned short int *p =(unsigned short int *)lpBuffer; str1.setNum(*p,16); str1="000" + str1; strTranslation+= str1.mid(str1.size()-4,4); str2.setNum(*(++p),16); str2="000" + str2; strTranslation+= str2.mid(str2.size()-4,4); //获得文件版本信息 //----------------------------------------------------- QString code = "\\StringFileInfo\\"+ strTranslation +"\\FileVersion"; bSuccess = VerQueryValue(lpData, (code.toStdWString().c_str()), &lpBuffer, &uLen); if (!bSuccess) { //qDebug()<<"Get file verstion error! "; delete lpData; return ""; } fileInfomation += QString::fromUtf16((const unsigned short int *)lpBuffer); //获得文件的描述 //--------------------------------------------------------- /*code = "\\StringFileInfo\\"+ strTranslation +"\\FileDescription"; bSuccess = VerQueryValue(lpData, (code.toStdWString().c_str()), &lpBuffer, &uLen); if (!bSuccess) { qDebug()<<"Get file verstion error! "; delete lpData; return ""; } fileInfomation +="^"; fileInfomation += QString::fromUtf16((const unsigned short int *)lpBuffer);*/ delete [] lpData;//此处不需要释放 return fileInfomation; } //================================================== //VC版本 char* szFileName = “C:\\EnochShen.exe”; DWORD dwSize = GetFileVersionInfoSize(szFileName,NULL); LPVOID pBlock = malloc(dwSize); GetFileVersionInfo(szFileName,0,dwSize,pBlock); char* pVerValue = NULL; UINT nSize = 0; VerQueryValue(pBlock,TEXT(“\\VarFileInfo\\Translation”), (LPVOID*)&pVerValue,&nSize); CString strSubBlock,strTranslation,strTemp; strTemp.Format(“000%x”,*((unsigned short int *)pVerValue)); strTranslation = strTemp.Right(4); strTemp.Format(“000%x”,*((unsigned short int *)&pVerValue[2])); strTranslation += strTemp.Right(4); //080404b0为中文,040904E4为英文 //文件描述 strSubBlock.Format(“\\StringFileInfo\\%s\\FileDescription”,strTranslation); VerQueryValue(pBlock,strSubBlock.GetBufferSetLength(256),(LPVOID*)&pVerValue,&nSize); strSubBlock.ReleaseBuffer(); strTemp.Format(“文件描述: %s”,pVerValue); AfxMessageBox(strTemp); //内部名称 strSubBlock.Format(“\\StringFileInfo\\%s\\InternalName”,strTranslation); VerQueryValue(pBlock,strSubBlock.GetBufferSetLength(256),(LPVOID*)&pVerValue,&nSize); strSubBlock.ReleaseBuffer(); strTemp.Format(“文件描述: %s”,pVerValue); AfxMessageBox(strTemp); //合法版权 strSubBlock.Format(“\\StringFileInfo\\%s\\LegalTradeMarks”,strTranslation); VerQueryValue(pBlock,strSubBlock.GetBufferSetLength(256),(LPVOID*)&pVerValue,&nSize); strSubBlock.ReleaseBuffer(); strTemp.Format(“合法版权: %s”,pVerValue); AfxMessageBox(strTemp); //原始文件名 strSubBlock.Format(“\\StringFileInfo\\%s\\OriginalFileName”,strTranslation); VerQueryValue(pBlock,strSubBlock.GetBufferSetLength(256),(LPVOID*)&pVerValue,&nSize); strSubBlock.ReleaseBuffer(); strTemp.Format(“原始文件名: %s”,pVerValue); AfxMessageBox(strTemp); //产品名称 strSubBlock.Format(“\\StringFileInfo\\%s\\ProductName”,strTranslation); VerQueryValue(pBlock,strSubBlock.GetBufferSetLength(256),(LPVOID*)&pVerValue,&nSize); strSubBlock.ReleaseBuffer(); strTemp.Format(“产品名称: %s”,pVerValue); AfxMessageBox(strTemp); //产品版本 strSubBlock.Format(“\\StringFileInfo\\%s\\ProductVersion”,strTranslation); VerQueryValue(pBlock,strSubBlock.GetBufferSetLength(256),(LPVOID*)&pVerValue,&nSize); strSubBlock.ReleaseBuffer(); strTemp.Format(“产品版本: %s”,pVerValue); AfxMessageBox(strTemp); free(pBlock); |
学习日记,兼职软件设计,软件修改,毕业设计。
本文出自 学习日记,转载时请注明出处及相应链接。
本文永久链接: https://www.softwareace.cn/?p=453