From 4026c56ba0e74e44f153dfe9f0a9258330ba16d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=B6ller?= Date: Wed, 11 Jul 2012 22:28:39 +0000 Subject: [PATCH] Fixed Issue 274. Fixed Issue 107. --- Hardware/ATI/ADL.cs | 2 +- Hardware/OperatingSystem.cs | 38 +++++++++++++++++++++++++++++++++++ Hardware/Ring0.cs | 5 +++-- OpenHardwareMonitorLib.csproj | 1 + 4 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 Hardware/OperatingSystem.cs diff --git a/Hardware/ATI/ADL.cs b/Hardware/ATI/ADL.cs index b594031..51f14f2 100644 --- a/Hardware/ATI/ADL.cs +++ b/Hardware/ATI/ADL.cs @@ -162,7 +162,7 @@ namespace OpenHardwareMonitor.Hardware.ATI { where T : class { DllImportAttribute attribute = new DllImportAttribute(dllName); - attribute.CallingConvention = CallingConvention.StdCall; + attribute.CallingConvention = CallingConvention.Cdecl; attribute.PreserveSig = true; attribute.EntryPoint = entryPoint; PInvokeDelegateFactory.CreateDelegate(attribute, out newDelegate); diff --git a/Hardware/OperatingSystem.cs b/Hardware/OperatingSystem.cs new file mode 100644 index 0000000..6cc2b34 --- /dev/null +++ b/Hardware/OperatingSystem.cs @@ -0,0 +1,38 @@ +/* + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + + Copyright (C) 2012 Michael Möller + +*/ + +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; + +namespace OpenHardwareMonitor.Hardware { + internal static class OperatingSystem { + + public static bool Is64BitOperatingSystem() { + if (IntPtr.Size == 8) + return true; + + try { + bool wow64Process; + bool result = IsWow64Process( + Process.GetCurrentProcess().Handle, out wow64Process); + + return result && wow64Process; + } catch (EntryPointNotFoundException) { + return false; + } + } + + [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool IsWow64Process(IntPtr hProcess, + out bool wow64Process); + } +} diff --git a/Hardware/Ring0.cs b/Hardware/Ring0.cs index 48d4797..d03893b 100644 --- a/Hardware/Ring0.cs +++ b/Hardware/Ring0.cs @@ -4,7 +4,7 @@ License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - Copyright (C) 2010-2011 Michael Möller + Copyright (C) 2010-2012 Michael Möller */ @@ -75,7 +75,8 @@ namespace OpenHardwareMonitor.Hardware { private static bool ExtractDriver(string fileName) { string resourceName = "OpenHardwareMonitor.Hardware." + - (IntPtr.Size == 4 ? "WinRing0.sys" : "WinRing0x64.sys"); + (OperatingSystem.Is64BitOperatingSystem() ? "WinRing0x64.sys" : + "WinRing0.sys"); string[] names = Assembly.GetExecutingAssembly().GetManifestResourceNames(); diff --git a/OpenHardwareMonitorLib.csproj b/OpenHardwareMonitorLib.csproj index 5e46a02..a590237 100644 --- a/OpenHardwareMonitorLib.csproj +++ b/OpenHardwareMonitorLib.csproj @@ -92,6 +92,7 @@ +