Can't get OpenHardwareMonitorLib.dll to work

左心房为你撑大大i 提交于 2019-12-12 01:36:41

问题


I've found very few examples of how to get OHM working in c#

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();
        }
    }
}

This should display some sensor data but when I run it gives me this error:

Managed Debugging Assistant 'PInvokeStackImbalance' has detected a problem in 'C:\Users\Josh\Desktop\DLLTutorial\HardwareMonitor\HardwareMonitor\bin\Debug\HardwareMonitor.vshost.exe'. Additional Information: A call to PInvoke function 'PInvokeDelegateFactoryInternalAssembly!PInvokeDelegateFactoryInternalWrapperType13::ADL_Main_Control_Create' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

I've downloaded the .dll from the OHM svn, put it in my project, added the reference to it and it crashes on the line "computer.Open();" with that error I posted above.

Please help!


回答1:


Apparently it's a problem with my set up. It doesn't fail on other systems...Don't you hate it when that happens.



来源:https://stackoverflow.com/questions/11583871/cant-get-openhardwaremonitorlib-dll-to-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!