非托管代码与来自所述OpenHardwareMonitor项目,我已经自己做了一个漂亮的小工具来监视CPU和GPU指标温度,负载一些启示等调用从C#
它工作正常,但我到一个PInvokeStackImbalance
警告运行当调用NVidia驱动程序方法时,不要认为忽略它们是明智的。然而,经过数周的实验(使用NVidia Documentaion)后,我仍然无法弄清楚如何定义和使用驱动程序结构和方法,以使VS 2015满意 - 这很奇怪,因为有尽管使用完全相同的代码,但在OpenHardwareMonitor项目中没有警告。
希望这里有人能指点我正确的方向。
[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
宾果!我不知道你可以在代表中指定调用约定,我将它添加到所有代表中,不再有任何警告! – VikFreeze