DerkurvigeTyrann Posted May 21, 2014 Posted May 21, 2014 Hi I tried to write a small script, which should read out the memory size and the available memory of my video Card. I searched for some functions in google and found this one NvAPI_GPU_GetMemoryInfo. http://docs.nvidia.com/gameworks/content/gameworkslibrary/coresdk/nvapi/group__driverapi.html#gac66aa214173169763b305ecfa77a215d My problem is that I have nearly zero experience with DLLs and want to ask if somebody could help me with that. I already found some code on this thread '?do=embed' frameborder='0' data-embedContent>> but as described there it won´t work. expandcollapse popup#include <Array.au3> Dim $gpuHwnds[1], $disHwnds[1], $PhyGpuDisHwnds[1] Dim $DLL = DllOpen('nvapi.dll') $N = NvAPI_Initialize() NvAPI_EnumPhysicalGPUs() NvAPI_EnumNvidiaDisplayHandle() NvAPI_GetPhysicalGPUsFromDisplay($disHwnds[1]) NvAPI_GPU_GetThermalSettings($disHwnds[1]) Exit NvAPI_GPU_GetMemoryInfo($disHwnds[1]) For $i = 0 To 10 $Usage = NvAPI_GPU_GetUsages($gpuHwnds[1]) ConsoleWrite('Usage ' & $Usage & @CRLF) Sleep(1000) Next DllClose($DLL) Func NvAPI_QueryInterface($nInterface) $result = DllCall($DLL, "ptr:cdecl", 'nvapi_QueryInterface', 'int', $nInterface) If @error Then Return SetError(2,@error,0) If $result[0] = 0 Then Return SetError(3,0,0) Return $result[0] EndFunc Func NvAPI_Initialize() Static Local $pInitialize = 0 If $pInitialize = 0 Then $pInitialize = NvAPI_QueryInterface(0x0150E828) If $pInitialize = 0 Then Return SetError(@error,@extended,0) EndIf $result = DllCallAddress("int:cdecl", $pInitialize) If @error Then Return SetError(2,@error,False) Return $result[0] EndFunc Func NvAPI_EnumPhysicalGPUs() Static Local $pEnumPhysGPUs = 0 If $pEnumPhysGPUs = 0 Then $pEnumPhysGPUs = NvAPI_QueryInterface(0xE5AC921F) If $pEnumPhysGPUs = 0 Then Return SetError(@error, @extended, 0) EndIf $stGPUHandles = DllStructCreate("INT_PTR gpuHandles[64];") $result = DllCallAddress("int:cdecl", $pEnumPhysGPUs, 'ptr', DllStructGetPtr($stGPUHandles), 'int*', 0) If @error Then Return SetError(2,@error,0) If $result[0] Then Return SetError(3,0,0) $gpuHwnds[0] = $result[2] For $i = 1 To $gpuHwnds[0] _ArrayAdd($gpuHwnds, DllStructGetData($stGPUHandles, 1, $i)) Next Return EndFunc Func NvAPI_GPU_GetUsages($vGPUHandle) Static Local $pGetUsages = 0 If $pGetUsages = 0 Then $pGetUsages = NvAPI_QueryInterface(0x189A1FDF) If $pGetUsages = 0 Then Return SetError(@error, @extended, 0) EndIf $stGPUUsages = DllStructCreate("uint gpuUsages[34];") DLLStructSetData($stGPUUsages, 1, BitOR(34 * 4, 0x10000), 1) $result = DllCallAddress("int:cdecl", $pGetUsages, 'ptr', $vGPUHandle, 'ptr', DllStructGetPtr($stGPUUsages)) If @error Then Return SetError(2,@error,0) If $result[0] Then Return SetError(3, 0, 0) Return DllStructGetData($stGPUUsages, 1, 4) ; 4 is equivalent to c's array[3] EndFunc Func NvAPI_EnumNvidiaDisplayHandle() Static Local $pEnumDisHwnd = 0 If $pEnumDisHwnd = 0 Then $pEnumDisHwnd = NvAPI_QueryInterface(0x9ABDD40D) If $pEnumDisHwnd = 0 Then Return SetError(@error, @extended, 0) EndIf $stDisHandles = DllStructCreate("PTR dispHandle;") $i = 0 While 1 $result = DllCallAddress("int:cdecl", $pEnumDisHwnd, 'int', $i, 'ptr', DllStructGetPtr($stDisHandles)) If @error Then Return SetError(2,@error,0) If $result[0] And $i = 0 Then Return SetError(3,0,0) If $result[0] Then ExitLoop _ArrayAdd($disHwnds, DllStructGetData($stDisHandles, 1)) $disHwnds[0] = $i + 1 $i += 1 WEnd EndFunc Func NvAPI_GetPhysicalGPUsFromDisplay($vdisHandle) Static Local $pPhysGPUsDisp = 0 If $pPhysGPUsDisp = 0 Then $pPhysGPUsDisp = NvAPI_QueryInterface(0x34EF9506) If $pPhysGPUsDisp = 0 Then Return SetError(@error, @extended, 0) EndIf $stGPUHandles = DllStructCreate("INT_PTR PgpuHandles[64];") ; was ptr only $result = DllCallAddress("int:cdecl", $pPhysGPUsDisp, 'ptr', $vdisHandle, 'ptr', DllStructGetPtr($stGPUHandles), 'int*', 0) If @error Then Return SetError(2,@error,0) If $result[0] Then Return SetError(3,0,0) $PhyGpuDisHwnds[0] = $result[3] For $i = 1 To $PhyGpuDisHwnds[0] _ArrayAdd($PhyGpuDisHwnds, DllStructGetData($stGPUHandles, 1, $i)) Next EndFunc ;===================;===================;===================;===================;===================;===================;=================== Func NvAPI_GPU_GetMemoryInfo($vdisHandle) Static Local $pMemInfo = 0 If $pMemInfo = 0 Then $pMemInfo = NvAPI_QueryInterface(0x774AA982) If $pMemInfo = 0 Then Return SetError(@error, @extended, 0) EndIf $NvMemoryInfo = DllStructCreate("uint values[5];") ;DLLStructSetData($NvMemoryInfo, 1, 0x20000, 1) $result = DllCallAddress("int:cdecl", $pMemInfo, 'ptr', $vdisHandle, 'ptr', DllStructGetPtr($NvMemoryInfo)) _ArrayDisplay($result, 'Memory') If @error Then Return SetError(2,@error,0) If $result[0] Then Return SetError(3,0,0) Return $result EndFunc Func NvAPI_GPU_GetThermalSettings($vGPUHandle) Static Local $pThermalInfo = 0 If $pThermalInfo = 0 Then $pThermalInfo = NvAPI_QueryInterface(0xE3640A56) If $pThermalInfo = 0 Then Return SetError(@error, @extended, 0) EndIf $NvSensorStruct = 'uint Controller;uint DefaultMinTemp;uint DefaultMaxTemp;uint CurrentTemp;uint Target;' $NvSensor = DllStructCreate($NvSensorStruct) ;DllStructSetData($NvSensor, 'Controller', 1) ;DllStructSetData($NvSensor, 'Target', 1) $NvGPUThermalSettings = DllStructCreate('uint Version;uint Count[3];ptr ' & DllStructGetPtr($NvSensor)) ;STRUCT' & $NvSensorStruct & 'ENDSTRUCT;');& DllStructCreate($$NvSensorStruct)) $result = DllCallAddress("int:cdecl", $pThermalInfo, 'ptr', $vGPUHandle, 'int', 0, 'ptr', DllStructGetPtr($NvGPUThermalSettings)) _ArrayDisplay($result, 'Thermal') If @error Then Return SetError(2,@error,0) If $result[0] Then Return SetError(3,0,0) Return $result EndFunc
DerkurvigeTyrann Posted May 23, 2014 Author Posted May 23, 2014 Maybe a site, with a tutorial i could learn from? I´ll take everything i´m pretty desperate^^
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now