File: get_versionex.rb

package info (click to toggle)
ruby-cstruct 1.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 412 kB
  • sloc: ruby: 1,008; makefile: 7
file content (47 lines) | stat: -rw-r--r-- 1,458 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# CStruct Examples
require 'windows/system_info'
require 'cstruct/win32struct'
include Windows::SystemInfo


# OSVERSIONINFOEXA in VC6 's SDK
#typedef struct _OSVERSIONINFOEXA {
#    DWORD dwOSVersionInfoSize;
#    DWORD dwMajorVersion;
#    DWORD dwMinorVersion;
#    DWORD dwBuildNumber;
#    DWORD dwPlatformId;
#    CHAR   szCSDVersion[ 128 ];     // Maintenance string for PSS usage
#    WORD wServicePackMajor;
#    WORD wServicePackMinor;
#    WORD wReserved[2];
#} OSVERSIONINFOEXA;


class OSVERSIONINFOEXA < Win32Struct
  DWORD :dwOSVersionInfoSize
  DWORD :dwMajorVersion
  DWORD :dwMinorVersion
  DWORD :dwBuildNumber
  DWORD :dwPlatformId
  CHAR  :szCSDVersion,[ 128 ]
  WORD  :wServicePackMajor
  WORD  :wServicePackMinor
  WORD  :wReserved,[2]    
end

ver_info_ex = OSVERSIONINFOEXA.new do |st| 
  st.dwOSVersionInfoSize = OSVERSIONINFOEXA.__size__  # __size__ is an alias for method 'size'
end

#ANSI Version: GetVersionExA
GetVersionExA(ver_info_ex.__data__) # __data__ is an alias for method 'data'

puts "<OS Version Infomation>"
puts "Major Version:#{ver_info_ex.dwMajorVersion}"
puts "Minor Version:#{ver_info_ex.dwMinorVersion}"
puts "Build Number:#{ver_info_ex.dwBuildNumber}"
puts "Platform Id:#{ver_info_ex.dwPlatformId}"
puts "CSD Version:#{ver_info_ex.szCSDVersion.to_cstr}"      # to_cstr return a string(C Style)
puts "ServicePack Major:#{ver_info_ex.wServicePackMajor}"
puts "ServicePack Minor:#{ver_info_ex.wServicePackMinor}"