36

I just included this bit in my already working code, but I am getting an LNK2019 error. I'll paste the error after pasting the code.

The Class CAboutDlg has:

public:

    CStatic m_VersionInfoCtrl;

   virtual BOOL OnInitDialog();

};

The Function itself:

BOOL CAboutDlg::OnInitDialog()

{

   CDialog::OnInitDialog();

   CString inFileName = AfxGetApp()->m_pszExeName;

   inFileName += ".exe";

   void * theVersionInfo;

   void * theFixedInfo;

   unsigned long aVersionInfoSize = GetFileVersionInfoSize ( inFileName , &aVersionInfoSize);

   CString returnString;

   if (aVersionInfoSize)

   {

   theVersionInfo = new char [aVersionInfoSize];

   GetFileVersionInfo ( inFileName, 0 , aVersionInfoSize, theVersionInfo) ;

   unsigned int aSize = 0;

   VerQueryValue( theVersionInfo , "\\" , &theFixedInfo , &aSize);

   if (theFixedInfo)

   {

   VS_FIXEDFILEINFO * aInfo = (VS_FIXEDFILEINFO *) theFixedInfo;

   DWORD dwMajorVersionMsb = HIWORD( aInfo->dwFileVersionMS );

   DWORD dwMajorVersionLsb = LOWORD( aInfo->dwFileVersionMS ); 

   DWORD dwMinorVersionMsb = HIWORD( aInfo->dwFileVersionLS );

   DWORD dwMinorVersionLsb = LOWORD( aInfo->dwFileVersionLS ); 



  returnString.Format("Version %d . %d . %d. %d",dwMajorVersionMsb,dwMajorVersionLsb,dwMinorVersionMsb,dwMinorVersionLsb);

  //memcpy(sVer,returnString.GetBuffer(),returnString.GetLength()+1);

  }

delete theVersionInfo;

   }

   m_VersionInfoCtrl.SetWindowText(returnString);

   return TRUE;  // return TRUE unless you set the focus to a control

   // EXCEPTION: OCX Property Pages should return FALSE

}

....

Its giving me the following three errors:

1.RangemasterGenerator error LNK2019: unresolved external symbol _VerQueryValueA@16 referenced in function "public: virtual int __thiscall CAboutDlg::OnInitDialog(void)" (?OnInitDialog@CAboutDlg@@UAEHXZ)

2.RangemasterGenerator error LNK2019: unresolved external symbol _GetFileVersionInfoA@16 referenced in function "public: virtual int __thiscall CAboutDlg::OnInitDialog(void)" (?OnInitDialog@CAboutDlg@@UAEHXZ)
3.RangemasterGenerator error LNK2019: unresolved external symbol _GetFileVersionInfoSizeA@8 referenced in function "public: virtual int __thiscall CAboutDlg::OnInitDialog(void)" (?OnInitDialog@CAboutDlg@@UAEHXZ)

... I am not able to understand what the problem is. Can anyone help please. Thanks.

juergen d
  • 201,996
  • 37
  • 293
  • 362
Neophile
  • 5,660
  • 14
  • 61
  • 107

4 Answers4

62

You need to link against the library that contains the two functions VerQueryValue and GetFileVersionInfo - the linker doesn't know by default where to find them.

A quick search for the two functions on MSDN suggests that they're both in the system library version.dll and the library you want to link against is version.lib. Just add that to the library list in the linker properties.

Top-Master
  • 7,611
  • 5
  • 39
  • 71
Timo Geusch
  • 24,095
  • 5
  • 52
  • 70
9

The functions GetFileVersionInfo and GetFileVersionInfoSize are defined in Version.dll and Version.lib so make sure, you are liking to the appropriate libraries.

Alok Save
  • 202,538
  • 53
  • 430
  • 533
  • 1
    Actually a CStatic is a specific kind of MFC control, not a static member. See here: http://msdn.microsoft.com/en-us/library/t98kd6f7%28v=vs.80%29.aspx – Timo Geusch Aug 11 '11 at 15:15
  • @Timo: Ahh, corrected, that was a blinder & someone up voted it! ;-) – Alok Save Aug 11 '11 at 15:19
  • Wait, but following the provided links I see that those functions are in `mincore.lib`. And you are right, they are in version.lib . What is wrong? – Ivan P. May 16 '18 at 06:09
6

For VS2012 or 2013 add to Project Properties->Linker->Input->Additional Dependencies -> Add Version.lib

AirCal86
  • 126
  • 2
  • 9
  • This is all that I needed to do. No need to worry about the dll, or the full path to the file,etc. – BuvinJ Dec 16 '16 at 21:37
5

I am also getting same error, while upgrading the VS6.0 application to VS2012 platform.

a. error LNK2019: unresolved external symbol _GetFileVersionInfoSizeA@8 referenced in function _main

b. error LNK2019: unresolved external symbol _GetFileVersionInfoA@16 referenced in function _main

c. error LNK2019: unresolved external symbol _VerQueryValueA@16 referenced in function _main

Resolution:

I found that it is due to missing reference to library "Version.lib".

a. For VS6.0 add it to Project Setting->Link->library modules

b. For VS2012 add to Project Properties->Linker->Input->Additional Dependancies and add full lib path to Include directory.

Mahendra
  • 51
  • 1
  • 1