version.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "putty.h"
  2. DWORD osMajorVersion, osMinorVersion, osPlatformId;
  3. void init_winver(void)
  4. {
  5. static bool initialised = false;
  6. if (initialised)
  7. return;
  8. initialised = true;
  9. OSVERSIONINFO osVersion;
  10. static HMODULE kernel32_module;
  11. DECL_WINDOWS_FUNCTION(static, BOOL, GetVersionExA, (LPOSVERSIONINFO));
  12. if (!kernel32_module) {
  13. kernel32_module = load_system32_dll("kernel32.dll");
  14. /* Deliberately don't type-check this function, because that
  15. * would involve using its declaration in a header file which
  16. * triggers a deprecation warning. I know it's deprecated (see
  17. * below) and don't need telling. */
  18. GET_WINDOWS_FUNCTION_NO_TYPECHECK(kernel32_module, GetVersionExA);
  19. }
  20. ZeroMemory(&osVersion, sizeof(osVersion));
  21. osVersion.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
  22. if (p_GetVersionExA && p_GetVersionExA(&osVersion)) {
  23. osMajorVersion = osVersion.dwMajorVersion;
  24. osMinorVersion = osVersion.dwMinorVersion;
  25. osPlatformId = osVersion.dwPlatformId;
  26. } else {
  27. /*
  28. * GetVersionEx is deprecated, so allow for it perhaps going
  29. * away in future API versions. If it's not there, simply
  30. * assume that's because Windows is too _new_, so fill in the
  31. * variables we care about to a value that will always compare
  32. * higher than any given test threshold.
  33. *
  34. * Normally we should be checking against the presence of a
  35. * specific function if possible in any case.
  36. */
  37. osMajorVersion = osMinorVersion = UINT_MAX; /* a very high number */
  38. osPlatformId = VER_PLATFORM_WIN32_NT; /* not Win32s or Win95-like */
  39. }
  40. }