Solved

GetFileVersionSize / GetFileVersionInfo -> Confusion

Posted on 1998-02-25
5
929 Views
Last Modified: 2013-12-03
I have stumbled my way through getting this code to work..  Mostly guess work and looking at someone else's code on this subject.  I am confused about how things are working.  I have several questions on this code marked throughout..  Hopefully someone can explain what I am confused about..



////////GET PRODUCT VERSION INFORMATION

   DWORD FileVersionSize;
   LPTSTR Filename;
   DWORD dwHnd;
   LPVOID pBuffer;
   VS_FIXEDFILEINFO *pFixedInfo;
   UINT uVersionLen;

   //CONVERT CString To LPTSTR
1.)  Is this a good technique for converting an object of CString to LPTSTR?  It seems to work?

     Filename = new char[strlen(TmpStr)+1];
     strcpy(Filename,TmpStr);

    //GET FILE VERSION SIZE INFO
      FileVersionSize = GetFileVersionInfoSize( Filename,&dwHnd);

#2.)  Why does this function require a DWORD Handle if it is never used?

    //GET FILE VERSION INFORMATION
    pBuffer = new LPVOID[FileVersionSize];  //Create Buffer
    GetFileVersionInfo(Filename,dwHnd,FileVersionSize,pBuffer);

#3.)  when I allocated the memory for pBuffer did I do it correctly for that type (LPVOID)?

    //Query Value
    VerQueryValue(pBuffer,"\\",(void **)&pFixedInfo,&uVersionLen);

#4.)  Now this is where I am completly lost.  Looking at the documentation for this function under Visual C++ 5.0.  How could one determine that the third parameter had to be of type VSFIXEDFILE_INFO?  The doc says this parameter "Points to a buffer that receives a pointer to the version-information value."  Only after looking at this over and over and looking at someone else's code I came to the conclusion that it had to be an Object of type VSFIXEDFILE_INFO.  Why does this parameter have to be a (void **) pointer?

    delete[] Filename;
    delete[] pBuffer;


Any help on any of these questions would greatly be appreciated..  Thanks In Advance,
Darrell
0
Comment
Question by:larockd
  • 3
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
galkin earned 10 total points
ID: 1411567
1.Yes you can convert CString to LPCTSTR since CString class has such an operator.
2.This function require this parameter since it sets it to zero. Ispite of the fact this parameter is never used I guess when this function was designed Windows developers intended to use it but funally then they didn't. But you still must supply valid DWORD variable.
3. When you allocate memory with operator new you must specify type since new allocates specific number of bytes. So specifying type new allocates sizeof(type) * number bytes. void doesn't have meaning of byte so this allocation is incorrect and you must be given compilation error.
4.About how to get version information of specific file I refer you to "codeguru" site at http://www.codeguru.com/dll/dll_version.shtml
0
 

Author Comment

by:larockd
ID: 1411568
#1.  I am confused on your number one answer.  CString has an operator to convert CString into LPTSTR?  How do I do this?  Right now you can see hwo I am doing it above.  Probably not the most efficient way.

#3.  On the new operation for number three, I do not get a compilation error.  In fact, when all is said and done and I check pFixedInfo it appears to contain all thwe correct values.  
This all might be luck of the draw.  However, since pBuffer needs to be of type LPVOID how should I allocated the buffer based on FileVersionSize which is a DWORD?

Thanks
0
 
LVL 7

Expert Comment

by:galkin
ID: 1411569
1. when you pass CString object where LPCTSTR is expected this operator is called. you can check it by stepping into code.
3.Where in 2 you allocate memory with new LPVOID you should be given a compilation error. If you don't get it it is due to rather sophisticated compiler which treats void as byte. I suggest you new BYTE and then convert result to LPVOID.
0
 

Author Comment

by:larockd
ID: 1411570
#1.) This is not happening on my compiler (Visual C++ v5.0 pro).

TmpStr is a CString that contains a Valid Path To A File Name.
I changed parameter one of the GetFileVersionSize call and GetFileVersionInfo call directly to the CString Object.  As above it was previously Filename which I manually converted to LPTSTR.  When I looked at your answer again you are referring to LPCTSTR, However I need LPTSTR for that parameter.


#3.)  My compiler is Visual C++.  So the way I should do it is

    pBuffer = new BYTE[FileVersionSize];

How would I convert the result to LPVOID?  In fact wouldn't the result already be in LPVOID form since I declared  pBuffer is of type LPVOID?

Thanks For your time.

When I compile this code with the CString Objects instead of the LPTSTR I get the following Errors.
--------------------Configuration: LORDSED - Win32 Debug--------------------
Compiling...
LORDSEDDlg.cpp
F:\Program Files\DevStudio\MyProjects\LordsBKup\LORDSEDDlg.cpp(185) : error C2664: 'GetFileVersionInfoSizeA' : cannot convert parameter 1 from 'class CString' to 'char *'
F:\Program Files\DevStudio\MyProjects\LordsBKup\LORDSEDDlg.cpp(189) : error C2664: 'GetFileVersionInfoA' : cannot convert parameter 1 from 'class CString' to 'char *'
Error executing cl.exe.

LORDSED.exe - 2 error(s), 0 warning(s)

Now if I change the parameter to the LPTSTR Filename it compiles.
Why does this happen.  Above you said it should automatically convert it?  Even if I type cast it, it will error (LPTSTR)TmpStr.


//CONVERT CString To LPTSTR
Filename = new char[strlen(TmpStr)+1];
strcpy(Filename,TmpStr);

    //GET FILE VERSION SIZE INFO
FileVersionSize = GetFileVersionInfoSize( TmpStr,&dwHnd);

//GET FILE VERSION INFORMATION
pBuffer = new LPVOID[FileVersionSize];  //Create Buffer
GetFileVersionInfo(TmpStr,dwHnd,FileVersionSize,pBuffer);

0
 
LVL 7

Expert Comment

by:galkin
ID: 1411571
1.You get en error since char* is ecpected in GetFileVersionInfoSize. CString has LPCTSTR operator which converts to const char in ANSI. You should explicity convert it to char. (LPTSTR)(LPCTSTR)strParam.
2.When you allocate memory you are given pointer to the same type you allocate. Since in C++ pointer of any type can be converted to pointer of another type( in some cases compiler does the job in other cases explicit conversion is required) you can later conver LPBYTE to LPVOID when you nedd to pass this parameter and LPVOID is expected.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

911 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

21 Experts available now in Live!

Get 1:1 Help Now