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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
| QString GetFileVertion(QString fullName){ DWORD dwLen = 0; char* lpData=NULL; LPCWSTR str_path; str_path=fullName.toStdWString().c_str(); BOOL bSuccess = FALSE; QString fileInfomation; DWORD vHandle=0; dwLen = GetFileVersionInfoSize( str_path, &vHandle); if (0 == dwLen) { qDebug()<<"获取版本字节信息失败!"; return""; } qDebug()<<"版本信息字节大小:"<<dwLen; lpData =(char*)malloc(dwLen+1); if (NULL == lpData) { qDebug()<<"分配内存失败"; return ""; } bSuccess = GetFileVersionInfo( fullName.toStdWString().c_str(),0, dwLen+1, lpData); if (!bSuccess) { qDebug()<<"获取文件版本信息错误!";
return""; } LPVOID lpBuffer = NULL; UINT uLen = 0;
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 str_value; QString code;
code ="\\StringFileInfo\\"+ strTranslation +"\\FileDescription"; bSuccess = VerQueryValue(lpData, (code.toStdWString().c_str()), &lpBuffer, &uLen); if (!bSuccess) { qDebug()<<"Get file verstion error!"; } else { str_value="文件说明:" + QString::fromUtf16((const unsigned short int *)lpBuffer)+"\n"; fileInfomation +=str_value; } code ="\\StringFileInfo\\"+ strTranslation +"\\FileVersion"; bSuccess = VerQueryValue(lpData, (code.toStdWString().c_str()), &lpBuffer, &uLen); if (!bSuccess) { qDebug()<<"获取文件版本信息错误!";
} else { str_value="文件版本信息:" + QString::fromUtf16((const unsigned short int *)lpBuffer)+"\n"; fileInfomation +=str_value; } code ="\\StringFileInfo\\"+ strTranslation +"\\ProductName"; bSuccess = VerQueryValue(lpData, (code.toStdWString().c_str()), &lpBuffer, &uLen); if (!bSuccess) { qDebug()<<"Get file ProductName error!";
} else { str_value="产品名称:" + QString::fromUtf16((const unsigned short int *)lpBuffer)+"\n"; fileInfomation +=str_value; } code ="\\StringFileInfo\\"+ strTranslation +"\\ProductVersion"; bSuccess = VerQueryValue(lpData, (code.toStdWString().c_str()), &lpBuffer, &uLen); if (!bSuccess) { qDebug()<<"获取产品版本信息错误!";
} else { str_value="产品版本信息:" + QString::fromUtf16((const unsigned short int *)lpBuffer)+"\n"; fileInfomation +=str_value; }
code ="\\StringFileInfo\\"+ strTranslation +"\\InternalName"; bSuccess = VerQueryValue(lpData, (code.toStdWString().c_str()), &lpBuffer, &uLen); if (!bSuccess) { qDebug()<<"Get file InternalName error!";
} else { str_value="内部名称:" + QString::fromUtf16((const unsigned short int *)lpBuffer)+"\n"; fileInfomation +=str_value; }
code ="\\StringFileInfo\\"+ strTranslation +"\\OriginalFileName"; bSuccess = VerQueryValue(lpData, (code.toStdWString().c_str()), &lpBuffer, &uLen); if (!bSuccess) { qDebug()<<"Get file OriginalFileName error!";
} else { str_value="原始文件名:" + QString::fromUtf16((const unsigned short int *)lpBuffer)+"\n"; fileInfomation +=str_value; } code ="\\StringFileInfo\\"+ strTranslation +"\\Type"; bSuccess = VerQueryValue( lpData, (code.toStdWString().c_str()), &lpBuffer, &uLen); if (!bSuccess) { qDebug()<<"Get file LegalTradeMarks error!";
} else { str_value="版权:" + QString::fromUtf16((const unsigned short int *)lpBuffer)+"\n"; fileInfomation +=str_value; }
delete lpData;
return fileInfomation; }
|