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.

96 lines
2.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1995 - 1999
  6. //
  7. // File: filever.cpp
  8. //
  9. // Contents: Get file version
  10. //
  11. // Functions: I_CryptGetFileVersion
  12. //
  13. // History: 22-Oct-97 philh created
  14. //--------------------------------------------------------------------------
  15. #include "global.hxx"
  16. #include "crypthlp.h"
  17. #include "unicode.h"
  18. #include <dbgdef.h>
  19. //+-------------------------------------------------------------------------
  20. // Get file version of the specified file
  21. //--------------------------------------------------------------------------
  22. BOOL
  23. WINAPI
  24. I_CryptGetFileVersion(
  25. IN LPCWSTR pwszFilename,
  26. OUT DWORD *pdwFileVersionMS, /* e.g. 0x00030075 = "3.75" */
  27. OUT DWORD *pdwFileVersionLS /* e.g. 0x00000031 = "0.31" */
  28. )
  29. {
  30. BOOL fResult;
  31. DWORD dwExceptionCode;
  32. BYTE rgb1[_MAX_PATH];
  33. LPSTR pszFilename = NULL;
  34. DWORD dwHandle = 0;
  35. DWORD cbInfo;
  36. void *pvInfo = NULL;
  37. VS_FIXEDFILEINFO *pFixedFileInfo = NULL; // not allocated
  38. UINT ccFixedFileInfo = 0;
  39. if (!MkMBStr(rgb1, _MAX_PATH, pwszFilename, &pszFilename))
  40. goto OutOfMemory;
  41. // The following APIs are in DELAYLOAD'ed version.dll. If the DELAYLOAD
  42. // fails an exception is raised.
  43. __try {
  44. if (0 == (cbInfo = GetFileVersionInfoSizeA(pszFilename, &dwHandle)))
  45. goto GetFileVersionInfoSizeError;
  46. if (NULL == (pvInfo = malloc(cbInfo)))
  47. goto OutOfMemory;
  48. if (!GetFileVersionInfoA(
  49. pszFilename,
  50. 0, // dwHandle, ignored
  51. cbInfo,
  52. pvInfo
  53. ))
  54. goto GetFileVersionInfoError;
  55. if (!VerQueryValueA(
  56. pvInfo,
  57. "\\", // VS_FIXEDFILEINFO
  58. (void **) &pFixedFileInfo,
  59. &ccFixedFileInfo
  60. ))
  61. goto VerQueryValueError;
  62. } __except(EXCEPTION_EXECUTE_HANDLER) {
  63. dwExceptionCode = GetExceptionCode();
  64. goto GetFileVersionException;
  65. }
  66. *pdwFileVersionMS = pFixedFileInfo->dwFileVersionMS;
  67. *pdwFileVersionLS = pFixedFileInfo->dwFileVersionLS;
  68. fResult = TRUE;
  69. CommonReturn:
  70. FreeMBStr(rgb1, pszFilename);
  71. if (pvInfo)
  72. free(pvInfo);
  73. return fResult;
  74. ErrorReturn:
  75. *pdwFileVersionMS = 0;
  76. *pdwFileVersionLS = 0;
  77. fResult = FALSE;
  78. goto CommonReturn;
  79. TRACE_ERROR(OutOfMemory)
  80. TRACE_ERROR(GetFileVersionInfoSizeError)
  81. TRACE_ERROR(GetFileVersionInfoError)
  82. TRACE_ERROR(VerQueryValueError)
  83. SET_ERROR_VAR(GetFileVersionException, dwExceptionCode)
  84. }