2007年12月20日星期四

取得文件的 Version information

连接库函数:
//----add by zeng for GetFileVersionInfoSize() and GetFileVersionInfo()
#include
#include
#pragma comment( lib , "C:\\Programme\\Microsoft Visual Studio\\VC98\\Lib\\VERSION.LIB" )
//--

代码:
//----Get the file version:
// C:\Programme\Adobe\Reader 8.0\Reader\AcroRd32.exe
long len;
DWORD dwHandle;
len = GetFileVersionInfoSize((LPTSTR)(LPCSTR)sourceDB,&dwHandle);
PTSTR pBuffer = new TCHAR[len];
CString l;
l.Format("%d", len);
AfxMessageBox(l);
memset((void*)pBuffer,0,len);

//get .exe or .DLL resource info, put into pBuffer?
if(GetFileVersionInfo((LPTSTR)(LPCSTR)sourceDB,0,len,(PVOID)pBuffer))
{ //GetFileVersionInfo false.
l.Format("%d", (LPTSTR)pBuffer);
AfxMessageBox(l);
UINT puLen;
//PTSTR lplpBuffer = new TCHAR[len];
VS_FIXEDFILEINFO *lplpBuffer;
if ( VerQueryValue( pBuffer, "\\",(void**)&lplpBuffer, /*(LPVOID*) &lplpBuffer,*/ &puLen ) )
l.Format("%d", lplpBuffer->dwProductVersionLS);
AfxMessageBox(l);
//AfxMessageBox("break");
}

//--



VS_FIXEDFILEINFO 的结构:
typedef struct tagVS_FIXEDFILEINFO
{
DWORD dwSignature; /* e.g. 0xfeef04bd */
DWORD dwStrucVersion; /* e.g. 0x00000042 = "0.42" */
DWORD dwFileVersionMS; /* e.g. 0x00030075 = "3.75" */
DWORD dwFileVersionLS; /* e.g. 0x00000031 = "0.31" */
DWORD dwProductVersionMS; /* e.g. 0x00030010 = "3.10" */
DWORD dwProductVersionLS; /* e.g. 0x00000031 = "0.31" */
DWORD dwFileFlagsMask; /* = 0x3F for version "0.42" */
DWORD dwFileFlags; /* e.g. VFF_DEBUG | VFF_PRERELEASE */
DWORD dwFileOS; /* e.g. VOS_DOS_WINDOWS16 */
DWORD dwFileType; /* e.g. VFT_DRIVER */
DWORD dwFileSubtype; /* e.g. VFT2_DRV_KEYBOARD */
DWORD dwFileDateMS; /* e.g. 0 */
DWORD dwFileDateLS; /* e.g. 0 */
} VS_FIXEDFILEINFO;


参考:
http://www.cpp-tutor.de/mfc/mfc/kap7/lektion8.htm

没有评论: