Home > Backend Development > C++ > How to Programmatically Get the Version of a DLL or EXE File in C/C ?

How to Programmatically Get the Version of a DLL or EXE File in C/C ?

Susan Sarandon
Release: 2024-10-30 19:57:02
Original
1035 people have browsed it

How to Programmatically Get the Version of a DLL or EXE File in C/C  ?

How to Get the Version of a DLL or EXE File Programmatically

Obtaining the product and file versions of a DLL or EXE file is a crucial aspect of software development. To accomplish this in C or C using Win32 native APIs, follow these steps:

  1. Utilize the GetFileVersionInfo API:

    This function provides access to version information associated with the specified file.

  2. Example Implementation:

    The following code demonstrates how to use the GetFileVersionInfo API to retrieve the version numbers:

    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)
                    {
                        // DWORD is always 32 bits, so first two revision numbers
                        // come from dwFileVersionMS, last two come from dwFileVersionLS
                        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;
    }
    Copy after login

By leveraging the GetFileVersionInfo API, you can effectively retrieve the version information of DLL or EXE files, enabling you to perform version checking and other related tasks.

The above is the detailed content of How to Programmatically Get the Version of a DLL or EXE File in C/C ?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template