Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
3.9 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: cversion.cpp
  4. //
  5. // Module: CMSETUP.LIB
  6. //
  7. // Synopsis: Implementation of the CVersion class, a utility class that
  8. // wraps up the functionality for detecting the version of a
  9. // given module filename.
  10. //
  11. // Copyright (c) 1998-1999 Microsoft Corporation
  12. //
  13. // Author: quintinb Created Header 08/19/99
  14. //
  15. //+----------------------------------------------------------------------------
  16. #include "cmsetup.h"
  17. #include "getmodulever.cpp"
  18. CVersion::CVersion(LPTSTR szFile)
  19. {
  20. m_bIsPresent = FALSE;
  21. m_szPath[0] = TEXT('\0');
  22. DWORD dwVersion = 0;
  23. DWORD dwBuild = 0;
  24. if ((NULL != szFile) && (TEXT('\0') != szFile[0]))
  25. {
  26. lstrcpy(m_szPath, szFile);
  27. Init();
  28. }
  29. }
  30. CVersion::CVersion()
  31. {
  32. m_bIsPresent = FALSE;
  33. m_szPath[0] = TEXT('\0');
  34. DWORD dwVersion = 0;
  35. DWORD dwBuild = 0;
  36. }
  37. CVersion::~CVersion()
  38. {
  39. // nothing to do really
  40. }
  41. void CVersion::Init()
  42. {
  43. MYDBGASSERT(TEXT('\0') != m_szPath[0]);
  44. //
  45. // Check to see if we have version information
  46. //
  47. HRESULT hr = GetModuleVersionAndLCID(m_szPath, &m_dwVersion, &m_dwBuild, &m_dwLCID);
  48. if (SUCCEEDED(hr))
  49. {
  50. m_bIsPresent = TRUE;
  51. CMTRACE3(TEXT("%s has Version = %u.%u"), m_szPath, (DWORD)HIWORD(m_dwVersion), (DWORD)LOWORD(m_dwVersion));
  52. CMTRACE3(TEXT("%s has Build Number = %u.%u"), m_szPath, (DWORD)HIWORD(m_dwBuild), (DWORD)LOWORD(m_dwBuild));
  53. CMTRACE2(TEXT("%s has LCID = %u"), m_szPath, m_dwLCID);
  54. }
  55. }
  56. BOOL CVersion::IsPresent()
  57. {
  58. return m_bIsPresent;
  59. }
  60. BOOL CVersion::GetVersionString(LPTSTR szStr)
  61. {
  62. if ((NULL != szStr) && (0 != m_dwVersion))
  63. {
  64. MYVERIFY(0 != (UINT)wsprintf(szStr, TEXT("%u.%u"), (DWORD)HIWORD(m_dwVersion),
  65. (DWORD)LOWORD(m_dwVersion)));
  66. return TRUE;
  67. }
  68. return FALSE;
  69. }
  70. BOOL CVersion::GetBuildNumberString(LPTSTR szStr)
  71. {
  72. if ((NULL != szStr) && (0 != m_dwBuild))
  73. {
  74. MYVERIFY(0 != (UINT)wsprintf(szStr, TEXT("%u.%u"), (DWORD)HIWORD(m_dwBuild),
  75. (DWORD)LOWORD(m_dwBuild)));
  76. return TRUE;
  77. }
  78. return FALSE;
  79. }
  80. BOOL CVersion::GetFilePath(LPTSTR szStr)
  81. {
  82. if ((m_bIsPresent) && (TEXT('\0') != m_szPath[0]) && (NULL != szStr))
  83. {
  84. lstrcpy(szStr, m_szPath);
  85. }
  86. return m_bIsPresent;
  87. }
  88. DWORD CVersion::GetVersionNumber()
  89. {
  90. return m_dwVersion;
  91. }
  92. DWORD CVersion::GetBuildAndQfeNumber()
  93. {
  94. return m_dwBuild;
  95. }
  96. DWORD CVersion::GetMajorVersionNumber()
  97. {
  98. return (DWORD)HIWORD(m_dwVersion);
  99. }
  100. DWORD CVersion::GetMinorVersionNumber()
  101. {
  102. return (DWORD)LOWORD(m_dwVersion);
  103. }
  104. DWORD CVersion::GetBuildNumber()
  105. {
  106. return (DWORD)HIWORD(m_dwBuild);
  107. }
  108. DWORD CVersion::GetQfeNumber()
  109. {
  110. return (DWORD)LOWORD(m_dwBuild);
  111. }
  112. DWORD CVersion::GetLCID()
  113. {
  114. return m_dwLCID;
  115. }
  116. // Note the following is a non-class function:
  117. //+----------------------------------------------------------------------------
  118. //
  119. // Function: ArePrimaryLangIDsEqual
  120. //
  121. // Synopsis: Helper routine to compare the Primary Language IDs of two given
  122. // LCIDs.
  123. //
  124. // Arguments: DWORD dwLCID1 - first LCID
  125. // DWORD dwLCID2 - second LCID
  126. //
  127. // Returns: BOOL - TRUE if the LCIDs have the same Primary Language ID
  128. //
  129. // History: quintinb Created 7/8/99
  130. //
  131. //+----------------------------------------------------------------------------
  132. BOOL ArePrimaryLangIDsEqual(DWORD dwLCID1, DWORD dwLCID2)
  133. {
  134. WORD wLangId1 = LANGIDFROMLCID(dwLCID1);
  135. WORD wLangId2 = LANGIDFROMLCID(dwLCID2);
  136. //
  137. // Now Convert the LANG IDs into their respective Primary Lang IDs and compare
  138. //
  139. return (PRIMARYLANGID(wLangId1) == PRIMARYLANGID(wLangId2));
  140. }