Question

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!

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top