win32.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright 2004 The WebRTC Project Authors. All rights reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef RTC_BASE_WIN32_H_
  11. #define RTC_BASE_WIN32_H_
  12. #ifndef WEBRTC_WIN
  13. #error "Only #include this header in Windows builds"
  14. #endif
  15. // Make sure we don't get min/max macros
  16. #ifndef NOMINMAX
  17. #define NOMINMAX
  18. #endif
  19. // clang-format off
  20. // clang formating would change include order.
  21. #include <winsock2.h> // must come first
  22. #include <windows.h>
  23. // clang-format on
  24. typedef int socklen_t;
  25. #ifndef SECURITY_MANDATORY_LABEL_AUTHORITY
  26. // Add defines that we use if we are compiling against older sdks
  27. #define SECURITY_MANDATORY_MEDIUM_RID (0x00002000L)
  28. #define TokenIntegrityLevel static_cast<TOKEN_INFORMATION_CLASS>(0x19)
  29. typedef struct _TOKEN_MANDATORY_LABEL {
  30. SID_AND_ATTRIBUTES Label;
  31. } TOKEN_MANDATORY_LABEL, *PTOKEN_MANDATORY_LABEL;
  32. #endif // SECURITY_MANDATORY_LABEL_AUTHORITY
  33. #undef SetPort
  34. #include <string>
  35. namespace rtc {
  36. const char* win32_inet_ntop(int af, const void* src, char* dst, socklen_t size);
  37. int win32_inet_pton(int af, const char* src, void* dst);
  38. enum WindowsMajorVersions {
  39. kWindows2000 = 5,
  40. kWindowsVista = 6,
  41. kWindows10 = 10,
  42. };
  43. #if !defined(WINUWP)
  44. bool GetOsVersion(int* major, int* minor, int* build);
  45. inline bool IsWindowsVistaOrLater() {
  46. int major;
  47. return (GetOsVersion(&major, nullptr, nullptr) && major >= kWindowsVista);
  48. }
  49. inline bool IsWindowsXpOrLater() {
  50. int major, minor;
  51. return (GetOsVersion(&major, &minor, nullptr) &&
  52. (major >= kWindowsVista || (major == kWindows2000 && minor >= 1)));
  53. }
  54. inline bool IsWindows8OrLater() {
  55. int major, minor;
  56. return (GetOsVersion(&major, &minor, nullptr) &&
  57. (major > kWindowsVista || (major == kWindowsVista && minor >= 2)));
  58. }
  59. inline bool IsWindows10OrLater() {
  60. int major;
  61. return (GetOsVersion(&major, nullptr, nullptr) && (major >= kWindows10));
  62. }
  63. #else
  64. // When targetting WinUWP the OS must be Windows 10 (or greater) as lesser
  65. // Windows OS targets are not supported.
  66. inline bool IsWindowsVistaOrLater() {
  67. return true;
  68. }
  69. inline bool IsWindowsXpOrLater() {
  70. return true;
  71. }
  72. inline bool IsWindows8OrLater() {
  73. return true;
  74. }
  75. inline bool IsWindows10OrLater() {
  76. return true;
  77. }
  78. #endif // !defined(WINUWP)
  79. } // namespace rtc
  80. #endif // RTC_BASE_WIN32_H_