Rev 1 | Blame | Compare with Previous | Last modification | View Log
/*Written by Steve Bryndin (fishbed@tezcat.com, steveb@gvsi.com).This code may be used in compiled form in any way you wish. Thisfile may be redistributed unmodified by any means PROVIDING it isnot sold for profit without the authors written consent, andproviding that this notice and the authors name is included.An email letting me know that you are using it would benice as well.This software is provided "as is" without express or implied warranty.Use it at you own risk! The author accepts no liability for any damagesto your computer or data these products may cause.*/// ExecImageVersion.cpp: implementation of the CExecImageVersion class.////////////////////////////////////////////////////////////////////////#include "stdafx.h"#include "ExecImageVersion.h"#include "memory.h"#ifdef _DEBUG#undef THIS_FILEstatic char THIS_FILE[]=__FILE__;#define new DEBUG_NEW#endif//////////////////////////////////////////////////////////////////////// Construction/Destruction////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// CExecImageVersion::CExecImageVersion( LPTSTR lpszExtension)//////////////////////////////////////////////////////////////////////////CExecImageVersion::CExecImageVersion( LPTSTR lpszExtension){m_strImage = AfxGetAppName();m_strImage += _T(".");m_strImage += lpszExtension;m_lpszImageName = m_strImage.GetBuffer(sizeof(m_strImage));m_lpBuffer = NULL;m_lpData = NULL;InitVer();}//////////////////////////////////////////////////////////////////////// CExecImageVersion::CExecImageVersion( LPTSTR lpszImageName, LPTSTR lpszExtension)//////////////////////////////////////////////////////////////////////////CExecImageVersion::CExecImageVersion( LPTSTR lpszImageName, LPTSTR lpszExtension){m_lpszImageName = lpszImageName;m_strImage += _T(".");m_strImage += lpszExtension;m_lpBuffer = NULL;m_lpData = NULL;InitVer();}//////////////////////////////////////////////////////////////////////// CExecImageVersion::~CExecImageVersion()//////////////////////////////////////////////////////////////////////////CExecImageVersion::~CExecImageVersion(){if (m_lpBuffer)free( m_lpBuffer);}//////////////////////////////////////////////////////////////////////// CString CExecImageVersion::GetProductName()//////////////////////////////////////////////////////////////////////////CString CExecImageVersion::GetProductName(){CString strProduct = _T(""); ;//Use the version information block to obtain the product name. 040904B0if (m_lpBuffer){::VerQueryValue( m_lpBuffer,TEXT("\\StringFileInfo\\040904B0\\ProductName"),&m_lpData,&m_uiDataSize);strProduct.Format("%s", m_lpData);}return strProduct;}//////////////////////////////////////////////////////////////////////// CString CExecImageVersion::GetProductVersion()//////////////////////////////////////////////////////////////////////////CString CExecImageVersion::GetProductVersion(){CString strProductVer = _T("");if (m_lpBuffer){//Use the version information block to obtain the product name.::VerQueryValue( m_lpBuffer,TEXT("\\StringFileInfo\\040904B0\\ProductVersion"),&m_lpData,&m_uiDataSize);strProductVer.Format("%s", m_lpData);}return strProductVer;}//////////////////////////////////////////////////////////////////////// CString CExecImageVersion::GetCompanyName()//////////////////////////////////////////////////////////////////////////CString CExecImageVersion::GetCompanyName(){CString strCompany = _T("");if (m_lpBuffer){//Use the version information block to obtain the product name.::VerQueryValue( m_lpBuffer,TEXT("\\StringFileInfo\\040904B0\\CompanyName"),&m_lpData,&m_uiDataSize);strCompany.Format("%s", m_lpData);}return strCompany;}//////////////////////////////////////////////////////////////////////// CString CExecImageVersion::GetCopyright()//////////////////////////////////////////////////////////////////////////CString CExecImageVersion::GetCopyright(){CString strCopy = _T("");if (m_lpBuffer){//Use the version information block to obtain the product name.::VerQueryValue( m_lpBuffer,TEXT("\\StringFileInfo\\040904B0\\LegalCopyright"),&m_lpData,&m_uiDataSize);strCopy.Format("%s", m_lpData);}return strCopy;}//////////////////////////////////////////////////////////////////////// CString CExecImageVersion::GetComments()//////////////////////////////////////////////////////////////////////////CString CExecImageVersion::GetComments(){CString strComments = _T("");if (m_lpBuffer){//Use the version information block to obtain the product name.::VerQueryValue( m_lpBuffer,TEXT("\\StringFileInfo\\040904B0\\Comments"),&m_lpData,&m_uiDataSize);strComments.Format("%s", m_lpData);}return strComments;}//////////////////////////////////////////////////////////////////////// CString CExecImageVersion::GetFileDescription()//////////////////////////////////////////////////////////////////////////CString CExecImageVersion::GetFileDescription(){CString strFileDescr = _T("");if (m_lpBuffer){//Use the version information block to obtain the product name.::VerQueryValue( m_lpBuffer,TEXT("\\StringFileInfo\\040904B0\\FileDescription"),&m_lpData,&m_uiDataSize);strFileDescr.Format("%s", m_lpData);}return strFileDescr;}//////////////////////////////////////////////////////////////////////// CString CExecImageVersion::GetFileVersion()//////////////////////////////////////////////////////////////////////////CString CExecImageVersion::GetFileVersion(){CString strFileVer = _T("");if (m_lpBuffer){//Use the version information block to obtain the product name.::VerQueryValue( m_lpBuffer,TEXT("\\StringFileInfo\\040904B0\\FileVersion"),&m_lpData,&m_uiDataSize);strFileVer.Format("%s", m_lpData);}return strFileVer;}//////////////////////////////////////////////////////////////////////// CString CExecImageVersion::GetInternalName()//////////////////////////////////////////////////////////////////////////CString CExecImageVersion::GetInternalName(){CString strIN = _T("");if (m_lpBuffer){//Use the version information block to obtain the product name.::VerQueryValue( m_lpBuffer,TEXT("\\StringFileInfo\\040904B0\\InternalName"),&m_lpData,&m_uiDataSize);strIN.Format("%s", m_lpData);}return strIN;}//////////////////////////////////////////////////////////////////////// CString CExecImageVersion::GetLegalTrademarks()//////////////////////////////////////////////////////////////////////////CString CExecImageVersion::GetLegalTrademarks(){CString strLegTrade = "";if (m_lpBuffer){//Use the version information block to obtain the product name.::VerQueryValue( m_lpBuffer,TEXT("\\StringFileInfo\\040904B0\\LegalTrademarks"),&m_lpData,&m_uiDataSize);strLegTrade.Format("%s", m_lpData);}return strLegTrade;}//////////////////////////////////////////////////////////////////////// CString CExecImageVersion::GetPrivateBuild()//////////////////////////////////////////////////////////////////////////CString CExecImageVersion::GetPrivateBuild(){CString strPrivBuild = _T("");if (m_lpBuffer){//Use the version information block to obtain the product name.::VerQueryValue( m_lpBuffer,TEXT("\\StringFileInfo\\040904B0\\PrivateBuild"),&m_lpData,&m_uiDataSize);strPrivBuild.Format("%s", m_lpData);}return strPrivBuild;}//////////////////////////////////////////////////////////////////////// CString CExecImageVersion::GetSpecialBuild()//////////////////////////////////////////////////////////////////////////CString CExecImageVersion::GetSpecialBuild(){CString strSpecBuild = _T("");if (m_lpBuffer){//Use the version information block to obtain the product name.::VerQueryValue( m_lpBuffer,TEXT("\\StringFileInfo\\040904B0\\SpecialBuild"),&m_lpData,&m_uiDataSize);strSpecBuild.Format("%s", m_lpData);}return strSpecBuild;}//////////////////////////////////////////////////////////////////////// void CExecImageVersion::InitVer()//////////////////////////////////////////////////////////////////////////void CExecImageVersion::InitVer(){m_dwHandle = 0;m_uiDataSize = 80;//m_lpData = malloc(m_uiDataSize);// Get the version information block size,// then use it to allocate a storage buffer.if (m_dwSize = ::GetFileVersionInfoSize( m_lpszImageName, &m_dwHandle)){m_lpBuffer = malloc( m_dwSize);// Get the versioninformation block::GetFileVersionInfo( m_lpszImageName, 0, m_dwSize, m_lpBuffer);}else{if (m_lpBuffer)free( m_lpBuffer);m_lpBuffer = NULL;}}