Solved

How do I extract the version info from my VS_VERSION_INFO structure ?

Posted on 2004-09-24
9
1,784 Views
Last Modified: 2008-01-09
How do I extract the version info from the VS_VERSION_INFO resource I have in my project ?

My project generates a dll file, so I cannot use the GetFileVersionInfo() to extract the info from the dll file itself, I need to extract the version info from the VS_VERSION_INFO resource I have in my project.
0
Comment
Question by:Morten from Eliten
[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
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 4

Expert Comment

by:DaveyEss
ID: 12140856
0
 

Author Comment

by:Morten from Eliten
ID: 12141503
The link http://www.microsoft.com/msj/0498/c0498.aspx also describes how to extract the version info from a file, not from your current project. Im not able to use this approach, I need to extract the information from the structure which is present in my project, not from the resulting Dll file.
0
 
LVL 4

Expert Comment

by:DaveyEss
ID: 12141636
I'm not sure I follow.  DO you mean you want to get the version info of your project at design time?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:_ys_
ID: 12141730
This article describes a method for embedding version information compile time.
www.dlugosz.com/CPP/Dlugosz_Programming_Guidelines.doc
0
 

Author Comment

by:Morten from Eliten
ID: 12144183
A resource file can contain one or more resources. These can be string resources, bitmaps, icons, version informations, etc.

All these resources have specific API calls that allows you to read that resource. To load a string resource you call LoadString(), to load a bitmap resource you call LoadBitmap(), to load an icon resource you call LoadIcon() - Now what do you call to load a versioninfo ?

The GetFileVersionInfo() and DllGetVersion() require you to load an .exe or .dll file into memory, then query that file for its version info.

First of all, the program I have is already loaded into memory, why would I load it into memory again to query information which already resides somewhere in its memory ?

Secondly since the program resides in a dll file, I have no clue what name this file has (It may have been renamed since it was compiled) and I dont know which folder it resides in (It may have been moved since it was compiled).
0
 
LVL 9

Expert Comment

by:_ys_
ID: 12158241
> the program I have is already loaded into memory, why would I load it into memory again to query information which already resides somewhere in its memory ?
As a DLL can only be loaded once into a process space, the LoadLibrary suite of functions wouldn't load a second instance if it were already there. They simply return a HANDLE to the existing loaded module.

> the program resides in a dll file, I have no clue what name this file has (It may have been renamed since it was compiled) and I dont know which folder it resides in (It may have been moved since it was compiled).
The function GetModuleName can give you the name to pass to GetFileVersionInfo.
0
 

Author Comment

by:Morten from Eliten
ID: 12161282
Well after trying out a large number of items, I finally came up with a way to extract the version numbers directly from the VS_VERSION_INFO resource of my project.

I have pasted the code I used to do so below, if anyone else ever wants to do this:

HRSRC hRes = FindResource(_Module.GetModuleInstance(), MAKEINTRESOURCE(VS_VERSION_INFO), RT_VERSION);
HGLOBAL hGlobal = LoadResource(_Module.GetModuleInstance(), hRes);
VS_VERSIONINFO *pVersionInfo      = (VS_VERSIONINFO*) LockResource(hGlobal);
char *pInfo = (char*) pVersionInfo;
BYTE sIdentifier[] = {0xBD, 0x04, 0xEF, 0xFE};

for(int nCount=0; nCount<pVersionInfo->wLength-4; nCount++)
{
 if(memcmp(pInfo+nCount, sIdentifier, 4) == 0)
 {
  VS_FIXEDFILEINFO *pFixedFileInfo = (VS_FIXEDFILEINFO*) (pInfo+nCount);
 }
}
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12632997
PAQed with points refunded (50)

modulo
Community Support Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

749 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