win32.dart 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import 'dart:ffi' hide Size;
  2. import 'package:ffi/ffi.dart';
  3. import 'package:win32/win32.dart' as win32;
  4. /// Get windows target build number.
  5. ///
  6. /// [Note]
  7. /// Please use this function wrapped with `Platform.isWindows`.
  8. int getWindowsTargetBuildNumber_() {
  9. final rtlGetVersion = DynamicLibrary.open('ntdll.dll').lookupFunction<
  10. Void Function(Pointer<win32.OSVERSIONINFOEX>),
  11. void Function(Pointer<win32.OSVERSIONINFOEX>)>('RtlGetVersion');
  12. final osVersionInfo = _getOSVERSIONINFOEXPointer();
  13. rtlGetVersion(osVersionInfo);
  14. int buildNumber = osVersionInfo.ref.dwBuildNumber;
  15. calloc.free(osVersionInfo);
  16. return buildNumber;
  17. }
  18. /// Get Windows OS version pointer
  19. ///
  20. /// [Note]
  21. /// Please use this function wrapped with `Platform.isWindows`.
  22. Pointer<win32.OSVERSIONINFOEX> _getOSVERSIONINFOEXPointer() {
  23. final pointer = calloc<win32.OSVERSIONINFOEX>();
  24. pointer.ref
  25. ..dwOSVersionInfoSize = sizeOf<win32.OSVERSIONINFOEX>()
  26. ..dwBuildNumber = 0
  27. ..dwMajorVersion = 0
  28. ..dwMinorVersion = 0
  29. ..dwPlatformId = 0
  30. ..szCSDVersion = ''
  31. ..wServicePackMajor = 0
  32. ..wServicePackMinor = 0
  33. ..wSuiteMask = 0
  34. ..wProductType = 0
  35. ..wReserved = 0;
  36. return pointer;
  37. }