Solved

GetFileVersionSize / GetFileVersionInfo -> Confusion

Posted on 1998-02-25
5
924 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
Comment Utility
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
Comment Utility
#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
Comment Utility
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
Comment Utility
#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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

772 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