CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Module Version

  1. #1
    Join Date
    Apr 1999
    Posts
    6

    Module Version

    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


  2. #2
    Join Date
    Apr 1999
    Posts
    37

    Re: Module Version

    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;
    }



    };


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured