namespace Vanara.PInvoke; /// Items from version.dll. public static partial class VersionDll { private const string Lib_Version = "version.dll"; /// Retrieves version information for the specified file. /// /// Type: LPCTSTR /// /// The name of the file. If a full path is not specified, the function uses the search sequence specified by the LoadLibrary function. /// /// /// /// Type: DWORD /// This parameter is ignored. /// /// /// Type: DWORD /// The size, in bytes, of the buffer pointed to by the lpData parameter. /// /// Call the GetFileVersionInfoSize function first to determine the size, in bytes, of a file's version information. The dwLen /// member should be equal to or greater than that value. /// /// /// If the buffer pointed to by lpData is not large enough, the function truncates the file's version information to the size of the buffer. /// /// /// /// Type: LPVOID /// Pointer to a buffer that receives the file-version information. /// You can use this value in a subsequent call to the VerQueryValue function to retrieve data from the buffer. /// /// /// Type: BOOL /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// /// /// /// File version info has fixed and non-fixed part. The fixed part contains information like version number. The non-fixed part /// contains things like strings. In the past GetFileVersionInfo was taking version information from the binary (exe/dll). /// Currently, it is querying fixed version from language neutral file (exe/dll) and the non-fixed part from mui file, merges them /// and returns to the user. If the given binary does not have a mui file then behavior is as in previous version. /// /// /// Call the GetFileVersionInfoSize function before calling the GetFileVersionInfo function. To retrieve information from the /// file-version information buffer, use the VerQueryValue function. /// /// /// Note /// /// The winver.h header defines GetFileVersionInfo as an alias which automatically selects the ANSI or Unicode version of this /// function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that /// not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions /// for Function Prototypes. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/winver/nf-winver-getfileversioninfoa BOOL GetFileVersionInfoA( LPCSTR // lptstrFilename, DWORD dwHandle, DWORD dwLen, LPVOID lpData ); [DllImport(Lib_Version, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winver.h", MSDNShortId = "NF:winver.GetFileVersionInfoA")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetFileVersionInfo([MarshalAs(UnmanagedType.LPTStr)] string lptstrFilename, [Optional] uint dwHandle, uint dwLen, [Out] IntPtr lpData); /// Retrieves version information for the specified file. /// /// Type: DWORD /// /// Controls the MUI DLLs (if any) from which the version resource is extracted. The value of this flag must match the flags passed /// to the corresponding GetFileVersionInfoSizeEx call, which was used to determine the buffer size that is passed in the dwLen /// parameter. Zero or more of the following flags. /// /// /// /// Value /// Meaning /// /// /// FILE_VER_GET_LOCALISED 0x01 /// Loads the entire version resource (both strings and binary version information) from the corresponding MUI file, if available. /// /// /// FILE_VER_GET_NEUTRAL 0x02 /// /// Loads the version resource strings from the corresponding MUI file, if available, and loads the binary version information /// (VS_FIXEDFILEINFO) from the corresponding language-neutral file, if available. /// /// /// /// FILE_VER_GET_PREFETCHED 0x04 /// /// Indicates a preference for version.dll to attempt to preload the image outside of the loader lock to avoid contention. This flag /// does not change the behavior or semantics of the function. /// /// /// /// /// /// Type: LPCTSTR /// /// The name of the file. If a full path is not specified, the function uses the search sequence specified by the LoadLibrary function. /// /// /// /// Type: DWORD /// This parameter is ignored. /// /// /// Type: DWORD /// The size, in bytes, of the buffer pointed to by the lpData parameter. /// /// Call the GetFileVersionInfoSizeEx function first to determine the size, in bytes, of a file's version information. The dwLen /// parameter should be equal to or greater than that value. /// /// /// If the buffer pointed to by lpData is not large enough, the function truncates the file's version information to the size of the buffer. /// /// /// /// Type: LPVOID /// When this function returns, contains a pointer to a buffer that contains the file-version information. /// You can use this value in a subsequent call to the VerQueryValue function to retrieve data from the buffer. /// /// /// Type: BOOL /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// /// /// /// Call the GetFileVersionInfoSizeEx function before calling the GetFileVersionInfoEx function. To retrieve information from /// the file-version information buffer, use the VerQueryValue function. /// /// /// Note /// /// The winver.h header defines GetFileVersionInfoEx as an alias which automatically selects the ANSI or Unicode version of this /// function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that /// not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions /// for Function Prototypes. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/winver/nf-winver-getfileversioninfoexa BOOL GetFileVersionInfoExA( DWORD // dwFlags, LPCSTR lpwstrFilename, DWORD dwHandle, DWORD dwLen, LPVOID lpData ); [DllImport(Lib_Version, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winver.h", MSDNShortId = "NF:winver.GetFileVersionInfoExA")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetFileVersionInfoEx(FILE_VER_GET dwFlags, [MarshalAs(UnmanagedType.LPTStr)] string lpwstrFilename, [Optional] uint dwHandle, uint dwLen, [Out] IntPtr lpData); /// /// Determines whether the operating system can retrieve version information for a specified file. If version information is /// available, GetFileVersionInfoSize returns the size, in bytes, of that information. /// /// /// Type: LPCTSTR /// The name of the file of interest. The function uses the search sequence specified by the LoadLibrary function. /// /// /// Type: LPDWORD /// A pointer to a variable that the function sets to zero. /// /// /// Type: DWORD /// If the function succeeds, the return value is the size, in bytes, of the file's version information. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// /// /// /// Call the GetFileVersionInfoSize function before calling the GetFileVersionInfo function. The size returned by /// GetFileVersionInfoSize indicates the buffer size required for the version information returned by GetFileVersionInfo. /// /// /// Note /// /// The winver.h header defines GetFileVersionInfoSize as an alias which automatically selects the ANSI or Unicode version of this /// function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that /// not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions /// for Function Prototypes. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/winver/nf-winver-getfileversioninfosizea DWORD GetFileVersionInfoSizeA( LPCSTR // lptstrFilename, LPDWORD lpdwHandle ); [DllImport(Lib_Version, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winver.h", MSDNShortId = "NF:winver.GetFileVersionInfoSizeA")] public static extern uint GetFileVersionInfoSize([MarshalAs(UnmanagedType.LPTStr)] string lptstrFilename, out uint lpdwHandle); /// /// Determines whether the operating system can retrieve version information for a specified file. If version information is /// available, GetFileVersionInfoSizeEx returns the size, in bytes, of that information. /// /// /// Type: DWORD /// Controls which MUI DLLs (if any) from which the version resource is extracted. Zero or more of the following flags. /// /// /// Value /// Meaning /// /// /// FILE_VER_GET_LOCALISED 0x01 /// Loads the entire version resource (both strings and binary version information) from the corresponding MUI file, if available. /// /// /// FILE_VER_GET_NEUTRAL 0x002 /// /// Loads the version resource strings from the corresponding MUI file, if available, and loads the binary version information /// (VS_FIXEDFILEINFO) from the corresponding language-neutral file, if available. /// /// /// /// /// /// Type: LPCTSTR /// The name of the file of interest. The function uses the search sequence specified by the LoadLibrary function. /// /// /// Type: LPDWORD /// /// When this function returns, contains a pointer to a variable that is set to zero because this function sets it to zero. This /// parameter exists for historical reasons. /// /// /// /// Type: DWORD /// If the function succeeds, the return value is the size, in bytes, of the file's version information. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// /// /// /// Call the GetFileVersionInfoSizeEx function before calling the GetFileVersionInfoEx function. The size returned by /// GetFileVersionInfoSizeEx indicates the buffer size required for the version information returned by GetFileVersionInfoEx. /// /// /// Note /// /// The winver.h header defines GetFileVersionInfoSizeEx as an alias which automatically selects the ANSI or Unicode version of this /// function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that /// not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions /// for Function Prototypes. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/winver/nf-winver-getfileversioninfosizeexa DWORD GetFileVersionInfoSizeExA( // DWORD dwFlags, LPCSTR lpwstrFilename, LPDWORD lpdwHandle ); [DllImport(Lib_Version, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winver.h", MSDNShortId = "NF:winver.GetFileVersionInfoSizeExA")] public static extern uint GetFileVersionInfoSizeEx(FILE_VER_GET dwFlags, [MarshalAs(UnmanagedType.LPTStr)] string lpwstrFilename, out uint lpdwHandle); /// /// Determines where to install a file based on whether it locates another version of the file in the system. The values /// VerFindFile returns in the specified buffers are used in a subsequent call to the VerInstallFile function. /// /// /// Type: DWORD /// This parameter can be the following value. All other bits are reserved. /// /// /// Value /// Meaning /// /// /// VFFF_ISSHAREDFILE 0x0001 /// /// The source file can be shared by multiple applications. An application can use this information to determine where the file /// should be copied. /// /// /// /// /// /// Type: LPCTSTR /// The name of the file to be installed. Include only the file name and extension, not a path. /// /// /// Type: LPCTSTR /// The directory in which Windows is running or will be run. This string is returned by the GetWindowsDirectory function. /// /// /// Type: LPCTSTR /// /// The directory where the installation program is installing a set of related files. If the installation program is installing an /// application, this is the directory where the application will reside. This parameter also points to the application's current /// directory unless otherwise specified. /// /// /// /// Type: LPWSTR /// /// A buffer that receives the path to a current version of the file being installed. The path is a zero-terminated string. If a /// current version is not installed, the buffer will contain a zero-length string. The buffer should be at least _MAX_PATH /// characters long, although this is not required. /// /// /// /// Type: PUINT /// The length of the szCurDir buffer. This pointer must not be NULL. /// /// When the function returns, lpuCurDirLen contains the size, in characters, of the data returned in szCurDir, including the /// terminating null character. If the buffer is too small to contain all the data, lpuCurDirLen will be the size of the buffer /// required to hold the path. /// /// /// /// Type: LPTSTR /// /// A buffer that receives the path to the installation location recommended by VerFindFile. The path is a zero-terminated /// string. The buffer should be at least _MAX_PATH characters long, although this is not required. /// /// /// /// Type: PUINT /// A pointer to a variable that specifies the length of the szDestDir buffer. This pointer must not be NULL. /// /// When the function returns, lpuDestDirLen contains the size, in characters, of the data returned in szDestDir, including the /// terminating null character. If the buffer is too small to contain all the data, lpuDestDirLen will be the size of the buffer /// needed to hold the path. /// /// /// /// Type: DWORD /// /// The return value is a bitmask that indicates the status of the file. It can be one or more of the following values. All other /// values are reserved. /// /// /// /// Return code/value /// Description /// /// /// VFF_CURNEDEST 0x0001 /// The currently installed version of the file is not in the recommended destination. /// /// /// VFF_FILEINUSE 0x0002 /// The system is using the currently installed version of the file; therefore, the file cannot be overwritten or deleted. /// /// /// VFF_BUFFTOOSMALL 0x0004 /// /// At least one of the buffers was too small to contain the corresponding string. An application should check the output buffers to /// determine which buffer was too small. /// /// /// /// /// /// This function works on 16-, 32-, and 64-bit file images. /// /// VerFindFile searches for a copy of the specified file by using the OpenFile function. However, it determines the system /// directory from the specified Windows directory, or searches the path. /// /// /// If the dwFlags parameter indicates that the file is private to this application (not VFFF_ISSHAREDFILE), /// VerFindFile recommends installing the file in the application's directory. Otherwise, if the system is running a shared /// copy of the system, the function recommends installing the file in the Windows directory. If the system is running a private /// copy of the system, the function recommends installing the file in the system directory. /// /// /// Note /// /// The winver.h header defines VerFindFile as an alias which automatically selects the ANSI or Unicode version of this function /// based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not /// encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for /// Function Prototypes. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/winver/nf-winver-verfindfilea DWORD VerFindFileA( DWORD uFlags, LPCSTR // szFileName, LPCSTR szWinDir, LPCSTR szAppDir, LPSTR szCurDir, PUINT puCurDirLen, LPSTR szDestDir, PUINT puDestDirLen ); [DllImport(Lib_Version, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winver.h", MSDNShortId = "NF:winver.VerFindFileA")] public static extern VFF VerFindFile(VFFF uFlags, [MarshalAs(UnmanagedType.LPTStr)] string szFileName, [Optional, MarshalAs(UnmanagedType.LPTStr)] string? szWinDir, [MarshalAs(UnmanagedType.LPTStr)] string szAppDir, [Out, MarshalAs(UnmanagedType.LPTStr)] StringBuilder szCurDir, ref uint puCurDirLen, [Out, MarshalAs(UnmanagedType.LPTStr)] StringBuilder szDestDir, ref uint puDestDirLen); /// /// Installs the specified file based on information returned from the VerFindFile function. VerInstallFile decompresses the /// file, if necessary, assigns a unique filename, and checks for errors, such as outdated files. /// /// /// Type: DWORD /// This parameter can be one of the following values. All other bits are reserved. /// /// /// Value /// Meaning /// /// /// VIFF_FORCEINSTALL 0x0001 /// Installs the file regardless of mismatched version numbers. The function checks only for physical errors during installation. /// /// /// VIFF_DONTDELETEOLD 0x0002 /// /// Installs the file without deleting the previously installed file, if the previously installed file is not in the destination directory. /// /// /// /// /// /// Type: LPCTSTR /// /// The name of the file to be installed. This is the filename in the directory pointed to by the szSrcDir parameter; the filename /// can include only the filename and extension, not a path. /// /// /// /// Type: LPCTSTR /// /// The name VerInstallFile will give the new file upon installation. This file name may be different from the filename in /// the szSrcFileName directory. The new name should include only the file name and extension, not a path. /// /// /// /// Type: LPCTSTR /// The name of the directory where the file can be found. /// /// /// Type: LPCTSTR /// The name of the directory where the file should be installed. VerFindFile returns this value in its szDestDir parameter. /// /// /// Type: LPCTSTR /// /// The name of the directory where a preexisting version of this file can be found. VerFindFile returns this value in its szCurDir parameter. /// /// /// /// Type: LPTSTR /// /// The name of a temporary copy of the source file. The buffer should be at least _MAX_PATH characters long, although this /// is not required, and should be empty on input. /// /// /// /// Type: PUINT /// The length of the szTmpFile buffer. This pointer must not be NULL. /// /// When the function returns, lpuTmpFileLen receives the size, in characters, of the data returned in szTmpFile, including the /// terminating null character. If the buffer is too small to contain all the data, lpuTmpFileLen will be the size of the buffer /// required to hold the data. /// /// /// /// Type: DWORD /// /// The return value is a bitmask that indicates exceptions. It can be one or more of the following values. All other values are reserved. /// /// /// /// Return code/value /// Description /// /// /// VIF_ACCESSVIOLATION 0x00000200L /// A read, create, delete, or rename operation failed due to an access violation. /// /// /// VIF_BUFFTOOSMALL 0x00040000L /// /// The szTmpFile buffer was too small to contain the name of the temporary source file. When the function returns, lpuTmpFileLen /// contains the size of the buffer required to hold the filename. /// /// /// /// VIF_CANNOTCREATE 0x00000800L /// The function cannot create the temporary file. The specific error may be described by another flag. /// /// /// VIF_CANNOTDELETE 0x00001000L /// /// The function cannot delete the destination file, or cannot delete the existing version of the file located in another directory. /// If the VIF_TEMPFILE bit is set, the installation failed, and the destination file probably cannot be deleted. /// /// /// /// VIF_CANNOTDELETECUR 0x00004000L /// The existing version of the file could not be deleted and VIFF_DONTDELETEOLD was not specified. /// /// /// VIF_CANNOTLOADCABINET 0x00100000L /// The function cannot load the cabinet file. /// /// /// VIF_CANNOTLOADLZ32 0x00080000L /// The function cannot load the compressed file. /// /// /// VIF_CANNOTREADDST 0x00020000L /// The function cannot read the destination (existing) files. This prevents the function from examining the file's attributes. /// /// /// VIF_CANNOTREADSRC 0x00010000L /// The function cannot read the source file. This could mean that the path was not specified properly. /// /// /// VIF_CANNOTRENAME 0x00002000L /// The function cannot rename the temporary file, but already deleted the destination file. /// /// /// VIF_DIFFCODEPG 0x00000010L /// /// The new file requires a code page that cannot be displayed by the version of the system currently running. This error can be /// overridden by calling VerInstallFile with the VIFF_FORCEINSTALL flag set. /// /// /// /// VIF_DIFFLANG 0x00000008L /// /// The new and preexisting files have different language or code-page values. This error can be overridden by calling /// VerInstallFile again with the VIFF_FORCEINSTALL flag set. /// /// /// /// VIF_DIFFTYPE 0x00000020L /// /// The new file has a different type, subtype, or operating system from the preexisting file. This error can be overridden by /// calling VerInstallFile again with the VIFF_FORCEINSTALL flag set. /// /// /// /// VIF_FILEINUSE 0x00000080L /// The preexisting file is in use by the system and cannot be deleted. /// /// /// VIF_MISMATCH 0x00000002L /// /// The new and preexisting files differ in one or more attributes. This error can be overridden by calling VerInstallFile again /// with the VIFF_FORCEINSTALL flag set. /// /// /// /// VIF_OUTOFMEMORY 0x00008000L /// /// The function cannot complete the requested operation due to insufficient memory. Generally, this means the application ran out /// of memory attempting to expand a compressed file. /// /// /// /// VIF_OUTOFSPACE 0x00000100L /// The function cannot create the temporary file due to insufficient disk space on the destination drive. /// /// /// VIF_SHARINGVIOLATION 0x00000400L /// A read, create, delete, or rename operation failed due to a sharing violation. /// /// /// VIF_SRCOLD 0x00000004L /// /// The file to install is older than the preexisting file. This error can be overridden by calling VerInstallFile again with the /// VIFF_FORCEINSTALL flag set. /// /// /// /// VIF_TEMPFILE 0x00000001L /// The temporary copy of the new file is in the destination directory. The cause of failure is reflected in other flags. /// /// /// VIF_WRITEPROT 0x00000040L /// /// The preexisting file is write-protected. This error can be overridden by calling VerInstallFile again with the VIFF_FORCEINSTALL /// flag set. /// /// /// /// /// /// This function works on 16-, 32-, and 64-bit file images. /// /// VerInstallFile copies the file from the source directory to the destination directory. If szCurDir indicates that a /// previous version of the file exists on the system, VerInstallFile compares the files' version stamp information. If the /// previously installed version of the file is more recent than the new version, or if the files' attributes are significantly /// different, for example, if they are in different languages, then VerInstallFile returns with one or more recoverable /// error codes. /// /// /// VerInstallFile leaves the temporary file in the destination directory. The application can either override the error or /// delete the temporary file. If the application overrides the error, VerInstallFile deletes the previously installed /// version and renames the temporary file with the original filename. /// /// /// Note /// /// The winver.h header defines VerInstallFile as an alias which automatically selects the ANSI or Unicode version of this function /// based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not /// encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for /// Function Prototypes. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/winver/nf-winver-verinstallfilea DWORD VerInstallFileA( DWORD uFlags, LPCSTR // szSrcFileName, LPCSTR szDestFileName, LPCSTR szSrcDir, LPCSTR szDestDir, LPCSTR szCurDir, LPSTR szTmpFile, PUINT puTmpFileLen ); [DllImport(Lib_Version, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winver.h", MSDNShortId = "NF:winver.VerInstallFileA")] public static extern VIF VerInstallFile(VIFF uFlags, [MarshalAs(UnmanagedType.LPTStr)] string szSrcFileName, [MarshalAs(UnmanagedType.LPTStr)] string szDestFileName, [MarshalAs(UnmanagedType.LPTStr)] string szSrcDir, [MarshalAs(UnmanagedType.LPTStr)] string szDestDir, [MarshalAs(UnmanagedType.LPTStr)] string szCurDir, [Out, MarshalAs(UnmanagedType.LPTStr)] StringBuilder szTmpFile, ref uint puTmpFileLen); /// Retrieves a description string for the language associated with a specified binary Microsoft language identifier. /// /// Type: DWORD /// The binary language identifier. For a complete list of the language identifiers, see Language Identifiers. /// /// For example, the description string associated with the language identifier 0x040A is "Spanish (Traditional Sort)". If the /// identifier is unknown, the szLang parameter points to a default string ("Language Neutral"). /// /// /// /// Type: LPTSTR /// The language specified by the wLang parameter. /// /// /// Type: DWORD /// The size, in characters, of the buffer pointed to by szLang. /// /// /// Type: DWORD /// /// The return value is the size, in characters, of the string returned in the buffer. This value does not include the terminating /// null character. If the description string is smaller than or equal to the buffer, the entire description string is in the /// buffer. If the description string is larger than the buffer, the description string is truncated to the length of the buffer. /// /// If an error occurs, the return value is zero. Unknown language identifiers do not produce errors. /// /// /// This function works on 16-, 32-, and 64-bit file images. /// /// Typically, an installation program uses this function to translate a language identifier returned by the VerQueryValue function. /// The text string may be used in a dialog box that asks the user how to proceed in the event of a language conflict. /// /// /// Note /// /// The winver.h header defines VerLanguageName as an alias which automatically selects the ANSI or Unicode version of this function /// based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not /// encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for /// Function Prototypes. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/winver/nf-winver-verlanguagenamea DWORD VerLanguageNameA( DWORD wLang, LPSTR // szLang, DWORD cchLang ); [DllImport(Lib_Version, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winver.h", MSDNShortId = "NF:winver.VerLanguageNameA")] public static extern uint VerLanguageName(uint wLang, [Out, MarshalAs(UnmanagedType.LPTStr)] StringBuilder szLang, uint cchLang); /// /// 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. /// /// /// Type: LPCVOID /// The version-information resource returned by the GetFileVersionInfo function. /// /// /// Type: LPCTSTR /// /// The version-information value to be retrieved. The string must consist of names separated by backslashes (\) and it must have /// one of the following forms. /// /// \ /// The root block. The function retrieves a pointer to the VS_FIXEDFILEINFO structure for the version-information resource. /// \VarFileInfo\Translation /// /// 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 /// /// 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. /// /// /// /// Type: 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. /// /// /// /// Type: PUINT /// /// 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 characters 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. /// /// /// /// Type: BOOL /// /// 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. /// /// /// This function works on 16-, 32-, and 64-bit file images. /// The following are predefined version information Unicode strings. /// /// /// Comments /// InternalName /// ProductName /// /// /// CompanyName /// LegalCopyright /// ProductVersion /// /// /// FileDescription /// LegalTrademarks /// PrivateBuild /// /// /// FileVersion /// OriginalFilename /// SpecialBuild /// /// /// Examples /// /// 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. /// /// /// // 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); } /// /// /// Note /// /// The winver.h header defines VerQueryValue as an alias which automatically selects the ANSI or Unicode version of this function /// based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not /// encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for /// Function Prototypes. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/winver/nf-winver-verqueryvaluea BOOL VerQueryValueA( LPCVOID pBlock, LPCSTR // lpSubBlock, LPVOID *lplpBuffer, PUINT puLen ); [DllImport(Lib_Version, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winver.h", MSDNShortId = "NF:winver.VerQueryValueA")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool VerQueryValue(IntPtr pBlock, [MarshalAs(UnmanagedType.LPTStr)] string lpSubBlock, out IntPtr lplpBuffer, out uint puLen); }