GetFileVersionSize / GetFileVersionInfo -> Confusion

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..


   DWORD FileVersionSize;
   LPTSTR Filename;
   DWORD dwHnd;
   LPVOID pBuffer;
   UINT uVersionLen;

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

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

      FileVersionSize = GetFileVersionInfoSize( Filename,&dwHnd);

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

    pBuffer = new LPVOID[FileVersionSize];  //Create Buffer

#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,
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
larockdAuthor Commented:
#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?

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.
larockdAuthor Commented:
#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--------------------
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.

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

FileVersionSize = GetFileVersionInfoSize( TmpStr,&dwHnd);

pBuffer = new LPVOID[FileVersionSize];  //Create Buffer

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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.