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,