On MSDN I noticed the following for the VerQueryValue function:
lplpBuffer [out]
LPVOID
When this method returns, contains the address of a pointer to the requested version information in the buffer pointed to by pBlock. The memory pointed to by lplpBuffer is freed when the associated pBlock memory is freed._
How does the system know when pBlock is freed since pBlock is allocated by the caller?
I'm using the following code:
UINT reqSize = ::GetSystemDirectoryW(nullptr, 1);
std::vector<wchar_t> winDirectory (reqSize, 0);
UINT retVal = ::GetSystemDirectoryW(&winDirectory[0], reqSize);
std::wstring filePath(winDirectory.begin(), winDirectory.end()-1);
filePath.append(L"\\kernel32.dll");
DWORD bufSize = ::GetFileVersionInfoSizeW(
filePath.c_str(),
nullptr);
std::vector<BYTE> fileInfo (bufSize, 0);
::GetFileVersionInfoW(
filePath.c_str(),
0,
bufSize,
&fileInfo[0]);
UINT size = 0;
VS_FIXEDFILEINFO * ptr = nullptr;
BOOL error = ::VerQueryValueW(
&fileInfo[0],
L"\\",
reinterpret_cast<LPVOID*>(&ptr),
&size);