Click to See Complete Forum and Search --> : Module Version


Uri
April 6th, 1999, 10:50 AM
I need to know a module's (EXE and DLL) version in my application. The version is set by the version resource, but I need to read the version of a module which was not necessarily loaded into my app. (like file/properties does).

Any idea?
thanks

RajM
April 6th, 1999, 01:59 PM
Use the GetFileVersionInfo API.

BOOL GetFileVersionInfo( LPTSTR lptstrFilename, // pointer to filename string
DWORD dwHandle, // ignored
DWORD dwLen, // size of buffer
LPVOID lpData // pointer to buffer to receive
// file-version info.);
Use FileVersionInfoSize API to get the size of the fileversion info before calling the above.try using the class given below


class CVersionInfo
{
PBYTE m_pVersionBuffer;
struct TRANSLATION {
WORD langID;
WORD charset;
} m_translation;
public:
CVersionInfo(TCHAR *pFileName)
{
DWORD dummy=0;
m_pVersionBuffer=NULL;
long Size=GetFileVersionInfoSize(pFileName,&dummy);
if(Size > 0)
{
m_pVersionBuffer=new BYTE[Size];
}
if(GetFileVersionInfo(pFileName,dummy,Size,m_pVersionBuffer) == 0)
{
delete [] m_pVersionBuffer;
m_pVersionBuffer=NULL;
}
LPVOID lpvi; UINT iLen;

// Get translation info
if (VerQueryValue(m_pVersionBuffer,"\\VarFileInfo\\Translation", &lpvi, &iLen) && iLen >= 4)
{
m_translation=*(TRANSLATION*)lpvi;
}
}
~CVersionInfo()
{
if(m_pVersionBuffer)
delete [] m_pVersionBuffer;
}
const TCHAR* GetValue(const TCHAR * pValue)
{
LPCTSTR pVal=NULL;
UINT iLenVal=0;
TCHAR ch[100];
_stprintf(ch,"\\StringFileInfo\\%04x%04x\\%s",m_translation.langID,m_translation.charset,pValue);

VerQueryValue(m_pVersionBuffer, (LPTSTR)(LPCTSTR)ch,
(LPVOID*)&pVal, &iLenVal);
return pVal;
}



};