With some inspiration from the OpenHardwareMonitor Project i have made myself a nice gadget to monitor CPU and GPU metrics Temperature, Load, etc.
It works fine but I am running in to a PInvokeStackImbalance
warning when calling the NVidia Driver Methods and don't think is wise to ignore them.
However after weeks of experimentation (with NVidia Documentaion in hand) I still can't figure out how to define and use the Drivers Structs and Methods in such a way that VS 2015 is happy with - Which is strange because there are no warnings in the OpenHardwareMonitor Project despite using the exact same code.
Hopefully someone here can point me in the right direction.
[DllImport("nvapi.dll", CallingConvention = CallingConvention.Cdecl, PreserveSig = true)]
private static extern IntPtr nvapi_QueryInterface(uint id);
private delegate NvStatus NvAPI_EnumPhysicalGPUsDelegate([Out] NvPhysicalGpuHandle[] gpuHandles, out int gpuCount);
private static readonly NvAPI_EnumPhysicalGPUsDelegate NvAPI_EnumPhysicalGPUs;
NvAPI_EnumPhysicalGPUs = Marshal.GetDelegateForFunctionPointer(nvapi_QueryInterface(0xE5AC921F), typeof(NvAPI_EnumPhysicalGPUsDelegate)) as NvAPI_EnumPhysicalGPUsDelegate;
status = NvAPI_EnumPhysicalGPUs != null ? NvAPI_EnumPhysicalGPUs(PhysicalGPUHandles, out PhysicalGPUHandlesCount) : NvStatus.FUNCTION_NOT_FOUND; // warning is thrown here