I am trying to get various information about the version of a file in order
to determine that it is the correct file. I have one working implementation,
but I also need to generalize the code a bit in order to use it in a related
project.

The generalized code works exactly the same way as the non-generalized code
with a couple exceptions, but I am running into an error with the
GetFileVersionInfo().

Here's a sample:

INT Validate(std::string _file, lpData _info)
{
LPVOID Data;
DWORD dwLength;
DWORD dwEmpty;
dwLength = GetFileVersionInfoSize(_file.c_str(),&dwEmpty);
if (!dwLength) return -1;
Data = (LPVOID) malloc(dwLength+1);
if (!Data) return -2;
memset(Data,0,dwLength+1);
if (!GetFileVersionInfo(_file.c_str(),NULL,dwLength,&Data))
{
free(Data);
return -3;
}
...
}

The lpData is a structure containing the information I want to verify about
the file. My problem is that the pointer is no longer valid after I call the
GetFileVersionInfo(). I checked at run-time by watching the pointers - the
'Data' and '_info' pointers are valid before I call it, but then when it
returns (it does not go into the body of the if-block), the values are
invalid and cause a crash. E.g. the following:

Before After
Valid Invalid
_info = 0x0012f2b4 --> 0x00050000
Data = 0x00fd7be0 --> 0x0034037c

As I said before, I have another version that works just fine. Am I doing
something wrong? I pretty much copy-pasted the code.

TIA,

Re: GetFileVersionInfo() by Igor

Igor
Fri May 06 17:31:12 CDT 2005

"BRM" <BRM@discussions.microsoft.com> wrote in message
news:042F8DBA-08DD-4BC8-A9D0-2C917D9FEA5B@microsoft.com
> LPVOID Data;
> Data = (LPVOID) malloc(dwLength+1);
> if (!GetFileVersionInfo(_file.c_str(),NULL,dwLength,&Data))

You should pass Data, not &Data. The way you call GetFileVersionInfo, it
writes the first 4 bytes of version info into the memory occupied by
Data variable (as opposed to the memory _pointed to_ by Data), with the
rest busily trashing the stack.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925



Re: GetFileVersionInfo() by thatsalok

thatsalok
Sat May 07 07:04:02 CDT 2005


Hi Mr BRM,
Look at these Wrapper class based on GetFileVersionInfo(), hop
you find them intresting.

[url]http://www.codeproject.com/file/fileversioninfo.asp[/url]
[url]http://www.codeproject.com/file/VersionInfo.asp[/url]



BRM wrote:
> *I am trying to get various information about the version of a fil
> in order
> to determine that it is the correct file. I have one workin
> implementation,
> but I also need to generalize the code a bit in order to use it in
> related
> project.
>
> The generalized code works exactly the same way as th
> non-generalized code
> with a couple exceptions, but I am running into an error with the
> GetFileVersionInfo().
>
> Here's a sample:
>
> INT Validate(std::string _file, lpData _info)
> {
> LPVOID Data;
> DWORD dwLength;
> DWORD dwEmpty;
> dwLength = GetFileVersionInfoSize(_file.c_str(),&dwEmpty);
> if (!dwLength) return -1;
> Data = (LPVOID) malloc(dwLength+1);
> if (!Data) return -2;
> memset(Data,0,dwLength+1);
> if (!GetFileVersionInfo(_file.c_str(),NULL,dwLength,&Data))
> {
> free(Data);
> return -3;
> }
> ....
> }
>
> The lpData is a structure containing the information I want to verif
> about
> the file. My problem is that the pointer is no longer valid after
> call the
> GetFileVersionInfo(). I checked at run-time by watching the pointer
> - the
> 'Data' and '_info' pointers are valid before I call it, but then whe
> it
> returns (it does not go into the body of the if-block), the value
> are
> invalid and cause a crash. E.g. the following:
>
> Before After
> Valid Invalid
> _info = 0x0012f2b4 --> 0x00050000
> Data = 0x00fd7be0 --> 0x0034037c
>
> As I said before, I have another version that works just fine. Am
> doing
> something wrong? I pretty much copy-pasted the code.
>
> TIA,


-
thatsalo
-----------------------------------------------------------------------
Posted via http://www.codecomments.co
-----------------------------------------------------------------------



Re: GetFileVersionInfo() by TemporalBeing

TemporalBeing
Mon May 09 08:12:30 CDT 2005

Thanks. For whatever reason I could not see that one at the end of last
week. (Perhaps I had just been looking at the screen too long.)

Thanks,

BRM