VerQueryValue Function

The VerQueryValue function retrieves specified version information from the specified version-information resource. To retrieve the appropriate resource, before you call VerQueryValue, you must first call the GetFileVersionInfoSize function, and then the GetFileVersionInfo function.

Syntax

BOOL VerQueryValue(      
    LPCVOID pBlock,     LPCTSTR lpSubBlock,     LPVOID *lplpBuffer,     PUINT puLen );

Parameters

pBlock
[in] Pointer to the buffer containing the version-information resource returned by the GetFileVersionInfo function.
lpSubBlock
[in] Pointer to a zero-terminated string specifying which version-information value to retrieve. The string must consist of names separated by backslashes (\) and it must have one of the following forms.
\
Specifies the root block. The function retrieves a pointer to the VS_FIXEDFILEINFO structure for the version-information resource.
\VarFileInfo\Translation
Specifies the translation array in a Var variable information structure—the Value member of this structure. The function retrieves a pointer to this array of language and code page identifiers. An application can use these identifiers to access a language-specific StringTable structure (using the szKey member) in the version-information resource.
\StringFileInfo\lang-codepage\string-name
Specifies a value in a language-specific StringTable structure. The lang-codepage name is a concatenation of a language and code page identifier pair found as a DWORD in the translation array for the resource. Here the lang-codepage name must be specified as a hexadecimal string. The string-name name must be one of the predefined strings described in the following Remarks section. The function retrieves a string value specific to the language and code page indicated.
lplpBuffer
[out] 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.
puLen
[out] When this method returns, contains a pointer to the size of the requested data pointed to by lplpBuffer: for version information values, the length in TCHARs of the string stored at lplpBuffer; for translation array values, the size in bytes of the array stored at lplpBuffer; and for root block, the size in bytes of the structure.

Return Value

If the specified version-information structure exists, and version information is available, the return value is nonzero. If the address of the length buffer is zero, no value is available for the specified version-information name.

If the specified name does not exist or the specified resource is not valid, the return value is zero.

Remarks

Windows NT 3.51 and earlier: The version information functions do not work with 16-bit Windows file images.

Windows 95/98/Me, Windows NT 4.0 and Windows 2000: These functions work on both 16- and 32-bit file images.

Windows XP: These functions works on 16-, 32-, and 64-bit file images.

The following are predefined version information Unicode strings.

CommentsInternalNameProductName
CompanyNameLegalCopyrightProductVersion
FileDescriptionLegalTrademarksPrivateBuild
FileVersionOriginalFilenameSpecialBuild

Example

The following example shows how to enumerate the available version languages and retrieve the FileDescription string-value for each language.

Be sure to call the GetFileVersionInfoSize and GetFileVersionInfo functions before calling VerQueryValue to properly initialize the pBlock buffer.

Windows 95/98/Me: VerQueryValueW is supported by the Microsoft Layer for Unicode. Calling this function a second time for \StringFileInfo\ information will overwrite the information from the first call, so you must save the information if you want to use it later. To use this version, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.

// Structure used to store enumerated languages and code pages.

HRESULT hr;

struct LANGANDCODEPAGE {
  WORD wLanguage;
  WORD wCodePage;
} *lpTranslate;

// Read the list of languages and code pages.

VerQueryValue(pBlock, 
              TEXT("\\VarFileInfo\\Translation"),
              (LPVOID*)&lpTranslate,
              &cbTranslate);

// Read the file description for each language and code page.

for( i=0; i < (cbTranslate/sizeof(struct LANGANDCODEPAGE)); i++ )
{
  hr = StringCchPrintf(SubBlock, 50,
            TEXT("\\StringFileInfo\\%04x%04x\\FileDescription"),
            lpTranslate[i].wLanguage,
            lpTranslate[i].wCodePage);
	if (FAILED(hr))
	{
	// TODO: write error handler.
	}

  // Retrieve file description for language and code page "i". 
  VerQueryValue(pBlock, 
                SubBlock, 
                &lpBuffer, 
                &dwBytes); 
}

Function Information

Minimum DLL Versionversion.dll
HeaderDeclared in Winver.h, include Windows.h
Import libraryVersion.lib
Minimum operating systems Windows 95, Windows NT 3.1
UnicodeImplemented as ANSI and Unicode versions.

See Also

Tags :


Community Content

DrTusk
Text and Example are misleading
This text doesn't indicate whether queries into StringFileInfo will return a NULL-terminated string, nor does it indicate whether pulen includes the trailing NULL or not.
Tags :

Page view tracker