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);
轉載請說明出處:http://blog.csdn.net/mycaibo


發佈了41 篇原創文章 · 獲贊 13 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章