Форум программистов, компьютерный форум, киберфорум
C# .NET
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.95/40: Рейтинг темы: голосов - 40, средняя оценка - 4.95
29 / 29 / 8
Регистрация: 13.12.2009
Сообщений: 70
1

Температура видеокарты NVIDIA

01.11.2011, 23:01. Показов 8220. Ответов 6
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Привет, есть проблема при определении температуры и других параметров карты NVIDIA при использовании nvcpl.dll. Собственно есть код:
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 private class NativeMethod
        {
            [DllImport("nvcpl.dll", EntryPoint = "NvCplGetThermalSettings", CallingConvention = CallingConvention.Cdecl)]
            public static extern bool NvCplGetThermalSettings(UInt32 nWindowsMonitorNumber, out UInt32 pdwCoreTemp, out UInt32 pdwAmbientTemp, out UInt32 pdwUpperLimit);
        }
 
        public UInt32 GetNVidiaCardTemperature(uint monitorNumber)
        {
            UInt32 coreTemp = 0;
            UInt32 ambientTemp = 0;
            UInt32 upperLimit = 0;
            NativeMethod.NvCplGetThermalSettings(0, out coreTemp, out ambientTemp, out upperLimit);
            return coreTemp;
        }
Вопрос какую dll надо для это использовать? Та которая лежит в system32 не работает и вылетает с ошибкой : "Была сделана попытка загрузить программу, имеющую неверный формат."
Скачал другую dll... возвращает нули. Или проблема в чем то другом?
0
Лучшие ответы (1)
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
01.11.2011, 23:01
Ответы с готовыми решениями:

Рабочая температура видеокарты nvidia geforce gt 230 м
Доброго времени суток. Играю на ноутбуке в фифа 13 и начал замечать что через пару минут после...

какая рабочая температура у видеокарты NVIDIA GeForce 9800 GT?
какая рабочая темпиратура у видеокарты NVIDIA GeForce 9800 GT

Какая максимальная температура видеокарты Nvidia Geforce Gt 220?
Скажите пожалуйста, какая максимальная температура видеокарты Nvidia Geforce Gt 220. У меня до 90...

Какова нормальная температура видеокарты NVIDIA GeForce 9500 GT (512 Мб)?
Подскажите пожалуйста какова нормальная температура видеокарты NVIDIA GeForce 9500 GT (512 Мб)?У...

6
Почетный модератор
Эксперт .NET
8721 / 3673 / 404
Регистрация: 14.06.2010
Сообщений: 4,513
Записей в блоге: 9
01.11.2011, 23:20 2
Лучший ответ Сообщение было отмечено как решение

Решение

Тоже когда-то искал инфу об этом... NvCplGetThermalSettings у меня не работала, постоянно возвращала NOT_IMPLEMENTED, нашел такой код:
NvAPI.cs (взят отсюда)
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
/*
  
  Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
  The contents of this file are subject to the Mozilla Public License Version
  1.1 (the "License"); you may not use this file except in compliance with
  the License. You may obtain a copy of the License at
 
  [url]http://www.mozilla.org/MPL/[/url]
 
  Software distributed under the License is distributed on an "AS IS" basis,
  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  for the specific language governing rights and limitations under the License.
 
  The Original Code is the Open Hardware Monitor code.
 
  The Initial Developer of the Original Code is 
  Michael Möller <m.moeller@gmx.ch>.
  Portions created by the Initial Developer are Copyright (C) 2009-2010
  the Initial Developer. All Rights Reserved.
 
  Contributor(s):
 
  Alternatively, the contents of this file may be used under the terms of
  either the GNU General Public License Version 2 or later (the "GPL"), or
  the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  in which case the provisions of the GPL or the LGPL are applicable instead
  of those above. If you wish to allow use of your version of this file only
  under the terms of either the GPL or the LGPL, and not to allow others to
  use your version of this file under the terms of the MPL, indicate your
  decision by deleting the provisions above and replace them with the notice
  and other provisions required by the GPL or the LGPL. If you do not delete
  the provisions above, a recipient may use your version of this file under
  the terms of any one of the MPL, the GPL or the LGPL.
 
*/
 
using System;
using System.Runtime.InteropServices;
using System.Text;
 
namespace Nvidia {
 
  public enum NvStatus {
    OK = 0,
    ERROR = -1,
    LIBRARY_NOT_FOUND = -2,
    NO_IMPLEMENTATION = -3,
    API_NOT_INTIALIZED = -4,
    INVALID_ARGUMENT = -5,
    NVIDIA_DEVICE_NOT_FOUND = -6,
    END_ENUMERATION = -7,
    INVALID_HANDLE = -8,
    INCOMPATIBLE_STRUCT_VERSION = -9,
    HANDLE_INVALIDATED = -10,
    OPENGL_CONTEXT_NOT_CURRENT = -11,
    NO_GL_EXPERT = -12,
    INSTRUMENTATION_DISABLED = -13,
    EXPECTED_LOGICAL_GPU_HANDLE = -100,
    EXPECTED_PHYSICAL_GPU_HANDLE = -101,
    EXPECTED_DISPLAY_HANDLE = -102,
    INVALID_COMBINATION = -103,
    NOT_SUPPORTED = -104,
    PORTID_NOT_FOUND = -105,
    EXPECTED_UNATTACHED_DISPLAY_HANDLE = -106,
    INVALID_PERF_LEVEL = -107,
    DEVICE_BUSY = -108,
    NV_PERSIST_FILE_NOT_FOUND = -109,
    PERSIST_DATA_NOT_FOUND = -110,
    EXPECTED_TV_DISPLAY = -111,
    EXPECTED_TV_DISPLAY_ON_DCONNECTOR = -112,
    NO_ACTIVE_SLI_TOPOLOGY = -113,
    SLI_RENDERING_MODE_NOTALLOWED = -114,
    EXPECTED_DIGITAL_FLAT_PANEL = -115,
    ARGUMENT_EXCEED_MAX_SIZE = -116,
    DEVICE_SWITCHING_NOT_ALLOWED = -117,
    TESTING_CLOCKS_NOT_SUPPORTED = -118,
    UNKNOWN_UNDERSCAN_CONFIG = -119,
    TIMEOUT_RECONFIGURING_GPU_TOPO = -120,
    DATA_NOT_FOUND = -121,
    EXPECTED_ANALOG_DISPLAY = -122,
    NO_VIDLINK = -123,
    REQUIRES_REBOOT = -124,
    INVALID_HYBRID_MODE = -125,
    MIXED_TARGET_TYPES = -126,
    SYSWOW64_NOT_SUPPORTED = -127,
    IMPLICIT_SET_GPU_TOPOLOGY_CHANGE_NOT_ALLOWED = -128,
    REQUEST_USER_TO_CLOSE_NON_MIGRATABLE_APPS = -129,
    OUT_OF_MEMORY = -130,
    WAS_STILL_DRAWING = -131,
    FILE_NOT_FOUND = -132,
    TOO_MANY_UNIQUE_STATE_OBJECTS = -133,
    INVALID_CALL = -134,
    D3D10_1_LIBRARY_NOT_FOUND = -135,
    FUNCTION_NOT_FOUND = -136
  }
 
  public enum NvThermalController {
    NONE = 0,
    GPU_INTERNAL,  
    ADM1032,
    MAX6649,       
    MAX1617,      
    LM99,      
    LM89,         
    LM64,         
    ADT7473,
    SBMAX6649,
    VBIOSEVT,  
    OS,    
    UNKNOWN = -1,
  }
 
  public enum NvThermalTarget {
    NONE = 0,
    GPU = 1,
    MEMORY = 2,
    POWER_SUPPLY = 4,
    BOARD = 8,
    ALL = 15,
    UNKNOWN = -1
  };
 
  [StructLayout(LayoutKind.Sequential, Pack = 8)]
  public struct NvSensor {
    public NvThermalController Controller;
    public uint DefaultMinTemp;
    public uint DefaultMaxTemp;
    public uint CurrentTemp;
    public NvThermalTarget Target;     
  }
 
  [StructLayout(LayoutKind.Sequential, Pack = 8)]
  public struct NvGPUThermalSettings {
    public uint Version;
    public uint Count;
    [MarshalAs(UnmanagedType.ByValArray, 
      SizeConst = NVAPI.MAX_THERMAL_SENSORS_PER_GPU)]
    public NvSensor[] Sensor;
  }
 
  [StructLayout(LayoutKind.Sequential)]
  public struct NvDisplayHandle {
    private readonly IntPtr ptr;
  }
 
  [StructLayout(LayoutKind.Sequential)]
  public struct NvPhysicalGpuHandle {
    private readonly IntPtr ptr;
  }
 
  [StructLayout(LayoutKind.Sequential, Pack = 8)]
  public struct NvClocks {
    public uint Version;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = NVAPI.MAX_CLOCKS_PER_GPU)]
    public uint[] Clock;
  }
 
  [StructLayout(LayoutKind.Sequential, Pack = 8)]
  public struct NvPState {
    public bool Present;
    public int Percentage;
  }
 
  [StructLayout(LayoutKind.Sequential, Pack = 8)]
  public struct NvPStates {
    public uint Version;
    public uint Flags;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = NVAPI.MAX_PSTATES_PER_GPU)]
    public NvPState[] PStates;
  }
 
  [StructLayout(LayoutKind.Sequential, Pack = 8)]
  public struct NvUsages {
    public uint Version;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = NVAPI.MAX_USAGES_PER_GPU)]
    public uint[] Usage;
  }
 
  [StructLayout(LayoutKind.Sequential, Pack = 8)]
  public struct NvCooler {
    public int Type;
    public int Controller;
    public int DefaultMin;
    public int DefaultMax;
    public int CurrentMin;
    public int CurrentMax;
    public int CurrentLevel;
    public int DefaultPolicy;
    public int CurrentPolicy;
    public int Target;
    public int ControlType;
    public int Active;
  }
 
  [StructLayout(LayoutKind.Sequential, Pack = 8)]
  public struct NvGPUCoolerSettings {
    public uint Version;
    public uint Count;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = NVAPI.MAX_COOLER_PER_GPU)]
    public NvCooler[] Cooler;
  }
 
  [StructLayout(LayoutKind.Sequential, Pack = 8)]
  public struct NvMemoryInfo {
    public uint Version;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 
      NVAPI.MAX_MEMORY_VALUES_PER_GPU)]
    public uint[] Values;
  }
 
  [StructLayout(LayoutKind.Sequential, Pack = 8)]
  public struct NvDisplayDriverVersion {
    public uint Version;
    public uint DriverVersion;
    public uint BldChangeListNum;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = NVAPI.SHORT_STRING_MAX)]
    public string BuildBranch;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = NVAPI.SHORT_STRING_MAX)]
    public string Adapter;
  }
 
  public class NVAPI {
 
    public const int MAX_PHYSICAL_GPUS = 64;
    public const int SHORT_STRING_MAX = 64;
 
    public const int MAX_THERMAL_SENSORS_PER_GPU = 3;    
    public const int MAX_CLOCKS_PER_GPU = 0x120;
    public const int MAX_PSTATES_PER_GPU = 8;
    public const int MAX_USAGES_PER_GPU = 33;
    public const int MAX_COOLER_PER_GPU = 20;
    public const int MAX_MEMORY_VALUES_PER_GPU = 5;
 
    public static readonly uint GPU_THERMAL_SETTINGS_VER = (uint)
      Marshal.SizeOf(typeof(NvGPUThermalSettings)) | 0x10000;
    public static readonly uint GPU_CLOCKS_VER = (uint)
      Marshal.SizeOf(typeof(NvClocks)) | 0x20000;
    public static readonly uint GPU_PSTATES_VER = (uint)
      Marshal.SizeOf(typeof(NvPStates)) | 0x10000;
    public static readonly uint GPU_USAGES_VER = (uint)
      Marshal.SizeOf(typeof(NvUsages)) | 0x10000;
    public static readonly uint GPU_COOLER_SETTINGS_VER = (uint)
      Marshal.SizeOf(typeof(NvGPUCoolerSettings)) | 0x20000;
    public static readonly uint GPU_MEMORY_INFO_VER = (uint) 
      Marshal.SizeOf(typeof(NvMemoryInfo)) | 0x20000;
    public static readonly uint DISPLAY_DRIVER_VERSION_VER = (uint)
      Marshal.SizeOf(typeof(NvDisplayDriverVersion)) | 0x10000;
      
    private delegate NvStatus NvAPI_InitializeDelegate();
    private delegate NvStatus NvAPI_GPU_GetFullNameDelegate(
      NvPhysicalGpuHandle gpuHandle, StringBuilder name);
 
    public delegate NvStatus NvAPI_GPU_GetThermalSettingsDelegate(
      NvPhysicalGpuHandle gpuHandle, int sensorIndex, 
      ref NvGPUThermalSettings nvGPUThermalSettings);
    public delegate NvStatus NvAPI_EnumNvidiaDisplayHandleDelegate(int thisEnum,
      ref NvDisplayHandle displayHandle);
    public delegate NvStatus NvAPI_GetPhysicalGPUsFromDisplayDelegate(
      NvDisplayHandle displayHandle, [Out] NvPhysicalGpuHandle[] gpuHandles, 
      out uint gpuCount);
    public delegate NvStatus NvAPI_EnumPhysicalGPUsDelegate(
      [Out] NvPhysicalGpuHandle[] gpuHandles, out int gpuCount);
    public delegate NvStatus NvAPI_GPU_GetTachReadingDelegate(
      NvPhysicalGpuHandle gpuHandle, out int value);
    public delegate NvStatus NvAPI_GPU_GetAllClocksDelegate(
      NvPhysicalGpuHandle gpuHandle, ref NvClocks nvClocks);
    public delegate NvStatus NvAPI_GPU_GetPStatesDelegate(
      NvPhysicalGpuHandle gpuHandle, ref NvPStates nvPStates);
    public delegate NvStatus NvAPI_GPU_GetUsagesDelegate(
      NvPhysicalGpuHandle gpuHandle, ref NvUsages nvUsages);
    public delegate NvStatus NvAPI_GPU_GetCoolerSettingsDelegate(
      NvPhysicalGpuHandle gpuHandle, int coolerIndex,
      ref NvGPUCoolerSettings nvGPUCoolerSettings);
    public delegate NvStatus NvAPI_GPU_GetMemoryInfoDelegate(
      NvDisplayHandle displayHandle, ref NvMemoryInfo nvMemoryInfo);
    public delegate NvStatus NvAPI_GetDisplayDriverVersionDelegate(
      NvDisplayHandle displayHandle, [In, Out] ref NvDisplayDriverVersion
      nvDisplayDriverVersion);
    public delegate NvStatus NvAPI_GetInterfaceVersionStringDelegate(
      StringBuilder version);
 
    private static readonly bool available;
    private static readonly NvAPI_InitializeDelegate NvAPI_Initialize;
    private static readonly NvAPI_GPU_GetFullNameDelegate 
      _NvAPI_GPU_GetFullName;
    private static readonly NvAPI_GetInterfaceVersionStringDelegate
      _NvAPI_GetInterfaceVersionString;
 
    public static readonly NvAPI_GPU_GetThermalSettingsDelegate 
      NvAPI_GPU_GetThermalSettings;
    public static readonly NvAPI_EnumNvidiaDisplayHandleDelegate
      NvAPI_EnumNvidiaDisplayHandle;
    public static readonly NvAPI_GetPhysicalGPUsFromDisplayDelegate
      NvAPI_GetPhysicalGPUsFromDisplay;
    public static readonly NvAPI_EnumPhysicalGPUsDelegate
      NvAPI_EnumPhysicalGPUs;
    public static readonly NvAPI_GPU_GetTachReadingDelegate
      NvAPI_GPU_GetTachReading;
    public static readonly NvAPI_GPU_GetAllClocksDelegate
      NvAPI_GPU_GetAllClocks;
    public static readonly NvAPI_GPU_GetPStatesDelegate
      NvAPI_GPU_GetPStates;
    public static readonly NvAPI_GPU_GetUsagesDelegate
      NvAPI_GPU_GetUsages;
    public static readonly NvAPI_GPU_GetCoolerSettingsDelegate
      NvAPI_GPU_GetCoolerSettings;
    public static readonly NvAPI_GPU_GetMemoryInfoDelegate
      NvAPI_GPU_GetMemoryInfo;
    public static readonly NvAPI_GetDisplayDriverVersionDelegate
      NvAPI_GetDisplayDriverVersion;
 
    private NVAPI() { }
 
    public static NvStatus NvAPI_GPU_GetFullName(NvPhysicalGpuHandle gpuHandle,
      out string name) {
      StringBuilder builder = new StringBuilder(SHORT_STRING_MAX);
      NvStatus status;
      if (_NvAPI_GPU_GetFullName != null)
        status = _NvAPI_GPU_GetFullName(gpuHandle, builder);
      else
        status = NvStatus.FUNCTION_NOT_FOUND;
      name = builder.ToString();
      return status;
    }
 
    public static NvStatus NvAPI_GetInterfaceVersionString(out string version) {
      StringBuilder builder = new StringBuilder(SHORT_STRING_MAX);
      NvStatus status;
      if (_NvAPI_GetInterfaceVersionString != null)
        status = _NvAPI_GetInterfaceVersionString(builder);
      else
        status = NvStatus.FUNCTION_NOT_FOUND;
      version = builder.ToString();
      return status;
    }
 
    private static string GetDllName() {
      if (IntPtr.Size == 4) {
        return "nvapi.dll";
      } else {
        return "nvapi64.dll";
      }
    }
 
    private static void GetDelegate<T>(uint id, out T newDelegate) 
      where T : class 
    {
      IntPtr ptr = nvapi_QueryInterface(id);
      if (ptr != IntPtr.Zero) {
        newDelegate =
          Marshal.GetDelegateForFunctionPointer(ptr, typeof(T)) as T;
      } else {
        newDelegate = null;
      }
    }
 
    [DllImport("nvapi.dll", CallingConvention = CallingConvention.Cdecl)]
    static extern IntPtr nvapi_QueryInterface(uint id);
    
    static NVAPI() {
      try {
        GetDelegate(0x0150E828, out NvAPI_Initialize);
      } catch (DllNotFoundException) { return; } 
        catch (EntryPointNotFoundException) { return; } 
        catch (ArgumentNullException) { return; }
 
      if (NvAPI_Initialize() == NvStatus.OK) {
        GetDelegate(0xE3640A56, out NvAPI_GPU_GetThermalSettings);
        GetDelegate(0xCEEE8E9F, out _NvAPI_GPU_GetFullName);
        GetDelegate(0x9ABDD40D, out NvAPI_EnumNvidiaDisplayHandle);
        GetDelegate(0x34EF9506, out NvAPI_GetPhysicalGPUsFromDisplay);
        GetDelegate(0xE5AC921F, out NvAPI_EnumPhysicalGPUs);
        GetDelegate(0x5F608315, out NvAPI_GPU_GetTachReading);
        GetDelegate(0x1BD69F49, out NvAPI_GPU_GetAllClocks);
        GetDelegate(0x60DED2ED, out NvAPI_GPU_GetPStates);
        GetDelegate(0x189A1FDF, out NvAPI_GPU_GetUsages);
        GetDelegate(0xDA141340, out NvAPI_GPU_GetCoolerSettings);
        GetDelegate(0x774AA982, out NvAPI_GPU_GetMemoryInfo);
        GetDelegate(0xF951A4D1, out NvAPI_GetDisplayDriverVersion);
        GetDelegate(0x01053FA5, out _NvAPI_GetInterfaceVersionString);
 
        available = true;
      }
    }
 
    public static bool IsAvailable {
      get { return available; }
    }
 
  }
}
и в Main (наработки):
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Runtime.InteropServices;
using System.Text;
 
namespace WindowsFormsApplication24
{
    static class Program
    {
        [DllImport( "nvcpl.dll", CallingConvention = CallingConvention.Cdecl )]
        [return: MarshalAs( UnmanagedType.Bool )]
        static extern bool NvCplGetThermalSettings (
            uint nWindowsMonitorNumber,
            out uint pdwCoreTemp,
            out uint pdwAmbientTemp,
            out uint pdwUpperLimit
            );
 
        [DllImport( "nvcpl.dll", CallingConvention = CallingConvention.Cdecl )]
        static extern int NvGetLastError ( );
 
        [DllImport( "nvcpl.dll", CallingConvention = CallingConvention.Cdecl )]
        static extern StringBuilder NvGetLastErrorMessage ( );
 
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main ( )
        {
            //uint core, ambient, upper;
            //if (NvCplGetThermalSettings(0, out core, out ambient, out upper)) {
            //    Console.WriteLine("{0}\r\n{1}\r\n{2}", core, ambient, upper);
            //} else {
            //    Console.WriteLine("error: {0} msg: {1}", NvGetLastError(), NvGetLastErrorMessage().ToString());
            //}
            //Console.ReadLine();
            int count;
            var gpuHandles  = new Nvidia.NvPhysicalGpuHandle[64];
            var sensors     = new Nvidia.NvGPUThermalSettings();
            sensors.Sensor  = new Nvidia.NvSensor[3];
 
 
            var status = Nvidia.NVAPI.NvAPI_EnumPhysicalGPUs( gpuHandles, out count );
            if ( status != 0 )
            {
                Console.WriteLine( "Error! Status: {0}", status );
                return;
            }
 
            for ( int i = 0; i < count; ++i )
            {
                sensors.Version = 65604; // V2 struct
                sensors.Count = 3;
 
                status = Nvidia.NVAPI.NvAPI_GPU_GetThermalSettings( gpuHandles[i], 15, ref sensors );
 
                if ( status != 0 )
                {
                    Console.WriteLine( "Error! Status: {0}", status );
                    continue;
                }
 
                Console.WriteLine( "GPU Handle {0}", i );
 
                for ( int j = 0; j < sensors.Count; ++j )
                {
                    Console.WriteLine( "\tSensor: {0}", j );
                    Console.WriteLine( "\tNvThermalController: {0}", sensors.Sensor[j].Controller );
                    Console.WriteLine( "\tNvThermalTarget: {0}", sensors.Sensor[j].Target );
                    Console.WriteLine( "\tDefaultMinTemp: {0}", sensors.Sensor[j].DefaultMinTemp );
                    Console.WriteLine( "\tDefaultMaxTemp: {0}", sensors.Sensor[j].DefaultMaxTemp );
                    Console.WriteLine( "\tCurrentTemp: {0}", sensors.Sensor[j].CurrentTemp );
                    Console.WriteLine();
                }
            }
            Console.ReadLine();
            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());
        }
    }
}
У меня значение сходится с AIDA64.

Добавлено через 6 минут
p.s. Если будут вопросы на счет загадочных значений в статическом конструкторе NvAPI, то вот ответ автора утилиты Open Hardware Monitor (откуда был взят файл NvAPI.cs) на вопрос который я ему задал по этому поводу:
-----Original Message-----
From: SSTREGG [mailto:---]
Sent: Mittwoch, 22. Juni 2011 02:23
To: m.moeller@gmx.ch
Subject: Open Hardware Monitor, NVAPI functions

Hello! I was looking for an example of using NVIDIA API in C# and found your code (http://code.google.com/p/open-... a/NVAPI.cs), and I have a question: wherefrom you take the values ​​of Id functions for nvapi_QueryInterface?

GetDelegate(/* this */0xE3640A56, out NvAPI_GPU_GetThermalSettings);
GetDelegate(/* this */0xCEEE8E9F, out _NvAPI_GPU_GetFullName);
GetDelegate(/* this */0x9ABDD40D, out NvAPI_EnumNvidiaDisplayHandle); ...

---------
Michael Möller answer:

Hi,

I assume these values are embedded in the nvapi.lib file. You can intercept them with a proxy dll between an application that is built with nvapi.lib and the actual nvapi.dll (that comes with the nvidia driver). The code from the lib in your application then calls nvapi_QueryInterface in your proxy dll (which you called nvapi.dll and is located in the same folder as the application exe) with these id values. There you can save them and forward the calls to the actual nvapi.dll. Most of them can be found also in the Free Pascal header translation http://bugs.freepascal.org/view.php?id=15771

Michael Möller
7
29 / 29 / 8
Регистрация: 13.12.2009
Сообщений: 70
01.11.2011, 23:49  [ТС] 3
SSTREGG Я подозревал, что вы ответите...) Вообщем как понял необходимо использовать nvapi.dll, буду пробовать так "You can intercept them with a proxy dll between an application that is built with nvapi.lib and the actual nvapi.dll".
А вообще странно, что есть официальный мануал по nvcpl.dll руководствуясь которым ничего толком не напишешь, максимум добился получения NvGetConnectedDevicesString и то криво.
Спасибо.

P.S. Получится - кину код сюда, все равно проет OpenSource.
0
1 / 1 / 0
Регистрация: 11.06.2011
Сообщений: 51
13.12.2011, 17:36 4
SSTREGG, Добрый день!

Подскажите используя ваш код при запуске выдает

Вызов функции PInvoke "ex_tempNVD!Nvidia.NVAPI+NvAPI_EnumPhysicalGPUsDelegate::Invoke" разбалансировал стек. Вероятно, это вызвано тем, что управляемая сигнатура PInvoke не совпадает с неуправляемой целевой сигнатурой. Убедитесь, что соглашение о вызовах и параметры сигнатуры PInvoke совпадают с неуправляемой целевой сигнатурой.

Что может быть?
0
Почетный модератор
Эксперт .NET
8721 / 3673 / 404
Регистрация: 14.06.2010
Сообщений: 4,513
Записей в блоге: 9
13.12.2011, 18:23 5
Неверные параметры маршалинга, более точно сейчас ничего сказать не могу. Напишите Вашу систему, на которой пробовали, как доберусь до компа (не раньше чем через неделю), буду пробовать... Может кто быстрее поможет...
0
1 / 1 / 0
Регистрация: 11.06.2011
Сообщений: 51
16.12.2011, 05:00 6
Добрый день!

Мои опыты показали что данная ошибка выходит только в том случае когда в проекте выставлена версия NET 4.0.

При смене целевой структуры на версии NET 2.0 и NET 3.5, все прекрасно работает...

Подскажите что надо изменить чтобы работало на NET 4.0?
0
Почетный модератор
Эксперт .NET
8721 / 3673 / 404
Регистрация: 14.06.2010
Сообщений: 4,513
Записей в блоге: 9
16.11.2013, 20:57 7
Смотрю тема еще кому-то интересна, судя по уведомлениям...

Ошибка была из-за того что все функции имеют соглашение о вызове Cdecl, а по умолчанию используется StdCall.
Вот исправленная версия NvAPI.cs + работает под x64: NvAPI.zip
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
/*
  
  Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
  The contents of this file are subject to the Mozilla Public License Version
  1.1 (the "License"); you may not use this file except in compliance with
  the License. You may obtain a copy of the License at
 
  [url]http://www.mozilla.org/MPL/[/url]
 
  Software distributed under the License is distributed on an "AS IS" basis,
  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  for the specific language governing rights and limitations under the License.
 
  The Original Code is the Open Hardware Monitor code.
 
  The Initial Developer of the Original Code is 
  Michael Möller <m.moeller@gmx.ch>.
  Portions created by the Initial Developer are Copyright (C) 2009-2010
  the Initial Developer. All Rights Reserved.
 
  Contributor(s):
 
  Alternatively, the contents of this file may be used under the terms of
  either the GNU General Public License Version 2 or later (the "GPL"), or
  the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  in which case the provisions of the GPL or the LGPL are applicable instead
  of those above. If you wish to allow use of your version of this file only
  under the terms of either the GPL or the LGPL, and not to allow others to
  use your version of this file under the terms of the MPL, indicate your
  decision by deleting the provisions above and replace them with the notice
  and other provisions required by the GPL or the LGPL. If you do not delete
  the provisions above, a recipient may use your version of this file under
  the terms of any one of the MPL, the GPL or the LGPL.
 
*/
 
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
 
namespace Nvidia
{
 
    public enum NvStatus
    {
        OK = 0,
        ERROR = -1,
        LIBRARY_NOT_FOUND = -2,
        NO_IMPLEMENTATION = -3,
        API_NOT_INTIALIZED = -4,
        INVALID_ARGUMENT = -5,
        NVIDIA_DEVICE_NOT_FOUND = -6,
        END_ENUMERATION = -7,
        INVALID_HANDLE = -8,
        INCOMPATIBLE_STRUCT_VERSION = -9,
        HANDLE_INVALIDATED = -10,
        OPENGL_CONTEXT_NOT_CURRENT = -11,
        NO_GL_EXPERT = -12,
        INSTRUMENTATION_DISABLED = -13,
        EXPECTED_LOGICAL_GPU_HANDLE = -100,
        EXPECTED_PHYSICAL_GPU_HANDLE = -101,
        EXPECTED_DISPLAY_HANDLE = -102,
        INVALID_COMBINATION = -103,
        NOT_SUPPORTED = -104,
        PORTID_NOT_FOUND = -105,
        EXPECTED_UNATTACHED_DISPLAY_HANDLE = -106,
        INVALID_PERF_LEVEL = -107,
        DEVICE_BUSY = -108,
        NV_PERSIST_FILE_NOT_FOUND = -109,
        PERSIST_DATA_NOT_FOUND = -110,
        EXPECTED_TV_DISPLAY = -111,
        EXPECTED_TV_DISPLAY_ON_DCONNECTOR = -112,
        NO_ACTIVE_SLI_TOPOLOGY = -113,
        SLI_RENDERING_MODE_NOTALLOWED = -114,
        EXPECTED_DIGITAL_FLAT_PANEL = -115,
        ARGUMENT_EXCEED_MAX_SIZE = -116,
        DEVICE_SWITCHING_NOT_ALLOWED = -117,
        TESTING_CLOCKS_NOT_SUPPORTED = -118,
        UNKNOWN_UNDERSCAN_CONFIG = -119,
        TIMEOUT_RECONFIGURING_GPU_TOPO = -120,
        DATA_NOT_FOUND = -121,
        EXPECTED_ANALOG_DISPLAY = -122,
        NO_VIDLINK = -123,
        REQUIRES_REBOOT = -124,
        INVALID_HYBRID_MODE = -125,
        MIXED_TARGET_TYPES = -126,
        SYSWOW64_NOT_SUPPORTED = -127,
        IMPLICIT_SET_GPU_TOPOLOGY_CHANGE_NOT_ALLOWED = -128,
        REQUEST_USER_TO_CLOSE_NON_MIGRATABLE_APPS = -129,
        OUT_OF_MEMORY = -130,
        WAS_STILL_DRAWING = -131,
        FILE_NOT_FOUND = -132,
        TOO_MANY_UNIQUE_STATE_OBJECTS = -133,
        INVALID_CALL = -134,
        D3D10_1_LIBRARY_NOT_FOUND = -135,
        FUNCTION_NOT_FOUND = -136
    }
 
    public enum NvThermalController
    {
        NONE = 0,
        GPU_INTERNAL,
        ADM1032,
        MAX6649,
        MAX1617,
        LM99,
        LM89,
        LM64,
        ADT7473,
        SBMAX6649,
        VBIOSEVT,
        OS,
        UNKNOWN = -1,
    }
 
    public enum NvThermalTarget
    {
        NONE = 0,
        GPU = 1,
        MEMORY = 2,
        POWER_SUPPLY = 4,
        BOARD = 8,
        ALL = 15,
        UNKNOWN = -1
    };
 
    [StructLayout( LayoutKind.Sequential, Pack = 8 )]
    public struct NvSensor
    {
        public NvThermalController Controller;
        public uint DefaultMinTemp;
        public uint DefaultMaxTemp;
        public uint CurrentTemp;
        public NvThermalTarget Target;
    }
 
    [StructLayout( LayoutKind.Sequential, Pack = 8 )]
    public struct NvGPUThermalSettings
    {
        public uint Version;
        public uint Count;
        [MarshalAs( UnmanagedType.ByValArray,
          SizeConst = NVAPI.MAX_THERMAL_SENSORS_PER_GPU )]
        public NvSensor[] Sensor;
    }
 
    [StructLayout( LayoutKind.Sequential )]
    public struct NvDisplayHandle
    {
        private readonly IntPtr ptr;
    }
 
    [StructLayout( LayoutKind.Sequential )]
    public struct NvPhysicalGpuHandle
    {
        private readonly IntPtr ptr;
    }
 
    [StructLayout( LayoutKind.Sequential, Pack = 8 )]
    public struct NvClocks
    {
        public uint Version;
        [MarshalAs( UnmanagedType.ByValArray, SizeConst = NVAPI.MAX_CLOCKS_PER_GPU )]
        public uint[] Clock;
    }
 
    [StructLayout( LayoutKind.Sequential, Pack = 8 )]
    public struct NvPState
    {
        public bool Present;
        public int Percentage;
    }
 
    [StructLayout( LayoutKind.Sequential, Pack = 8 )]
    public struct NvPStates
    {
        public uint Version;
        public uint Flags;
        [MarshalAs( UnmanagedType.ByValArray, SizeConst = NVAPI.MAX_PSTATES_PER_GPU )]
        public NvPState[] PStates;
    }
 
    [StructLayout( LayoutKind.Sequential, Pack = 8 )]
    public struct NvUsages
    {
        public uint Version;
        [MarshalAs( UnmanagedType.ByValArray, SizeConst = NVAPI.MAX_USAGES_PER_GPU )]
        public uint[] Usage;
    }
 
    [StructLayout( LayoutKind.Sequential, Pack = 8 )]
    public struct NvCooler
    {
        public int Type;
        public int Controller;
        public int DefaultMin;
        public int DefaultMax;
        public int CurrentMin;
        public int CurrentMax;
        public int CurrentLevel;
        public int DefaultPolicy;
        public int CurrentPolicy;
        public int Target;
        public int ControlType;
        public int Active;
    }
 
    [StructLayout( LayoutKind.Sequential, Pack = 8 )]
    public struct NvGPUCoolerSettings
    {
        public uint Version;
        public uint Count;
        [MarshalAs( UnmanagedType.ByValArray, SizeConst = NVAPI.MAX_COOLER_PER_GPU )]
        public NvCooler[] Cooler;
    }
 
    [StructLayout( LayoutKind.Sequential, Pack = 8 )]
    public struct NvMemoryInfo
    {
        public uint Version;
        [MarshalAs( UnmanagedType.ByValArray, SizeConst =
          NVAPI.MAX_MEMORY_VALUES_PER_GPU )]
        public uint[] Values;
    }
 
    [StructLayout( LayoutKind.Sequential, Pack = 8 )]
    public struct NvDisplayDriverVersion
    {
        public uint Version;
        public uint DriverVersion;
        public uint BldChangeListNum;
        [MarshalAs( UnmanagedType.ByValTStr, SizeConst = NVAPI.SHORT_STRING_MAX )]
        public string BuildBranch;
        [MarshalAs( UnmanagedType.ByValTStr, SizeConst = NVAPI.SHORT_STRING_MAX )]
        public string Adapter;
    }
 
    public class NVAPI
    {
 
        public const int MAX_PHYSICAL_GPUS = 64;
        public const int SHORT_STRING_MAX = 64;
 
        public const int MAX_THERMAL_SENSORS_PER_GPU = 3;
        public const int MAX_CLOCKS_PER_GPU = 0x120;
        public const int MAX_PSTATES_PER_GPU = 8;
        public const int MAX_USAGES_PER_GPU = 33;
        public const int MAX_COOLER_PER_GPU = 20;
        public const int MAX_MEMORY_VALUES_PER_GPU = 5;
 
        public static readonly uint GPU_THERMAL_SETTINGS_VER = (uint)
          Marshal.SizeOf( typeof( NvGPUThermalSettings ) ) | 0x10000;
        public static readonly uint GPU_CLOCKS_VER = (uint)
          Marshal.SizeOf( typeof( NvClocks ) ) | 0x20000;
        public static readonly uint GPU_PSTATES_VER = (uint)
          Marshal.SizeOf( typeof( NvPStates ) ) | 0x10000;
        public static readonly uint GPU_USAGES_VER = (uint)
          Marshal.SizeOf( typeof( NvUsages ) ) | 0x10000;
        public static readonly uint GPU_COOLER_SETTINGS_VER = (uint)
          Marshal.SizeOf( typeof( NvGPUCoolerSettings ) ) | 0x20000;
        public static readonly uint GPU_MEMORY_INFO_VER = (uint)
          Marshal.SizeOf( typeof( NvMemoryInfo ) ) | 0x20000;
        public static readonly uint DISPLAY_DRIVER_VERSION_VER = (uint)
          Marshal.SizeOf( typeof( NvDisplayDriverVersion ) ) | 0x10000;
 
        [UnmanagedFunctionPointer( CallingConvention.Cdecl )]
        private delegate NvStatus NvAPI_InitializeDelegate ( );
        [UnmanagedFunctionPointer( CallingConvention.Cdecl )]
        private delegate NvStatus NvAPI_GPU_GetFullNameDelegate (
          NvPhysicalGpuHandle gpuHandle, StringBuilder name );
 
        [UnmanagedFunctionPointer( CallingConvention.Cdecl )]
        public delegate NvStatus NvAPI_GPU_GetThermalSettingsDelegate (
          NvPhysicalGpuHandle gpuHandle, int sensorIndex,
          ref NvGPUThermalSettings nvGPUThermalSettings );
        [UnmanagedFunctionPointer( CallingConvention.Cdecl )]
        public delegate NvStatus NvAPI_EnumNvidiaDisplayHandleDelegate ( int thisEnum,
          ref NvDisplayHandle displayHandle );
        [UnmanagedFunctionPointer( CallingConvention.Cdecl )]
        public delegate NvStatus NvAPI_GetPhysicalGPUsFromDisplayDelegate (
          NvDisplayHandle displayHandle, [Out] NvPhysicalGpuHandle[] gpuHandles,
          out uint gpuCount );
        [UnmanagedFunctionPointer( CallingConvention.Cdecl )]
        public delegate NvStatus NvAPI_EnumPhysicalGPUsDelegate (
          [Out] NvPhysicalGpuHandle[] gpuHandles, out int gpuCount );
        [UnmanagedFunctionPointer( CallingConvention.Cdecl )]
        public delegate NvStatus NvAPI_GPU_GetTachReadingDelegate (
          NvPhysicalGpuHandle gpuHandle, out int value );
        [UnmanagedFunctionPointer( CallingConvention.Cdecl )]
        public delegate NvStatus NvAPI_GPU_GetAllClocksDelegate (
          NvPhysicalGpuHandle gpuHandle, ref NvClocks nvClocks );
        [UnmanagedFunctionPointer( CallingConvention.Cdecl )]
        public delegate NvStatus NvAPI_GPU_GetPStatesDelegate (
          NvPhysicalGpuHandle gpuHandle, ref NvPStates nvPStates );
        [UnmanagedFunctionPointer( CallingConvention.Cdecl )]
        public delegate NvStatus NvAPI_GPU_GetUsagesDelegate (
          NvPhysicalGpuHandle gpuHandle, ref NvUsages nvUsages );
        [UnmanagedFunctionPointer( CallingConvention.Cdecl )]
        public delegate NvStatus NvAPI_GPU_GetCoolerSettingsDelegate (
          NvPhysicalGpuHandle gpuHandle, int coolerIndex,
          ref NvGPUCoolerSettings nvGPUCoolerSettings );
        [UnmanagedFunctionPointer( CallingConvention.Cdecl )]
        public delegate NvStatus NvAPI_GPU_GetMemoryInfoDelegate (
          NvDisplayHandle displayHandle, ref NvMemoryInfo nvMemoryInfo );
        [UnmanagedFunctionPointer( CallingConvention.Cdecl )]
        public delegate NvStatus NvAPI_GetDisplayDriverVersionDelegate (
          NvDisplayHandle displayHandle, [In, Out] ref NvDisplayDriverVersion
          nvDisplayDriverVersion );
        [UnmanagedFunctionPointer( CallingConvention.Cdecl )]
        public delegate NvStatus NvAPI_GetInterfaceVersionStringDelegate (
          StringBuilder version );
 
        private static readonly bool available;
        private static readonly NvAPI_InitializeDelegate NvAPI_Initialize;
        private static readonly NvAPI_GPU_GetFullNameDelegate 
      _NvAPI_GPU_GetFullName;
        private static readonly NvAPI_GetInterfaceVersionStringDelegate
      _NvAPI_GetInterfaceVersionString;
 
        public static readonly NvAPI_GPU_GetThermalSettingsDelegate 
      NvAPI_GPU_GetThermalSettings;
        public static readonly NvAPI_EnumNvidiaDisplayHandleDelegate
      NvAPI_EnumNvidiaDisplayHandle;
        public static readonly NvAPI_GetPhysicalGPUsFromDisplayDelegate
      NvAPI_GetPhysicalGPUsFromDisplay;
        public static readonly NvAPI_EnumPhysicalGPUsDelegate
      NvAPI_EnumPhysicalGPUs;
        public static readonly NvAPI_GPU_GetTachReadingDelegate
      NvAPI_GPU_GetTachReading;
        public static readonly NvAPI_GPU_GetAllClocksDelegate
      NvAPI_GPU_GetAllClocks;
        public static readonly NvAPI_GPU_GetPStatesDelegate
      NvAPI_GPU_GetPStates;
        public static readonly NvAPI_GPU_GetUsagesDelegate
      NvAPI_GPU_GetUsages;
        public static readonly NvAPI_GPU_GetCoolerSettingsDelegate
      NvAPI_GPU_GetCoolerSettings;
        public static readonly NvAPI_GPU_GetMemoryInfoDelegate
      NvAPI_GPU_GetMemoryInfo;
        public static readonly NvAPI_GetDisplayDriverVersionDelegate
      NvAPI_GetDisplayDriverVersion;
 
        private NVAPI ( ) { }
 
        public static NvStatus NvAPI_GPU_GetFullName ( NvPhysicalGpuHandle gpuHandle,
          out string name )
        {
            StringBuilder builder = new StringBuilder( SHORT_STRING_MAX );
            NvStatus status;
            if ( _NvAPI_GPU_GetFullName != null )
                status = _NvAPI_GPU_GetFullName( gpuHandle, builder );
            else
                status = NvStatus.FUNCTION_NOT_FOUND;
            name = builder.ToString();
            return status;
        }
 
        public static NvStatus NvAPI_GetInterfaceVersionString ( out string version )
        {
            StringBuilder builder = new StringBuilder( SHORT_STRING_MAX );
            NvStatus status;
            if ( _NvAPI_GetInterfaceVersionString != null )
                status = _NvAPI_GetInterfaceVersionString( builder );
            else
                status = NvStatus.FUNCTION_NOT_FOUND;
            version = builder.ToString();
            return status;
        }
 
        private static string GetDllName ( )
        {
            if ( IntPtr.Size == 4 )
            {
                return "nvapi.dll";
            }
            else
            {
                return "nvapi64.dll";
            }
        }
 
        private static void GetDelegate<T> ( uint id, out T newDelegate )
          where T : class
        {
            IntPtr ptr = nvapi_QueryInterface( id );
            if ( ptr != IntPtr.Zero )
            {
                newDelegate =
                  Marshal.GetDelegateForFunctionPointer( ptr, typeof( T ) ) as T;
            }
            else
            {
                newDelegate = null;
            }
        }
 
        [UnmanagedFunctionPointer( CallingConvention.Cdecl )]
        delegate IntPtr nvapi_QueryInterfaceDelegate ( uint id );
 
        static readonly nvapi_QueryInterfaceDelegate nvapi_QueryInterface;
 
        #region ~ Win32 API ~
 
        [DllImport( "kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode )]
        private static extern IntPtr LoadLibrary ( string lpFileName );
 
        [DllImport( "kernel32.dll", SetLastError = true, CharSet = CharSet.Ansi )]
        private static extern IntPtr GetProcAddress (
            IntPtr hModule,
            string lpProcName
            );
 
        #endregion
 
        //[DllImport( "nvapi.dll", CallingConvention = CallingConvention.Cdecl )]
        //static extern IntPtr nvapi_QueryInterface ( uint id );
 
        static NVAPI ( )
        {
            try
            {
                var hLib = LoadLibrary( GetDllName() );
                if ( hLib == IntPtr.Zero )
                    throw new Win32Exception();
 
                var pFunc = GetProcAddress( hLib, "nvapi_QueryInterface" );
                if ( pFunc == IntPtr.Zero )
                    throw new Win32Exception();
 
                nvapi_QueryInterface = (nvapi_QueryInterfaceDelegate)Marshal.GetDelegateForFunctionPointer( pFunc, typeof( nvapi_QueryInterfaceDelegate ) );
 
                GetDelegate( 0x0150E828, out NvAPI_Initialize );
            }
            catch ( DllNotFoundException ) { return; }
            catch ( EntryPointNotFoundException ) { return; }
            catch ( ArgumentNullException ) { return; }
 
            if ( NvAPI_Initialize() == NvStatus.OK )
            {
                GetDelegate( 0xE3640A56, out NvAPI_GPU_GetThermalSettings );
                GetDelegate( 0xCEEE8E9F, out _NvAPI_GPU_GetFullName );
                GetDelegate( 0x9ABDD40D, out NvAPI_EnumNvidiaDisplayHandle );
                GetDelegate( 0x34EF9506, out NvAPI_GetPhysicalGPUsFromDisplay );
                GetDelegate( 0xE5AC921F, out NvAPI_EnumPhysicalGPUs );
                GetDelegate( 0x5F608315, out NvAPI_GPU_GetTachReading );
                GetDelegate( 0x1BD69F49, out NvAPI_GPU_GetAllClocks );
                GetDelegate( 0x60DED2ED, out NvAPI_GPU_GetPStates );
                GetDelegate( 0x189A1FDF, out NvAPI_GPU_GetUsages );
                GetDelegate( 0xDA141340, out NvAPI_GPU_GetCoolerSettings );
                GetDelegate( 0x774AA982, out NvAPI_GPU_GetMemoryInfo );
                GetDelegate( 0xF951A4D1, out NvAPI_GetDisplayDriverVersion );
                GetDelegate( 0x01053FA5, out _NvAPI_GetInterfaceVersionString );
 
                available = true;
            }
        }
 
        public static bool IsAvailable
        {
            get { return available; }
        }
 
    }
}
1
16.11.2013, 20:57
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
16.11.2013, 20:57
Помогаю со студенческими работами здесь

Нормальная ли температура видеокарты GeFors NVIDIA GTX 650ti 60-65 градусов в загруженом состоянии
Нормальная ли температура видеокарты GeFors NVIDIA GTX 650ti 60-65 градусов в загруженом состоянии

после замены видеокарты NVIDIA 8500 GT на видеокарту NVIDIA NX 8800 GTX стал мигать экран в играх
Всем доброе время суток. У меня возникла проблема : после замены видеокарты NVIDIA 8500 GT на...

Температура чипсета NVIDIA MCP79D
Добрый день! Имеется ноутбук Asus K50ID от 2010-11 г. В нём Intel Core 2 Duo T9900, NVIDIA MCP79D,...

Температура nVIDIA GeForce 6800
на видюхе nVIDIA GeForce 6800 температура около90 градусов. Обороты вентилятора Эверест постоянно...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
7
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru