@@ -25,31 +25,31 @@ internal static class NvApi
2525 private const string DllName = "nvapi.dll" ;
2626 private const string DllName64 = "nvapi64.dll" ;
2727
28- public static readonly NvAPI_EnumNvidiaDisplayHandleDelegate NvAPI_EnumNvidiaDisplayHandle ;
29- public static readonly NvAPI_EnumPhysicalGPUsDelegate NvAPI_EnumPhysicalGPUs ;
30- public static readonly NvAPI_GetDisplayDriverVersionDelegate NvAPI_GetDisplayDriverVersion ;
31- public static readonly NvAPI_GetPhysicalGPUsFromDisplayDelegate NvAPI_GetPhysicalGPUsFromDisplay ;
32- public static readonly NvAPI_GPU_ClientFanCoolersGetControlDelegate NvAPI_GPU_ClientFanCoolersGetControl ;
33- public static readonly NvAPI_GPU_ClientFanCoolersGetStatusDelegate NvAPI_GPU_ClientFanCoolersGetStatus ;
34- public static readonly NvAPI_GPU_ClientFanCoolersSetControlDelegate NvAPI_GPU_ClientFanCoolersSetControl ;
35- public static readonly NvAPI_GPU_ClientPowerTopologyGetStatusDelegate NvAPI_GPU_ClientPowerTopologyGetStatus ;
36- public static readonly NvAPI_GPU_GetAllClockFrequenciesDelegate NvAPI_GPU_GetAllClockFrequencies ;
37- public static readonly NvAPI_GPU_GetAllClocksDelegate NvAPI_GPU_GetAllClocks ;
38- public static readonly NvAPI_GPU_GetBusIdDelegate NvAPI_GPU_GetBusId ;
39- public static readonly NvAPI_GPU_GetCoolerSettingsDelegate NvAPI_GPU_GetCoolerSettings ;
40- public static readonly NvAPI_GPU_GetDynamicPstatesInfoExDelegate NvAPI_GPU_GetDynamicPstatesInfoEx ;
41- public static readonly NvAPI_GPU_GetMemoryInfoDelegate NvAPI_GPU_GetMemoryInfo ;
42- public static readonly NvAPI_GPU_GetPCIIdentifiersDelegate NvAPI_GPU_GetPCIIdentifiers ;
43- public static readonly NvAPI_GPU_GetTachReadingDelegate NvAPI_GPU_GetTachReading ;
44- public static readonly NvAPI_GPU_GetThermalSettingsDelegate NvAPI_GPU_GetThermalSettings ;
45- public static readonly NvAPI_GPU_GetUsagesDelegate NvAPI_GPU_GetUsages ;
46- public static readonly NvAPI_GPU_SetCoolerLevelsDelegate NvAPI_GPU_SetCoolerLevels ;
47- public static readonly NvAPI_GPU_GetThermalSensorsDelegate NvAPI_GPU_ThermalGetSensors ;
48-
49- private static readonly NvAPI_GetInterfaceVersionStringDelegate _nvAPI_GetInterfaceVersionString ;
50- private static readonly NvAPI_GPU_GetFullNameDelegate _nvAPI_GPU_GetFullName ;
51-
52- static NvApi ( )
28+ public static NvAPI_EnumNvidiaDisplayHandleDelegate NvAPI_EnumNvidiaDisplayHandle { get ; internal set ; }
29+ public static NvAPI_EnumPhysicalGPUsDelegate NvAPI_EnumPhysicalGPUs { get ; internal set ; }
30+ public static NvAPI_GetDisplayDriverVersionDelegate NvAPI_GetDisplayDriverVersion { get ; internal set ; }
31+ public static NvAPI_GetPhysicalGPUsFromDisplayDelegate NvAPI_GetPhysicalGPUsFromDisplay { get ; internal set ; }
32+ public static NvAPI_GPU_ClientFanCoolersGetControlDelegate NvAPI_GPU_ClientFanCoolersGetControl { get ; internal set ; }
33+ public static NvAPI_GPU_ClientFanCoolersGetStatusDelegate NvAPI_GPU_ClientFanCoolersGetStatus { get ; internal set ; }
34+ public static NvAPI_GPU_ClientFanCoolersSetControlDelegate NvAPI_GPU_ClientFanCoolersSetControl { get ; internal set ; }
35+ public static NvAPI_GPU_ClientPowerTopologyGetStatusDelegate NvAPI_GPU_ClientPowerTopologyGetStatus { get ; internal set ; }
36+ public static NvAPI_GPU_GetAllClockFrequenciesDelegate NvAPI_GPU_GetAllClockFrequencies { get ; internal set ; }
37+ public static NvAPI_GPU_GetAllClocksDelegate NvAPI_GPU_GetAllClocks { get ; internal set ; }
38+ public static NvAPI_GPU_GetBusIdDelegate NvAPI_GPU_GetBusId { get ; internal set ; }
39+ public static NvAPI_GPU_GetCoolerSettingsDelegate NvAPI_GPU_GetCoolerSettings { get ; internal set ; }
40+ public static NvAPI_GPU_GetDynamicPstatesInfoExDelegate NvAPI_GPU_GetDynamicPstatesInfoEx { get ; internal set ; }
41+ public static NvAPI_GPU_GetMemoryInfoDelegate NvAPI_GPU_GetMemoryInfo { get ; internal set ; }
42+ public static NvAPI_GPU_GetPCIIdentifiersDelegate NvAPI_GPU_GetPCIIdentifiers { get ; internal set ; }
43+ public static NvAPI_GPU_GetTachReadingDelegate NvAPI_GPU_GetTachReading { get ; internal set ; }
44+ public static NvAPI_GPU_GetThermalSettingsDelegate NvAPI_GPU_GetThermalSettings { get ; internal set ; }
45+ public static NvAPI_GPU_GetUsagesDelegate NvAPI_GPU_GetUsages { get ; internal set ; }
46+ public static NvAPI_GPU_SetCoolerLevelsDelegate NvAPI_GPU_SetCoolerLevels { get ; internal set ; }
47+ public static NvAPI_GPU_GetThermalSensorsDelegate NvAPI_GPU_GetThermalSensors { get ; internal set ; }
48+
49+ private static NvAPI_GetInterfaceVersionStringDelegate _nvAPI_GetInterfaceVersionString ;
50+ private static NvAPI_GPU_GetFullNameDelegate _nvAPI_GPU_GetFullName ;
51+
52+ public static void Initialize ( )
5353 {
5454 NvAPI_InitializeDelegate nvApiInitialize ;
5555
@@ -58,7 +58,7 @@ static NvApi()
5858 if ( ! DllExists ( ) )
5959 return ;
6060
61- GetDelegate ( 0x0150E828 , out nvApiInitialize ) ;
61+ nvApiInitialize = GetDelegate < NvAPI_InitializeDelegate > ( 0x0150E828 ) ;
6262 }
6363 catch ( Exception e ) when ( e is DllNotFoundException or ArgumentNullException or EntryPointNotFoundException or BadImageFormatException )
6464 {
@@ -67,28 +67,28 @@ static NvApi()
6767
6868 if ( nvApiInitialize ( ) == NvStatus . OK )
6969 {
70- GetDelegate ( 0xE3640A56 , out NvAPI_GPU_GetThermalSettings ) ;
71- GetDelegate ( 0xCEEE8E9F , out _nvAPI_GPU_GetFullName ) ;
72- GetDelegate ( 0x9ABDD40D , out NvAPI_EnumNvidiaDisplayHandle ) ;
73- GetDelegate ( 0x34EF9506 , out NvAPI_GetPhysicalGPUsFromDisplay ) ;
74- GetDelegate ( 0xE5AC921F , out NvAPI_EnumPhysicalGPUs ) ;
75- GetDelegate ( 0x5F608315 , out NvAPI_GPU_GetTachReading ) ;
76- GetDelegate ( 0x1BD69F49 , out NvAPI_GPU_GetAllClocks ) ;
77- GetDelegate ( 0x60DED2ED , out NvAPI_GPU_GetDynamicPstatesInfoEx ) ;
78- GetDelegate ( 0x189A1FDF , out NvAPI_GPU_GetUsages ) ;
79- GetDelegate ( 0xDA141340 , out NvAPI_GPU_GetCoolerSettings ) ;
80- GetDelegate ( 0x891FA0AE , out NvAPI_GPU_SetCoolerLevels ) ;
81- GetDelegate ( 0x774AA982 , out NvAPI_GPU_GetMemoryInfo ) ;
82- GetDelegate ( 0xF951A4D1 , out NvAPI_GetDisplayDriverVersion ) ;
83- GetDelegate ( 0x01053FA5 , out _nvAPI_GetInterfaceVersionString ) ;
84- GetDelegate ( 0x2DDFB66E , out NvAPI_GPU_GetPCIIdentifiers ) ;
85- GetDelegate ( 0x1BE0B8E5 , out NvAPI_GPU_GetBusId ) ;
86- GetDelegate ( 0x35AED5E8 , out NvAPI_GPU_ClientFanCoolersGetStatus ) ;
87- GetDelegate ( 0xDCB616C3 , out NvAPI_GPU_GetAllClockFrequencies ) ;
88- GetDelegate ( 0x814B209F , out NvAPI_GPU_ClientFanCoolersGetControl ) ;
89- GetDelegate ( 0xA58971A5 , out NvAPI_GPU_ClientFanCoolersSetControl ) ;
90- GetDelegate ( 0x0EDCF624E , out NvAPI_GPU_ClientPowerTopologyGetStatus ) ;
91- GetDelegate ( 0x65FE3AAD , out NvAPI_GPU_ThermalGetSensors ) ;
70+ NvAPI_GPU_GetThermalSettings = GetDelegate < NvAPI_GPU_GetThermalSettingsDelegate > ( 0xE3640A56 ) ;
71+ _nvAPI_GPU_GetFullName = GetDelegate < NvAPI_GPU_GetFullNameDelegate > ( 0xCEEE8E9F ) ;
72+ NvAPI_EnumNvidiaDisplayHandle = GetDelegate < NvAPI_EnumNvidiaDisplayHandleDelegate > ( 0x9ABDD40D ) ;
73+ NvAPI_GetPhysicalGPUsFromDisplay = GetDelegate < NvAPI_GetPhysicalGPUsFromDisplayDelegate > ( 0x34EF9506 ) ;
74+ NvAPI_EnumPhysicalGPUs = GetDelegate < NvAPI_EnumPhysicalGPUsDelegate > ( 0xE5AC921F ) ;
75+ NvAPI_GPU_GetTachReading = GetDelegate < NvAPI_GPU_GetTachReadingDelegate > ( 0x5F608315 ) ;
76+ NvAPI_GPU_GetAllClocks = GetDelegate < NvAPI_GPU_GetAllClocksDelegate > ( 0x1BD69F49 ) ;
77+ NvAPI_GPU_GetDynamicPstatesInfoEx = GetDelegate < NvAPI_GPU_GetDynamicPstatesInfoExDelegate > ( 0x60DED2ED ) ;
78+ NvAPI_GPU_GetUsages = GetDelegate < NvAPI_GPU_GetUsagesDelegate > ( 0x189A1FDF ) ;
79+ NvAPI_GPU_GetCoolerSettings = GetDelegate < NvAPI_GPU_GetCoolerSettingsDelegate > ( 0xDA141340 ) ;
80+ NvAPI_GPU_SetCoolerLevels = GetDelegate < NvAPI_GPU_SetCoolerLevelsDelegate > ( 0x891FA0AE ) ;
81+ NvAPI_GPU_GetMemoryInfo = GetDelegate < NvAPI_GPU_GetMemoryInfoDelegate > ( 0x774AA982 ) ;
82+ NvAPI_GetDisplayDriverVersion = GetDelegate < NvAPI_GetDisplayDriverVersionDelegate > ( 0xF951A4D1 ) ;
83+ _nvAPI_GetInterfaceVersionString = GetDelegate < NvAPI_GetInterfaceVersionStringDelegate > ( 0x01053FA5 ) ;
84+ NvAPI_GPU_GetPCIIdentifiers = GetDelegate < NvAPI_GPU_GetPCIIdentifiersDelegate > ( 0x2DDFB66E ) ;
85+ NvAPI_GPU_GetBusId = GetDelegate < NvAPI_GPU_GetBusIdDelegate > ( 0x1BE0B8E5 ) ;
86+ NvAPI_GPU_ClientFanCoolersGetStatus = GetDelegate < NvAPI_GPU_ClientFanCoolersGetStatusDelegate > ( 0x35AED5E8 ) ;
87+ NvAPI_GPU_GetAllClockFrequencies = GetDelegate < NvAPI_GPU_GetAllClockFrequenciesDelegate > ( 0xDCB616C3 ) ;
88+ NvAPI_GPU_ClientFanCoolersGetControl = GetDelegate < NvAPI_GPU_ClientFanCoolersGetControlDelegate > ( 0x814B209F ) ;
89+ NvAPI_GPU_ClientFanCoolersSetControl = GetDelegate < NvAPI_GPU_ClientFanCoolersSetControlDelegate > ( 0xA58971A5 ) ;
90+ NvAPI_GPU_ClientPowerTopologyGetStatus = GetDelegate < NvAPI_GPU_ClientPowerTopologyGetStatusDelegate > ( 0x0EDCF624E ) ;
91+ NvAPI_GPU_GetThermalSensors = GetDelegate < NvAPI_GPU_GetThermalSensorsDelegate > ( 0x65FE3AAD ) ;
9292
9393 IsAvailable = true ;
9494 }
@@ -188,7 +188,7 @@ public enum NvUtilizationDomain
188188 BusInterface // Bus
189189 }
190190
191- public static bool IsAvailable { get ; }
191+ public static bool IsAvailable { get ; private set ; }
192192
193193 [ DllImport ( DllName , EntryPoint = "nvapi_QueryInterface" , CallingConvention = CallingConvention . Cdecl , PreserveSig = true ) ]
194194 [ DefaultDllImportSearchPaths ( DllImportSearchPath . System32 ) ]
@@ -216,14 +216,18 @@ public static NvStatus NvAPI_GetInterfaceVersionString(out string version)
216216 return status ;
217217 }
218218
219- private static void GetDelegate < T > ( uint id , out T newDelegate ) where T : class
219+ private static T GetDelegate < T > ( uint id ) where T : class
220220 {
221221 IntPtr ptr = Environment . Is64BitProcess ? NvAPI64_QueryInterface ( id ) : NvAPI32_QueryInterface ( id ) ;
222222
223223 if ( ptr != IntPtr . Zero )
224- newDelegate = Marshal . GetDelegateForFunctionPointer ( ptr , typeof ( T ) ) as T ;
224+ {
225+ return Marshal . GetDelegateForFunctionPointer ( ptr , typeof ( T ) ) as T ;
226+ }
225227 else
226- newDelegate = null ;
228+ {
229+ return null ;
230+ }
227231 }
228232
229233 public static bool DllExists ( )
0 commit comments