win32utils-devel@rubyforge.org
2004-Dec-10 11:07 UTC
[Win32utils-devel] Modification for mkmf
Hi all,
I came across this page today:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winprog
/winprog/using_the_windows_headers.asp
Based on that, I think we need a patch for mkmf when on Windows that
sets _WIN32_WINNT automatically based on platform. This is the basic
code I''ve come up with:
require "mkmf"
require "win32ole"
require "socket"
# We need to get the exact version number and set _WIN32_WINNT
accordingly
host = Socket.gethostname
cs "winmgmts:{impersonationLevel=impersonate,(security)}//#{host}/root/cimv
2"
wmi = WIN32OLE.connect(cs)
major = nil
minor = nil
wmi.InstancesOf("Win32_OperatingSystem").each{ |ole|
major, minor = ole.Version.split(".").map{ |e| e.to_i }
break
}
win32_winnt = nil
# The value for Windows NT 4 and Windows 95 are the same.
# The value for Windows 2000 and Windows ME are the same.
case major
when 5
case minor
when 2 # 2003
win32_winnt = "0x0502"
when 1 # XP
win32_winnt = "0x0501"
else # 2000
win32_winnt = "0x0500"
end
when 4
case minor
when 0 # NT or 95
win32_winnt = "0x0400"
when 90 # ME
win32_winnt = "0x0500"
when 10 # 98
win32_winnt = "0x0410"
end
end
# So long as we''re not on Windows 3.51 or earlier, this should be
defined
if win32_winnt
$CPPFLAGS += " -D_WIN32_WINNT=#{win32_winnt}"
end
# END
I realize there are possible scenarios where this won''t quite work (see
the example they discuss near the bottom of the link I provided). In
such cases, it would be up to the extension writer to set $CPPFLAGS
accordingly.
Optionally, the WMI + OLE code could be replaced with WIN32API +
GetVersionEx().
What do you think?
Dan
win32utils-devel@rubyforge.org
2004-Dec-10 12:07 UTC
[Win32utils-devel] Modification for mkmf
Here''s a Win32API snippet for getting major and minor:
require "Win32API"
GetVersionEx =
Win32API.new(''kernel32'',''GetVersionEx'',''P'',''I'')
swCSDVersion = "\0" * 128
OSVERSIONINFO = [148,0,0,0,0,swCSDVersion].pack("LLLLLa128")
GetVersionEx.call(OSVERSIONINFO)
info = OSVERSIONINFO.unpack("LLLLLa128")
major, minor = info[1,2]
Regards,
Dan