In the realm of software development, it often becomes necessary to retrieve the version information associated with dynamic link libraries (DLLs) and executable programs (EXEs). By utilizing Win32 native APIs accessible through C or C , developers can seamlessly acquire the product and file versions of these executable entities.
The key to unlocking version information lies in the GetFileVersionInfo API. This powerful function populates a buffer with data pertaining to the specified DLL or EXE file. Let us delve into the intricacies of its usage:
The following code sample illustrates the practical application of the GetFileVersionInfo API:
DWORD verHandle = 0;
UINT size = 0;
LPBYTE lpBuffer = NULL;
DWORD verSize = GetFileVersionInfoSize(szVersionFile, &verHandle);
if (verSize != NULL) {
LPSTR verData = new char[verSize];
if (GetFileVersionInfo(szVersionFile, verHandle, verSize, verData)) {
if (VerQueryValue(verData, "\\", (VOID FAR * FAR *)&lpBuffer, &size)) {
if (size) {
VS_FIXEDFILEINFO *verInfo = (VS_FIXEDFILEINFO *)lpBuffer;
if (verInfo->dwSignature == 0xfeef04bd) {
// Parse the file version into a four-part dotted string
TRACE("File Version: %d.%d.%d.%d\n",
(verInfo->dwFileVersionMS >> 16) & 0xffff,
(verInfo->dwFileVersionMS >> 0) & 0xffff,
(verInfo->dwFileVersionLS >> 16) & 0xffff,
(verInfo->dwFileVersionLS >> 0) & 0xffff
);
}
}
}
}
delete[] verData;
}
In conclusion, the GetFileVersionInfo API provides a comprehensive solution for programmatically obtaining version information from DLLs and EXEs. By tapping into this functionality, developers can automate version retrieval tasks, ensuring accuracy and efficiency in their software development endeavors.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3