Source code of Windows XP (NT5)
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.

129 lines
3.0 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000
  5. //
  6. // File: verread.cpp
  7. //
  8. // Contents: code for reading version info for app matching
  9. //
  10. // History: 24-Feb-00 dmunsil created
  11. //
  12. //---------------------------------------------------------------------------
  13. #include "stdafx.h"
  14. #include "stdio.h"
  15. #include "assert.h"
  16. #include "verread.h"
  17. BOOL bInitVersionData(TCHAR *szPath, PVERSION_DATA pVersionData)
  18. {
  19. UINT unSize = 0;
  20. DWORD dwNull = 0;
  21. assert(szPath && pVersionData);
  22. ZeroMemory(pVersionData, sizeof(VERSION_DATA));
  23. pVersionData->dwBufferSize = GetFileVersionInfoSize(szPath, &dwNull);
  24. if (!pVersionData->dwBufferSize) {
  25. goto err;
  26. }
  27. pVersionData->pBuffer = new BYTE[pVersionData->dwBufferSize];
  28. if (!pVersionData->pBuffer) {
  29. goto err;
  30. }
  31. if (!GetFileVersionInfo(szPath, 0, pVersionData->dwBufferSize, pVersionData->pBuffer)) {
  32. goto err;
  33. }
  34. if (!VerQueryValue(pVersionData->pBuffer, TEXT("\\"), (PVOID*)&pVersionData->pFixedInfo, &unSize)) {
  35. goto err;
  36. }
  37. return TRUE;
  38. err:
  39. if (pVersionData->pBuffer) {
  40. delete [] pVersionData->pBuffer;
  41. ZeroMemory(pVersionData, sizeof(VERSION_DATA));
  42. }
  43. return FALSE;
  44. }
  45. /*--
  46. Search order is:
  47. - Language neutral, Unicode (0x000004B0)
  48. - Language neutral, Windows-multilingual (0x000004e4)
  49. - US English, Unicode (0x040904B0)
  50. - US English, Windows-multilingual (0x040904E4)
  51. If none of those exist, it's not likely we're going to get good
  52. matching info from what does exist.
  53. --*/
  54. TCHAR *szGetVersionString(PVERSION_DATA pVersionData, TCHAR *szString)
  55. {
  56. TCHAR szTemp[100] = "";
  57. TCHAR *szReturn = NULL;
  58. static DWORD adwLangs[] = {0x000004B0, 0x000004E4, 0x040904B0, 0x040904E4, 0};
  59. int i;
  60. assert(pVersionData && szString);
  61. for (i = 0; adwLangs[i]; ++i) {
  62. UINT unLen;
  63. _stprintf(szTemp, TEXT("\\StringFileInfo\\%08X\\%s"), adwLangs[i], szString);
  64. if (VerQueryValue(pVersionData->pBuffer, szTemp, (PVOID*)&szReturn, &unLen)) {
  65. goto out;
  66. }
  67. }
  68. out:
  69. return szReturn;
  70. }
  71. ULONGLONG qwGetBinFileVer(PVERSION_DATA pVersionData)
  72. {
  73. LARGE_INTEGER liReturn;
  74. assert(pVersionData);
  75. liReturn.LowPart = pVersionData->pFixedInfo->dwFileVersionLS;
  76. liReturn.HighPart = pVersionData->pFixedInfo->dwFileVersionMS;
  77. return liReturn.QuadPart;
  78. }
  79. ULONGLONG qwGetBinProdVer(PVERSION_DATA pVersionData)
  80. {
  81. LARGE_INTEGER liReturn;
  82. assert(pVersionData);
  83. liReturn.LowPart = pVersionData->pFixedInfo->dwProductVersionLS;
  84. liReturn.HighPart = pVersionData->pFixedInfo->dwProductVersionMS;
  85. return liReturn.QuadPart;
  86. }
  87. void vReleaseVersionData(PVERSION_DATA pVersionData)
  88. {
  89. assert(pVersionData);
  90. if (pVersionData->pBuffer) {
  91. delete [] pVersionData->pBuffer;
  92. ZeroMemory(pVersionData, sizeof(VERSION_DATA));
  93. }
  94. }