Solved

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

Posted on 2004-09-24
9
1,760 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
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 4

Expert Comment

by:DaveyEss
Comment Utility
0
 

Author Comment

by:Morten from Eliten
Comment Utility
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
Comment Utility
I'm not sure I follow.  DO you mean you want to get the version info of your project at design time?
0
 
LVL 9

Expert Comment

by:_ys_
Comment Utility
This article describes a method for embedding version information compile time.
www.dlugosz.com/CPP/Dlugosz_Programming_Guidelines.doc
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:Morten from Eliten
Comment Utility
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_
Comment Utility
> 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
Comment Utility
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
Comment Utility
PAQed with points refunded (50)

modulo
Community Support Moderator
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

728 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now