windows - Python ctypes - Getting 0 with GetVersionEx function -
explanation: i'm trying results of function getversionex, '0' @ output time:
class op_info(structure): _fields_ = [ ('dwosversioninfosize', dword), ('dwmajorversion', dword), ('dwminorversion', dword), ('dwbuildnumber', dword), ('dwplatformid', dword), ('szcsdversion', dword) ] def info(): op = op_info() ctypes.windll.kernel32.getversion(byref(op)) return op.dwmajorversion print info()
question: how can make function works , real results?
edit: @eryksun did before called getversionexw function:
import sys op.dwosversioninfosize = sys.getsizeof(op_info)
and output is: 452
but final result of info() still 0
here's example setup calling getversionexw
fill in either osversioninfo
or osversioninfoex
record.
import ctypes ctypes.wintypes import byte, word, dword, wchar kernel32 = ctypes.windll('kernel32', use_last_error=true) class osversioninfo(ctypes.structure): _fields_ = (('dwosversioninfosize', dword), ('dwmajorversion', dword), ('dwminorversion', dword), ('dwbuildnumber', dword), ('dwplatformid', dword), ('szcsdversion', wchar * 128)) def __init__(self, *args, **kwds): super(osversioninfo, self).__init__(*args, **kwds) self.dwosversioninfosize = ctypes.sizeof(self) kernel32.getversionexw(ctypes.byref(self)) class osversioninfoex(osversioninfo): _fields_ = (('wservicepackmajor', word), ('wservicepackminor', word), ('wsuitemask', word), ('wproducttype', byte), ('wreserved', byte)) def errcheck_bool(result, func, args): if not result: raise ctypes.winerror(ctypes.get_last_error()) return args kernel32.getversionexw.errcheck = errcheck_bool kernel32.getversionexw.argtypes = (ctypes.pointer(osversioninfo),) def get_os_major_version(): info = osversioninfo() return info.dwmajorversion
if __name__ == '__main__': print get_os_major_version()
Comments
Post a Comment