了解 VerQueryValue [英] Understanding VerQueryValue
问题描述
在 MSDN 上,我注意到 VerQueryValue 函数的以下内容:
On MSDN I noticed the following for the VerQueryValue function:
lplpBuffer [输出]
LPVOID
当此方法返回时,包含指向 pBlock 指向的缓冲区中所请求版本信息的指针的地址.lplpBuffer 指向的内存在相关 pBlock 内存被释放时被释放._
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._
既然 pBlock 是由调用者分配的,系统如何知道 pBlock 何时被释放?
How does the system know when pBlock is freed since pBlock is allocated by the caller?
我正在使用以下代码:
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 转换等所需的任何空间)
VerQueryValue returns a pointer to somewhere inside the initial block of memory that you allocate (GetFileVersionInfoSize returns the size of a block that is large enough to contain the whole version resource + any space required for ansi to unicode conversion etc)
这篇关于了解 VerQueryValue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!