static NVAPI() { DllImportAttribute attribute = new DllImportAttribute("nvapi64.dll") { CallingConvention = CallingConvention.Cdecl, PreserveSig = true, EntryPoint = "nvapi_QueryInterface" }; PInvokeDelegateFactory.CreateDelegate(attribute, out nvapi_QueryInterface); try { GetDelegate(0x0150E828, out NvAPI_Initialize); } catch (Exception e) { Helpers.ConsolePrint("NVAPI", e.ToString()); return; } if (NvAPI_Initialize() == NvStatus.OK) { GetDelegate(0x5F608315, out NvAPI_GPU_GetTachReading); GetDelegate(0x60DED2ED, out NvAPI_GPU_GetPStates); GetDelegate(0xE3640A56, out NvAPI_GPU_GetThermalSettings); GetDelegate(0xE5AC921F, out NvAPI_EnumPhysicalGPUs); GetDelegate(0x1BE0B8E5, out NvAPI_GPU_GetBusID); } available = true; }
static NVAPI() { DllImportAttribute attribute = new DllImportAttribute("nvapi64.dll"); attribute.CallingConvention = CallingConvention.Cdecl; attribute.PreserveSig = true; attribute.EntryPoint = "nvapi_QueryInterface"; PInvokeDelegateFactory.CreateDelegate(attribute, out nvapi_QueryInterface); try { GetDelegate(0x0150E828, out NvAPI_Initialize); } catch (Exception e) { Logger.Info("NVAPI", e.ToString()); return; } if (NvAPI_Initialize() == NvStatus.OK) { GetDelegate(0x5F608315, out NvAPI_GPU_GetTachReading); GetDelegate(0x60DED2ED, out NvAPI_GPU_GetPStates); GetDelegate(0xE3640A56, out NvAPI_GPU_GetThermalSettings); GetDelegate(0xE5AC921F, out NvAPI_EnumPhysicalGPUs); GetDelegate(0x1BE0B8E5, out NvAPI_GPU_GetBusID); GetDelegate(0x34206D86, out NvAPI_DLL_ClientPowerPoliciesGetInfo); GetDelegate(0x70916171, out NvAPI_DLL_ClientPowerPoliciesGetStatus); GetDelegate(0xAD95F5ED, out NvAPI_DLL_ClientPowerPoliciesSetStatus); GetDelegate(0xDA141340, out NvAPI_GPU_GetCoolerLevels); GetDelegate(0x891FA0AE, out NvAPI_GPU_SetCoolerLevels); } available = true; }
static NVAPI() { DllImportAttribute attribute = new DllImportAttribute(GetDllName()); attribute.CallingConvention = CallingConvention.Cdecl; attribute.PreserveSig = true; attribute.EntryPoint = "nvapi_QueryInterface"; PInvokeDelegateFactory.CreateDelegate(attribute, out nvapi_QueryInterface); try { GetDelegate(0x0150E828, out NvAPI_Initialize); } catch (DllNotFoundException) { 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); available = true; } }
static NvapiNativeMethods() { DllImportAttribute attribute = new DllImportAttribute("nvapi64.dll"); attribute.CallingConvention = CallingConvention.Cdecl; attribute.PreserveSig = true; attribute.EntryPoint = "nvapi_QueryInterface"; PInvokeDelegateFactory.CreateDelegate(attribute, typeof(NvQueryInterfaceDelegate), out object newDelegate); NvQueryInterface = (NvQueryInterfaceDelegate)newDelegate; try { IntPtr ptr = NvQueryInterface(0x0150E828); NvInitialize = (NvInitializeDelegate)Marshal.GetDelegateForFunctionPointer(ptr, typeof(NvInitializeDelegate)); } catch (Exception e) { Logger.ErrorDebugLine(e); return; } if (NvInitialize() == NvStatus.NVAPI_OK) { Type t = typeof(NvapiNativeMethods); var properties = t.GetProperties(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.SetProperty); foreach (var property in properties) { var id = ((IdAttribute)property.GetCustomAttributes(typeof(IdAttribute), inherit: false).First()).Id; SetDelegate(property, id); } } }
private NVAPIService() { DllImportAttribute attribute = new DllImportAttribute(GetLibraryName()); attribute.CallingConvention = CallingConvention.Cdecl; attribute.PreserveSig = true; attribute.EntryPoint = "nvapi_QueryInterface"; PInvokeDelegateFactory.CreateDelegate(attribute, out nvapi_QueryInterface); GetNvAPIDelegate(0x0150E828, out NvAPI_Initialize); NvAPI_Initialize(); GetNvAPIDelegate(0xE5AC921F, out NvAPI_EnumPhysicalGPUs); GetNvAPIDelegate(0xD9930B07, out NvAPI_EnumTCCPhysicalGPUs); GetNvAPIDelegate(0x9ABDD40D, out NvAPI_EnumNvidiaDisplayHandle); GetNvAPIDelegate(0x34EF9506, out NvAPI_GetPhysicalGPUsFromDisplay); GetNvAPIDelegate(0x1BE0B8E5, out NvAPI_GPU_GetBusId); GetNvAPIDelegate(0xE3640A56, out NvAPI_GPU_GetThermalSettings); GetNvAPIDelegate(0x60DED2ED, out NvAPI_GPU_GetDynamicPstatesInfoEx); GetNvAPIDelegate(0x189A1FDF, out NvAPI_GPU_GetDynamicPstatesInfo); { NvPhysicalGpuHandle[] physicalGpuHandles = new NvPhysicalGpuHandle[MAX_PHYSICAL_GPUS]; if (NvAPI_EnumPhysicalGPUs(physicalGpuHandles, out int physicalGpuCount) == 0) { nvPhysicalGpuHandles.AddRange(physicalGpuHandles.Where((handle, i) => i < physicalGpuCount && handle.IsValid).ToList()); } NvPhysicalGpuHandle[] TCCPhysicalGpuHandles = new NvPhysicalGpuHandle[MAX_PHYSICAL_GPUS]; if (NvAPI_EnumTCCPhysicalGPUs(TCCPhysicalGpuHandles, out int TCCPhysicalGpuCount) == 0) { nvPhysicalGpuHandles.AddRange(TCCPhysicalGpuHandles.Where((handle, i) => i < TCCPhysicalGpuCount && handle.IsValid).ToList()); } } }
static NVAPI() { DllImportAttribute attribute = new DllImportAttribute(GetDllName()); attribute.CallingConvention = CallingConvention.Cdecl; attribute.PreserveSig = true; attribute.EntryPoint = "nvapi_QueryInterface"; PInvokeDelegateFactory.CreateDelegate(attribute, out nvapi_QueryInterface); 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; } }
private static void GetDelegate <T>(string entryPoint, out T newDelegate) where T : class { DllImportAttribute attribute = new DllImportAttribute(getLibraryName()); attribute.CallingConvention = CallingConvention.Cdecl; attribute.PreserveSig = true; attribute.EntryPoint = entryPoint; PInvokeDelegateFactory.CreateDelegate(attribute, out newDelegate); }
private static T CreateDelegate <T>(string entryPoint) where T : Delegate { var attribute = new DllImportAttribute(GetDllName()) { CallingConvention = CallingConvention.Cdecl, PreserveSig = true, EntryPoint = entryPoint }; PInvokeDelegateFactory.CreateDelegate(attribute, out T newDelegate); return(newDelegate); }
private static void GetDelegate <T>(string entryPoint, out T newDelegate) where T : class { DllImportAttribute attribute = new DllImportAttribute(dllName) { CallingConvention = CallingConvention.Cdecl, PreserveSig = true, EntryPoint = entryPoint }; PInvokeDelegateFactory.CreateDelegate(attribute, out newDelegate); }
private static T CreateDelegate <T>(string entryPoint) where T : class { DllImportAttribute attribute = new DllImportAttribute(GetDllName()); attribute.CallingConvention = CallingConvention.StdCall; attribute.PreserveSig = true; attribute.EntryPoint = entryPoint; T newDelegate; PInvokeDelegateFactory.CreateDelegate(attribute, out newDelegate); return(newDelegate); }
static NvapiNativeMethods() { DllImportAttribute attribute = new DllImportAttribute("nvapi64.dll"); attribute.CallingConvention = CallingConvention.Cdecl; attribute.PreserveSig = true; attribute.EntryPoint = "nvapi_QueryInterface"; PInvokeDelegateFactory.CreateDelegate(attribute, out NvQueryInterface); try { GetDelegate(0x0150E828, out NvInitialize); } catch (Exception e) { Logger.ErrorDebugLine(e); return; } if (NvInitialize() == NvStatus.NVAPI_OK) { GetDelegate(0x5F608315, out NvGetTachReading); GetDelegate(0x60DED2ED, out NvGetPStates); GetDelegate(0xE5AC921F, out NvEnumPhysicalGPUs); GetDelegate(0xD9930B07, out NvEnumTCCPhysicalGPUs); GetDelegate(0x1BE0B8E5, out NvGetBusID); GetDelegate(0x6FF81213, out NvGetPStateV1); GetDelegate(0x6FF81213, out NvGetPStateV2); GetDelegate(0x0F4DAE6B, out NvSetPStateV1); GetDelegate(0x0F4DAE6B, out NvSetPStateV2); GetDelegate(0xDCB616C3, out NvGetAllClockFrequenciesV2); GetDelegate(0x0D258BB5, out NvThermalPoliciesGetInfo); GetDelegate(0xE9C425A1, out NvThermalPoliciesGetLimit); GetDelegate(0x34C0B13D, out NvThermalPoliciesSetLimit); GetDelegate(0x70916171, out NvPowerPoliciesGetStatus); GetDelegate(0xAD95F5ED, out NvPowerPoliciesSetStatus); GetDelegate(0x34206D86, out NvPowerPoliciesGetInfo); GetDelegate(0xDA141340, out NvGetCoolerSettings); GetDelegate(0x891FA0AE, out NvSetCoolerLevels); GetDelegate(0x8F6ED0FB, out NvRestoreCoolerSettings); GetDelegate(0xFB85B01E, out NvFanCoolersGetInfo); GetDelegate(0x35AED5E8, out NvFanCoolersGetStatus); GetDelegate(0x814B209F, out NvFanCoolersGetControl); GetDelegate(0xA58971A5, out NvFanCoolersSetControl); } }
static NvapiNativeMethods() { DllImportAttribute attribute = new DllImportAttribute("nvapi64.dll"); attribute.CallingConvention = CallingConvention.Cdecl; attribute.PreserveSig = true; attribute.EntryPoint = "nvapi_QueryInterface"; PInvokeDelegateFactory.CreateDelegate(attribute, out NvQueryInterface); try { NvInitialize = GetDelegate <NvInitializeDelegate>(0x0150E828); } catch (Exception e) { Logger.ErrorDebugLine(e); return; } if (NvInitialize() == NvStatus.NVAPI_OK) { NvGetTachReading = GetDelegate <NvDelegates.NvGetTachReadingDelegate>(0x5F608315); NvGetPStates = GetDelegate <NvDelegates.NvGetPStatesDelegate>(0x60DED2ED); NvEnumPhysicalGPUs = GetDelegate <NvDelegates.NvEnumPhysicalGPUsDelegate>(0xE5AC921F); NvEnumTCCPhysicalGPUs = GetDelegate <NvDelegates.NvEnumTCCPhysicalGPUsDelegate>(0xD9930B07); NvGetBusID = GetDelegate <NvDelegates.NvGetBusIdDelegate>(0x1BE0B8E5); NvGetPStateV1 = GetDelegate <NvDelegates.NvGetPStateV1Delegate>(0x6FF81213); NvGetPStateV2 = GetDelegate <NvDelegates.NvGetPStateV2Delegate>(0x6FF81213); NvSetPStateV1 = GetDelegate <NvDelegates.NvSetPStateV1Delegate>(0x0F4DAE6B); NvSetPStateV2 = GetDelegate <NvDelegates.NvSetPStateV2Delegate>(0x0F4DAE6B); NvGetAllClockFrequenciesV2 = GetDelegate <NvDelegates.NvGetAllClockFrequenciesV2Delegate>(0xDCB616C3); NvThermalPoliciesGetInfo = GetDelegate <NvDelegates.NvThermalPoliciesGetInfoDelegate>(0x0D258BB5); NvThermalPoliciesGetLimit = GetDelegate <NvDelegates.NvThermalPoliciesGetSetLimitDelegate>(0xE9C425A1); NvThermalPoliciesSetLimit = GetDelegate <NvDelegates.NvThermalPoliciesGetSetLimitDelegate>(0x34C0B13D); NvPowerPoliciesGetStatus = GetDelegate <NvDelegates.NvPowerPoliciesGetStatusDelegate>(0x70916171); NvPowerPoliciesSetStatus = GetDelegate <NvDelegates.NvPowerPoliciesSetStatusDelegate>(0xAD95F5ED); NvPowerPoliciesGetInfo = GetDelegate <NvDelegates.NvPowerPoliciesGetInfoDelegate>(0x34206D86); NvGetCoolerSettings = GetDelegate <NvDelegates.NvGetCoolerSettingsDelegate>(0xDA141340); NvSetCoolerLevels = GetDelegate <NvDelegates.NvSetCoolerLevelsDelegate>(0x891FA0AE); NvRestoreCoolerSettings = GetDelegate <NvDelegates.NvRestoreCoolerSettingsDelegate>(0x8F6ED0FB); NvFanCoolersGetInfo = GetDelegate <NvDelegates.NvFanCoolersGetInfoDelegate>(0xFB85B01E); NvFanCoolersGetStatus = GetDelegate <NvDelegates.NvFanCoolersGetStatusDelegate>(0x35AED5E8); NvFanCoolersGetControl = GetDelegate <NvDelegates.NvFanCoolersGetControlDelegate>(0x814B209F); NvFanCoolersSetControl = GetDelegate <NvDelegates.NvFanCoolersSetControlDelegate>(0xA58971A5); } }
private static void SetDelegate(PropertyInfo property, string dllName) { DllImportAttribute attribute = new DllImportAttribute(dllName) { CallingConvention = CallingConvention.Cdecl, PreserveSig = true, EntryPoint = property.Name }; try { PInvokeDelegateFactory.CreateDelegate(attribute, property.PropertyType, out object newDelegate); property.SetValue(null, newDelegate, null); } catch (Exception e) { Logger.ErrorDebugLine(e); } }
static NVAPI() { DllImportAttribute attribute = new DllImportAttribute(GetDllName()) { CallingConvention = CallingConvention.Cdecl, PreserveSig = true, EntryPoint = "nvapi_QueryInterface" }; PInvokeDelegateFactory.CreateDelegate(attribute, out nvapi_QueryInterface); 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_GetDynamicPstatesInfoEx); GetDelegate(0x189A1FDF, out NvAPI_GPU_GetDynamicPstatesInfo); GetDelegate(0xDA141340, out NvAPI_GPU_GetCoolerSettings); GetDelegate(0x891FA0AE, out NvAPI_GPU_SetCoolerLevels); GetDelegate(0x774AA982, out NvAPI_GetDisplayDriverMemoryInfo); GetDelegate(0xF951A4D1, out NvAPI_GetDisplayDriverVersion); GetDelegate(0x01053FA5, out _NvAPI_GetInterfaceVersionString); GetDelegate(0x2DDFB66E, out NvAPI_GPU_GetPCIIdentifiers); GetDelegate(0x1BE0B8E5, out NvAPI_GPU_GetBusId); GetDelegate(0x35AED5E8, out NvAPI_GPU_ClientFanCoolersGetStatus); GetDelegate(0xF40238EF, out NvAPI_GPU_PowerMonitorGetStatus); GetDelegate(0x465f9bcf, out NvAPI_GPU_GetCurrentVoltage); GetDelegate(0x67B5DB55, out NvAPI_GetVBlankCounter); available = true; } }