文件信息结构描述:
struct VS_FIXEDFILEINFO {
DWORD dwSignature//=0xFEEFO4BD
DWORD dwStrucVersion //该结构的版本信息,分高低版本
DWORD dwFileVersionMS//主文件版本
DWORD dwFileVersionLS//次文件版本
DWORD dwProductVersionMS //主产品版本
DWORD dwProductVersionLS //次产品版本
DWORD dwFileFlagsMask//文件标志掩码
DWORD dwFileFlags//文件标志(是否包含调试版本,动态版本结构...)
DWORD dwFileOS //文件原定的 *** 作系统(VOS_DOS,VOS_NT,VOS__WINDOWS16...)
DWORD dwFileType //文件类型(VFT_UNKNOWN,VFT_APP,VFT_DLL...)
DWORD dwFileSubtype /游枯简/当dwFileType为VFT_APP或VFT_DLL时该值为0,当为驱动信息VFT_APP或字体信息时该值包含其具体神裤的信息
DWORD dwFileDateMS //主时间戳
DWORD dwFileDateLS //次时间戳
}
===============================================
struct st_Language
{
WORD wLanguageID
WORD wCodePage
}
CString str("D:\\test\\test.exe")
DWORD dwSize = GetFileVersionInfoSize(str,NULL)
if(0 == dwSize) return
LPBYTE pBlock = (BYTE*)malloc(dwSize)
bool b = GetFileVersionInfo(str,0,dwSize,pBlock)
char* pVerValue = NULL
UINT nlen1 = 0
VerQueryValue(pBlock,TEXT("file://VarFileInfo//Translation"),
(LPVOID*)&pVerValue,&nlen1)
//获取语言
char* pLanValue = NULL
UINT nLen2 = 0
VerQueryValue(pBlock,"VarFileInfo\\Translation",(LPVOID*)&pLanValue,&nLen2)
//080404b0为中文
st_Language stlang = *((st_Language *)pLanValue)
//获取版本属败激性
VerQueryValue(pBlock,TEXT("file://%22),(LPVOID*)%26pVerValue,%26nlen1/)
VS_FIXEDFILEINFO *pfixfileinfo = (VS_FIXEDFILEINFO *)pVerValue
//修改属性
pfixfileinfo->dwFileVersionLS = 1234
pfixfileinfo->dwFileVersionMS = 4321
pfixfileinfo->dwProductVersionLS = 101
pfixfileinfo->dwProductVersionMS = 1010
//修改资源
HANDLE handle = BeginUpdateResource(str,FALSE)
BOOL result = UpdateResource(handle
,RT_VERSION
,MAKEINTRESOURCE(1)
,stlang.wLanguageID
,pBlock
,dwSize)
if (result == FALSE)
{
AfxMessageBox("Updata Resource False.")
}
EndUpdateResource(handle,FALSE)
free(pBlock)
茄宴C/C++ codeString __fastcall TForm8::GetFileVersion(String FileName)
{
int iVerInfoSize
char *pBuf
AnsiString asVer=""颤戚银
VS_FIXEDFILEINFO *pVsInfo
unsigned int iFileInfoSize = sizeof( VS_FIXEDFILEINFO )
iVerInfoSize = GetFileVersionInfoSize(FileName.c_str(), NULL)
if(iVerInfoSize!= 0)
{
pBuf = new char[iVerInfoSize]
if(GetFileVersionInfo(FileName.c_str(),0, iVerInfoSize, pBuf ) )
{
if(VerQueryValue(pBuf, "\\",(void **)&pVsInfo,&iFileInfoSize))
{
asVer = IntToStr( HIWORD(pVsInfo->dwFileVersionMS) )+"仔枣."
asVer += IntToStr( LOWORD(pVsInfo->dwFileVersionMS) )+"."
asVer += IntToStr( HIWORD(pVsInfo->dwFileVersionLS) )+"."
asVer += IntToStr( LOWORD(pVsInfo->dwFileVersionLS) )
}
}
delete pBuf
}
return asVer
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)