?
Solved

how to display version information in the title bar?

Posted on 2001-07-24
4
Medium Priority
?
293 Views
Last Modified: 2013-11-20
hi,

i have filled in version information in my rc file, how can i display the information at my application window's title bar?

i have search for a long while but still cannot find a direct way to do this.

thanks,

bun
0
Comment
Question by:bunwong
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 

Expert Comment

by:abegnoche
ID: 6314646
here's the code that works for me. sorry I have no explanation for this, but looking at each api in msdn you should be able to understand what's going on.

    TCHAR szFilename[126] = "c:\\dev\\your_dll_here.dll";
    DWORD dwSize;
    DWORD dwZero;

     dwSize = ::GetFileVersionInfoSize(szFilename, &dwZero);

    // if version info exists
    if (dwSize)
    {
        char *pVersionInfo = new char[dwSize];
        char *pValue;
        UINT uValueLen;
        BOOL bRC;

        BOOL bRet = GetFileVersionInfo( szFilename, NULL, dwSize, pVersionInfo);
        if (!bRet)
            return;

        bRC = VerQueryValue(pVersionInfo,  
                            _TEXT("\\StringFileInfo\\040904B0\\FileVersion"),
                            (void  **) &pValue,
                            &uValueLen);

        if (bRC)
            MessageBox( pValue, "File Version", MB_OK|MB_ICONINFORMATION);

        delete [] pVersionInfo;
    }
0
 
LVL 3

Accepted Solution

by:
aphillips earned 400 total points
ID: 6315750
MFC should really provide this in it's templates, including displaying ti in the About box.

I use this function to get the version info as 4 strings.  You can then do with them as you wish including adding them to the mainframe window title.


#include <winver.h>

void GetExeVersion(CString &s1, CString &s2, CString &s3, CString &s4)
{
    // Get version of executable
    DWORD dummy;                                        // Version functions take parameters that do nothing?!
    size_t vi_size;                                     // Size of all version info
    void *buf;                                          // Buffer to hold all version info
    void *p_version;                                    // Holds ptr to product version string in buffer
    UINT len;                                           // Length of product version string

    if ((vi_size = ::GetFileVersionInfoSize(__argv[0], &dummy)) > 0 &&
        (buf = ::malloc(vi_size+1)) != NULL &&
        ::GetFileVersionInfo(__argv[0], dummy, vi_size, buf) &&
        ::VerQueryValue(buf, "\\StringFileInfo\\040904B0\\ProductVersion",
                        &p_version, &len) )
    {
        CString strProductVersion((LPCTSTR)p_version, len);
        ::free(buf);

        AfxExtractSubString(s1, strProductVersion, 0, ',');
        AfxExtractSubString(s2, strProductVersion, 1, ',');
        AfxExtractSubString(s3, strProductVersion, 2, ',');
        AfxExtractSubString(s4, strProductVersion, 3, ',');
        s1.TrimLeft();
        s2.TrimLeft();
        s3.TrimLeft();
        s4.TrimLeft();
    }
    else
    {
        s1.Empty();
        s2.Empty();
        s3.Empty();
        s4.Empty();
    }
}
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 6316270
Hi bunwong,

a friend of me once wrote a little hack to read version numbers from resources directly, maybe you want
to use this. Only problem I see is that the date-values are not set.

HRSRC      hRsrc = FindResource(AfxGetResourceHandle(), MAKEINTRESOURCE(VS_VERSION_INFO), RT_VERSION);
if ( hRsrc != NULL )
{
 HGLOBAL hg = LoadResource(NULL, hRsrc);  
 if(hg != NULL)
 {
  char *pRes = (char *) LockResource(hg);
  VS_FIXEDFILEINFO *pVersion = (VS_FIXEDFILEINFO *) (pRes + 0x28); // this is a hack !!!

  // read infos from pVersion...

 }
}

hope that helps,

ZOPPO
0
 

Author Comment

by:bunwong
ID: 6317191
very neat. other experts also provide very good solution. thanks all!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question