verinfo.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //-----------------------------------------------------------------------------
  2. // @doc
  3. //
  4. // @module VERINFO.CPP - VersionInfo object implementation |
  5. //
  6. // This is the implementation of the VersionInfo object, which handles the
  7. // extraction of version information about a module in a class that can be
  8. // used in a generic array. This provides one mechanism by which we can collect
  9. // version information from dependent modules to be displayed in the about box,
  10. // for example.
  11. //
  12. // Copyright <cp> 1995 Microsoft Corporation, All Rights Reserved
  13. //
  14. // Mark Snyder, Software Design Engineer
  15. // Microsoft Travel Products
  16. //
  17. #include "stdafx.h"
  18. #include "verinfo.h"
  19. VersionInfo::VersionInfo()
  20. {
  21. Initialize();
  22. }
  23. VersionInfo::VersionInfo(char* pszFileName)
  24. {
  25. Initialize();
  26. if (pszFileName==NULL)
  27. return;
  28. DWORD dwBogus;
  29. DWORD cbVer = GetFileVersionInfoSize(pszFileName, &dwBogus);
  30. if (!cbVer)
  31. return;
  32. BYTE* pbVer = new BYTE[cbVer];
  33. if (!pbVer)
  34. return;
  35. if (!GetFileVersionInfo(pszFileName, 0, cbVer, pbVer))
  36. {
  37. delete [] pbVer;
  38. return;
  39. }
  40. PVOID pvValue;
  41. UINT cbValue;
  42. if (VerQueryValue(pbVer, TEXT("\\"), &pvValue, &cbValue) && pvValue!=NULL)
  43. {
  44. m_dwVersionMS = ((VS_FIXEDFILEINFO*)pvValue)->dwProductVersionMS;
  45. m_dwVersionLS = ((VS_FIXEDFILEINFO*)pvValue)->dwProductVersionLS;
  46. m_dwFileFlags = ((VS_FIXEDFILEINFO*)pvValue)->dwFileFlagsMask
  47. & ((VS_FIXEDFILEINFO*)pvValue)->dwFileFlags;
  48. }
  49. if (VerQueryValue(pbVer, TEXT("\\StringFileInfo\\040904b0\\ProductName"), &pvValue, &cbValue))
  50. memcpy(m_szProductName, pvValue, min(cbValue, sizeof(m_szProductName)-1));
  51. if (VerQueryValue(pbVer, TEXT("\\StringFileInfo\\040904b0\\ProductVersion"), &pvValue, &cbValue))
  52. memcpy(m_szProductVersion, pvValue, min(cbValue, sizeof(m_szProductVersion)-1));
  53. if (VerQueryValue(pbVer, TEXT("\\StringFileInfo\\040904b0\\BuildFlavor"), &pvValue, &cbValue))
  54. memcpy(m_szBuildFlavor, pvValue, min(cbValue, sizeof(m_szBuildFlavor)-1));
  55. delete [] pbVer;
  56. }
  57. void VersionInfo::Initialize()
  58. {
  59. memset(m_szProductName, 0x00, sizeof(m_szProductName));
  60. memset(m_szProductVersion, 0x00, sizeof(m_szProductVersion));
  61. memset(m_szBuildFlavor, 0x00, sizeof(m_szBuildFlavor));
  62. m_dwVersionMS = 0;
  63. m_dwVersionLS = 0;
  64. m_dwFileFlags = 0;
  65. }