Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

How do you call this function using dllcall?


  • Please log in to reply
2 replies to this topic
jd
  • Guests
  • Last active:
  • Joined: --
I have looked all over the place and can't find how to call GetProcessMemoryInfo using AHK.

the MSDN link is GetProcessMemoryInfo

That whole c++ syntax is such greek to me, I can't even begin to comprhend it enough to make it work in AHK.

I would like to find out how much memory a process is consuming, and from the looks of it that is the function to do it.

[ Moderator!: MSDN link fixed ]

Serenity
  • Members
  • 1271 posts
  • Last active:
  • Joined: 07 Nov 2004
Here's a wrapper function:

Msgbox % GetProcessMemoryInfo( "firefox.exe" )

GetProcessMemoryInfo( pname ) 
{
	Process, Exist, %pname%
	pid := Errorlevel

	; get process handle
	hProcess := DllCall( "OpenProcess", UInt, 0x10|0x400, Int, false, UInt, pid )

	; get memory info
	VarSetCapacity( memCounters, 40, 0 )
	DllCall( "psapi.dll\GetProcessMemoryInfo", UInt, hProcess, UInt, &memCounters, UInt, 40 )
	DllCall( "CloseHandle", UInt, hProcess )

	list = cb,PageFaultCount,PeakWorkingSetSize,WorkingSetSize,QuotaPeakPagedPoolUsage
	,QuotaPagedPoolUsage,QuotaPeakNonPagedPoolUsage,QuotaNonPagedPoolUsage
	,PagefileUsage,PeakPagefileUsage

	/*
	cb := NumGet( memCounters, 0, "UInt" )
	PageFaultCount := NumGet( memCounters, 4, "UInt" )
	PeakWorkingSetSize := NumGet( memCounters, 8, "UInt" )
	WorkingSetSize := NumGet( memCounters, 12, "UInt" )
	QuotaPeakPagedPoolUsage := NumGet( memCounters, 16, "UInt" )
	QuotaPagedPoolUsage := NumGet( memCounters, 20, "UInt" )
	QuotaPeakNonPagedPoolUsage := NumGet( memCounters, 24, "UInt" )
	QuotaNonPagedPoolUsage := NumGet( memCounters, 28, "UInt" )
	PagefileUsage := NumGet( memCounters, 32, "UInt" )
	PeakPagefileUsage := NumGet( memCounters, 36, "UInt" )
	*/

	n=0
	Loop, Parse, list, `,
	{
		n+=4
		SetFormat, Float, 0.0 ; round up K
		this := A_Loopfield
		this := NumGet( memCounters, (A_Index = 1 ? 0 : n-4), "UInt") / 1024

		; omit cb
		If A_Index != 1
			info .= A_Loopfield . ": " . this . " K" . ( A_Loopfield != "" ? "`n" : "" ) 
	}  

	; Return "[" . pid . "] " . pname . "`n`n" . info ; for everything
	Return WorkingSetSize := NumGet( memCounters, 12, "UInt" ) / 1024 . " K" ; what Task Manager shows
}

"Anything worth doing is worth doing slowly." - Mae West
Posted Image

DJAnonimo
  • Members
  • 171 posts
  • Last active: Apr 30 2013 01:20 AM
  • Joined: 10 Sep 2006

Serenity your function returns wrong size, it's about half size of the process memory usage.

 

Any idea why ?