c++visual-studio-2015fileversioninfo

read FILEVERSION value in code


My dll built in c++ has a .rc file that contains this:

VS_VERSION_INFO VERSIONINFO
 FILEVERSION 1,0,8,7
 PRODUCTVERSION 1,0,8,7

I wish read the FILEVERSION value to log into my code.. how can I do? I read something, but all the posts are relative to read other dll or exe, I need to read my current dll

thanks


Solution

  • Using GetFileVersionInfo() and VerQueryValue() is the safe and official way to read any file's version data. The DLL can get its own path + filename by calling GetModuleFileName() with the HINSTANCE provided to its DllMain() entry point.

    That being said, it is more efficient for the DLL to just read the version data out of its own version resource directly, using (Find|Load|Lock)Resource() instead of GetFileVersionInfo(). However, there are caveats with doing this:

    There are several answers on StackOverflow that explain how to use this approach, and some of them have code snippets, including:

    https://stackoverflow.com/a/48577200/65863

    https://stackoverflow.com/a/13942403/65863