Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error LNK2019 when using GetFileVersionInfoSize()

Tags:

c++

mfc

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.

like image 816
Neophile Avatar asked Aug 11 '11 15:08

Neophile


3 Answers

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.

like image 123
Timo Geusch Avatar answered Oct 05 '22 23:10

Timo Geusch


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

like image 22
Alok Save Avatar answered Oct 05 '22 23:10

Alok Save


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

like image 38
AirCal86 Avatar answered Oct 05 '22 23:10

AirCal86