Actually is not as easy as it looks. Unless you really need to retrieve localized version info size, use GetFileVersionInfoSize instead GetFileVersionInfoSizeEx. GetFileVersionInfoSize is available starting with Windows 2000. You do not have to call LoadLibrary and GetProcAddress since your module (exe) is linked implicitly with Version.lib. To write robust code you would have to write more than simple GetProcAddress. If you really want to use both, depending on the operating system, you will have to retrieve proc address depending on OS version and load appropriate procedure address, since Version.lib contains both: ASCII and UNICODE versions of the functions. If your app is built as ANSII you would have to use ANSI version of the function: GetFileVersionInfoSizeExW or GetFileVersionInfoSizeW depending on what system your app is running on. For unicode build you will have to explicitly request UNICODE versions: GetFileVersionInfoSizeExW or GetFileVersionInfoSizeA. Something like this:
//#define _USE_EXPLICIT
void GetFileVersionLenInfo()
{
OSVERSIONINFO osvi = {sizeof(OSVERSIONINFO)};
DWORD dwHandle = 8000;
DWORD dwVer = 0;
GetVersionEx(&osvi);
HINSTANCE hInst = NULL;
#ifdef _USE_EXPLICIT
typedef DWORD (CALLBACK\* lpfnGETFILEVERSIONINFOSIZEEX)(DWORD, LPCTSTR, LPDWORD);
typedef DWORD (CALLBACK\* lpfnGETFILEVERSIONINFOSIZE)(LPCTSTR, LPDWORD);
//typedef UINT (CALLBACK\* LPFNDLLFUNC1)(DWORD,UINT);
hInst = LoadLibrary(\_T("VERSION.dll"));
if(osvi.dwMajorVersion > 5)
{
#ifdef UNICODE
lpfnGETFILEVERSIONINFOSIZEEX lpfnGetFileVersionInfoSizeEx = (lpfnGETFILEVERSIONINFOSIZEEX)GetProcAddress(hInst, "GetFileVersionInfoSizeExW");
#else
lpfnGETFILEVERSIONINFOSIZEEX lpfnGetFileVersionInfoSizeEx = (lpfnGETFILEVERSIONINFOSIZEEX)GetProcAddress(hInst, "GetFileVersionInfoSizeExA");
#endif // UNICODE
dwVer = lpfnGetFileVersionInfoSizeEx(FILE\_VER\_GET\_NEUTRAL,
\_T("C:\\\\Program Files\\\\Beyond Compare 2\\\\BC2.exe"),
&dwHandle);
return;
}
#ifdef UNICODE
lpfnGETFILEVERSIONINFOSIZE lpfnGetFileVersionInfoSize = (lpfnGETFILEVERSIONINFOSIZE)GetProcAddress(hInst, "GetFileVersionInfoSizeW");
#else
lpfnGETFILEVERSIONINFOSIZE lpfnGetFileVersionInfoSize = (lpfnGETFILEVERSIONINFOSIZE)GetProcAddress(hInst, "GetFileVersionInfoSizeA");
#endif // UNICODE
dwVer = lpfnGetFileVersionInfoSize(
_T("C:\\Program Files\\Beyond Compare 2\\BC2.exe"),
&dwHandle);
#else
dwVer = GetFileVersionInfoSize(
_T("C:\\Program Files\\Beyond Compare 2\\BC22.exe"),