无法获得OpenHardwareMonitorLib.dll工作

问题描述:

我已经找到了如何获得OHM在C#无法获得OpenHardwareMonitorLib.dll工作

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using OpenHardwareMonitor.Hardware; 

namespace OpenHardwareMonitorReport 
{ 

    class Program 
    { 

     static void Main(string[] args) 
     { 
      Computer computer = new Computer(); 
      computer.Open(); 

      var temps = new List<decimal>(); 
      foreach (var hardware in computer.Hardware) 
      { 
       if (hardware.HardwareType != HardwareType.CPU) 
        continue; 
       hardware.Update(); 
       foreach (var sensor in hardware.Sensors) 
       { 
        if (sensor.SensorType != SensorType.Temperature) 
        { 
         if (sensor.Value != null) 
          temps.Add((decimal)sensor.Value); 
        } 
       } 
      } 

      foreach (decimal temp in temps) 
      { 
       Console.WriteLine(temp); 
      } 
      Console.ReadLine(); 
     } 
    } 
} 

这应该显示一些传感器数据,但是当我运行它给我这个错误做工非常举几个例子:

托管调试助手'PInvokeStackImbalance'在'C:\ Users \ Josh \ Desktop \ DLLTutorial \ HardwareMonitor \ HardwareMonitor \ bin \ Debug \ HardwareMonitor.vshost.exe'中检测到问题。 附加信息:对PInvoke函数'PInvokeDelegateFactoryInternalAssembly!PInvokeDelegateFactoryInternalWrapperType13 :: ADL_Main_Control_Create'的调用使堆栈不平衡。这很可能是因为托管的PInvoke签名与非托管目标签名不匹配。检查PInvoke签名的调用约定和参数是否与目标非托管签名相匹配。

我已经从OHM svn下载了.dll文件,把它放到了我的项目中,并添加了对它的引用,并且它在“computer.Open()”行中崩溃了。与我上面发布的错误。

请帮忙!

+0

我刚刚下载了最新的示例并运行了您提供的代码。它在我的机器上运行良好。你运行的是什么版本的Windows/.Net? – scottm 2012-07-20 17:56:44

+0

Windows 7 Professional 64位,.Net 4.0 – 2012-07-20 18:00:12

+0

这就是我正在运行的。你安装了SP1吗? – scottm 2012-07-20 18:01:15

显然这是我的设置问题。它不会在其他系统上失败......当这种情况发生时,你是否讨厌它?