Created
February 19, 2016 12:16
-
-
Save z4none/dde6eea38d25c789fd56 to your computer and use it in GitHub Desktop.
get file version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| AnsiString GetFileVersion(AnsiString Path) | |
| { | |
| AnsiString asReturn; | |
| DWORD dwHandle,InfoSize; | |
| InfoSize = GetFileVersionInfoSize(Path.c_str(),&dwHandle); | |
| if(InfoSize == 0) return ""; | |
| //将版本信息资源读入缓冲区 | |
| char *InfoBuf = new char[InfoSize]; | |
| GetFileVersionInfo(Path.c_str(),0,InfoSize,InfoBuf); | |
| //获得生成文件使用的代码页及字符集信息 | |
| char *pInfoVal; | |
| unsigned int dwInfoValSize; | |
| VerQueryValue(InfoBuf,"\\VarFileInfo\\Translation",&((void *)pInfoVal), | |
| &dwInfoValSize);AnsiString V = "\\StringFileInfo\\" | |
| +IntToHex(*((unsigned short int *)pInfoVal),4) | |
| +IntToHex(*((unsigned short int *) &pInfoVal[2]),4) | |
| + "\\FileVersion"; | |
| //获得具体的版本号 | |
| VerQueryValue(InfoBuf, V.c_str(),&((void *)pInfoVal),&dwInfoValSize); | |
| asReturn = AnsiString(pInfoVal). | |
| SetLength(dwInfoValSize-1); | |
| delete InfoBuf; | |
| return(asReturn); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment