Get Application Version from Resources

David Aaronson 21 Reputation points
2022-01-19T15:03:34.22+00:00

Hi everybody!

I need to display my WinAPI application name and version on the main window.

Like: MyApp 1.2.3.0

Now I just saving this info in the cpp file and also in the VS_VERSION resource. I was thinking if only I could save it in one place? Maybe I could do some defines that will extract the info from resources? I saw similar questions here but no clear answer. Thanks.

Best regards,
David

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,417 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,525 questions
0 comments No comments
{count} votes

Accepted answer
  1. Artemiy Moroz 271 Reputation points
    2022-01-19T15:24:07.74+00:00

    Hi
    As @David Lowndes mentioned here, to query the version from a resource one should use VerQueryValue API.
    But unfortunately, this API does not support resource IDs directly, moreover, it does modifications to loaded resource's memory. So one should load the resource with LoadResource and then copy it to writable memory. I found a code sample for this: Retrieve the application version from its own resources

    Hope this helps.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. David Lowndes 4,711 Reputation points
    2022-01-19T15:09:22.34+00:00

    The key API to use to get a string from the version resource is VerQueryValue

    0 comments No comments