简体   繁体   English

了解VerQueryValue

[英]Understanding VerQueryValue

On MSDN I noticed the following for the VerQueryValue function: 在MSDN上,我注意到VerQueryValue函数的以下内容:

lplpBuffer [out] lplpBuffer [out]
LPVOID LPVOID
When this method returns, contains the address of a pointer to the requested version information in the buffer pointed to by pBlock. 当此方法返回时,包含指向pBlock指向的缓冲区中所请求的版本信息的指针的地址。 The memory pointed to by lplpBuffer is freed when the associated pBlock memory is freed._ 当关联的pBlock内存被释放时,lplpBuffer指向的内存被释放._

How does the system know when pBlock is freed since pBlock is allocated by the caller? 由于pBlock是由调用者分配的,系统如何知道何时释放pBlock?

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);

VerQueryValue返回指向您分配的初始内存块内某处的指针(GetFileVersionInfoSize返回一个足够大的块的大小,以包含整个版本资源+ ansi到unicode转换所需的任何空间等)

At least in some occasions, VerQueryValue performs conversion of the version data (eg Unicode to ASCII conversion when Unicode version of GetFileVersionInfo , but ASCII version of VerQueryValue are used). 至少在某些情况下, VerQueryValue执行版本数据的转换(例如,当使用Unicode版本的GetFileVersionInfo但使用ASCII版本的VerQueryValue时,Unicode转换为ASCII转换)。 GetFileVersionInfoSize obviously computes the buffer size large enough to hold converted data. GetFileVersionInfoSize显然计算的缓冲区大小足以容纳转换后的数据。

GetFileVersionInfo copies data into the supplied buffer. GetFileVersionInfo数据复制到提供的缓冲区中。 As the format of this data isn't readily available/documented, you need to use the helper function VerQueryValue to retrieve pointers to specific entries within the buffer GetFileVersionInfo filled in. 由于该数据的格式没有现成/文档,您需要使用辅助函数VerQueryValue到缓冲区检索指向特定条目GetFileVersionInfo填充。

The way MS documented that "The pointer returned by VerQueryValue isn't allocated from anywhere - it's just pointing to somewhere within another buffer" is somewhat confusing. MS记录的方式“VerQueryValue返回的指针不是从任何地方分配的 - 它只是指向另一个缓冲区中的某个地方”有点令人困惑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM